4

I am trying to write an application that listens to a number of multicast groups using Windows sockets.

The problem I'm running in to is that when I go to bind the socket, if I try to bind to the multicast group address and port this fails with WSAEADDRNOTAVAIL. If I instead bind to INADDR_ANY and the port, then I can still receive other unrelated traffic destined for the same port.

When I implemented the same thing in Linux, I didn't have any issues binding to the multicast address (in fact, I saw it recommended several places to avoid getting unrelated traffic for the port).

Is this just not available with Windows sockets? I assume I could filter traffic myself by using WSARecvFrom and peeking at the headers, but I'd rather a simple solution if one exists.

Also, this is running on Windows Server 2008.

Paul D.
  • 1,785
  • 2
  • 19
  • 25
  • 2
    I'm having the very same issue with Windows sockets. It looks like Windows sockets don't accept bindings on multicast IPs, which makes it imposible to prevent the socket from receiving unrelated trafic from other IP on the same port. – mtctn May 09 '17 at 10:53
  • I'm here to concur with what others have said, after a decent amount of investigation, I haven't found any way to bind to the multicast address and prevent other traffic on the port from coming through. – teeks99 Oct 05 '22 at 12:42

1 Answers1

2

While the doc for bind() does not say that this unsupported, it does say in the remarks:

For multicast operations, the preferred method is to call the bind function to associate a socket with a local IP address and then join the multicast group....

Maybe this scheme will yield better results?

ribram
  • 2,392
  • 1
  • 18
  • 20
  • 2
    Yes, as I mentioned in the original question, you can do this, however it does not prevent a recv on that socket from getting unicast data for the port. I so for have not found a solution, other than to do a WSARecvMsg and examine the packet info to see the real destination address. – Paul D. Jun 03 '11 at 20:10
  • Sorry I thought setsockopt() with IP_ADD_MEMBERSHIP was supposed to filter out non-group traffic for the socket regardless of the address specifiedin bind(). – ribram Jun 03 '11 at 22:00