Skip to content

Conversation

@WCBru
Copy link
Contributor

@WCBru WCBru commented Feb 26, 2025

Fixes #3121

Tested in 1.5.4 release, but it doesn't look like UDP has changed since then.

I've tested Windows output (srt-live-transmit.exe srt://XXX.XXX.XXX.XXX udp://239.XXX.XXX.XXX) but not UDP input or on Linux

E: There's a bunch of renaming that might not conform to the repo's style, but the most important change is the remove of line 914, and the new binding logic used in line 1003 and 1058

@WCBru WCBru marked this pull request as draft February 26, 2025 08:56
@WCBru WCBru marked this pull request as ready for review February 26, 2025 08:58
@WCBru
Copy link
Contributor Author

WCBru commented Feb 26, 2025

Do these changes also need to be made in testing/testmedia.cpp?

@ethouris
Copy link
Collaborator

Yes, please. BTW I just checked this on my windows build and seems like the problem has been fixed.

Note one more thing: if this distinction for the platform is not necessary in the constructor of UdpCommon (the removed sadr = maddr instruction) then consider removing also any conditional code from the constructor.

Comment on lines +834 to +837
interface_addr = sockaddr_any(AF_INET);
interface_addr.sin.sin_family = AF_INET;
interface_addr.sin.sin_addr.s_addr = htonl(INADDR_ANY);
interface_addr.sin.sin_port = htons(port);
Copy link
Collaborator

@ethouris ethouris Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the API of sockaddr_any directly, or better use CreateAddr as you already have it.

Suggested change
interface_addr = sockaddr_any(AF_INET);
interface_addr.sin.sin_family = AF_INET;
interface_addr.sin.sin_addr.s_addr = htonl(INADDR_ANY);
interface_addr.sin.sin_port = htons(port);
interface_addr = CreateAddr("", port, AF_INET);

// Also, sets port sharing when working with multicast
sadr = maddr;
int reuse = 1;
int shareAddrRes = setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&reuse), sizeof(reuse));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this is still necessary to be set before setting the multicast option, or can be moved to the place directly before binding so that the Windows-specific code is in one place.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, confirmed here: setting SO_REUSEADDR is not necessary because the same option is set the same way in the same function few lines earlier, this time for any platform, so this part setting the option can be removed. So please, as you are changing things here, remove this all, and then place the Verb() calls in appropriate conditionals before the ::bind() call.

Comment on lines +1007 to +1011
int stat =
#if defined(_WIN32) || defined(__CYGWIN__)
is_multicast ? ::bind(m_sock, interface_addr.get(), interface_addr.size()) :
#endif
::bind(m_sock, target_addr.get(), target_addr.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better without cpp entanglement.

Suggested change
int stat =
#if defined(_WIN32) || defined(__CYGWIN__)
is_multicast ? ::bind(m_sock, interface_addr.get(), interface_addr.size()) :
#endif
::bind(m_sock, target_addr.get(), target_addr.size());
#if defined(_WIN32) || defined(__CYGWIN__)
sockaddr_any bindaddr = is_multicast ? interface_addr : target_addr;
#else
sockaddr_any bindaddr = target_addr;
#endif
::bind(m_sock, bindaddr.get(), bindaddr.size());


Setup(host, port, attr);
if (adapter != "")
if (is_multicast && interface_addr.isany() == false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think == false makes too much noise.

Suggested change
if (is_multicast && interface_addr.isany() == false)
if (is_multicast && !interface_addr.isany())

@ethouris ethouris added this to the v1.5.5 milestone Feb 26, 2025
@ethouris ethouris added Type: Bug Indicates an unexpected problem or unintended behavior [apps] Area: Test applications related improvements labels Feb 26, 2025
@ethouris
Copy link
Collaborator

Replaced by #3126; same changes with modifications have been merged.

@ethouris ethouris closed this Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[apps] Area: Test applications related improvements Type: Bug Indicates an unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] (Windows) srt-live-transmit Sends UDP Multicast to Adapter Address rather than Specified Destination

2 participants