Discussion:
[asio-users] Difference in bind ability and broadcast UDP reception between OS
Mark Jones
2011-11-15 19:54:01 UTC
Permalink
Hi everyone,

I am seeing something that I wanted to share with the list to see if others have seen and whether this is expected behavior or not.

I have an incoming packet that is addressed to 255.255.255.255 and in order to receive this packet on Windows, I need not do anything special, it will be received by the socket that is bound to the endpoint of the IP address of the Ethernet card that I am receiving the packet on.

In other words, this broadcast UDP packet can be picked up by the socket that is bound the following way:

mainSocket.open(udp::v4());
ethernetCardEndpoint = udp::endpoint(address_v4(static_cast<uint32_t>(ethIFaceInfo.ipAddress)), port);
mainSocket.bind(ethernetCardEndpoint);

However, on Linux, I also had to add another socket in that is bound to an endpoint that is for the broadcast address, address_v4::broadcast(), in order to receive the packet that is addressed to the broadcast address:

broadcastReceiveSocket.open(udp::v4());
broadcastEndpoint = udp::endpoint(address_v4::broadcast(), port);
broadcastReceiveSocket.bind(broadcastEndpoint);

Why is the broadcast UDP packet not received by the main socket as it is on Windows?

As mentioned, this same binding to the broadcast address on Windows is not needed, however if I try to do so it will fail on the call to bind on that 2nd socket that I am trying to bind to the endpoint for the broadcast address. So, I guess I should not attempt to bind to the broadcast address on Windows, and that is OK since it doesn't seem to be needed anyway. However, why does attempting to bind to the endpoint for the broadcast address fail on Windows?

On Mac OS X, the behavior is the following. The bind to the broadcast endpoint will fail, just as on Windows. So, why does it work on Linux, but not on Windows or Mac? However, the broadcast packet will not be received by the main socket that is bound to the endpoint that matches the Ethernet card address either. So on Mac OS the broadcast UDP packet cannot be received at all. Why is it not picked up by the main socket as it is on Windows or why doesn't the bind to the broadcast endpoint work as it does on Linux so that it might be received by the socket bound to the broadcast endpoint?

Has anyone seen this before?

Thanks,
Mark
Arash Partow
2011-11-15 20:12:38 UTC
Permalink
Post by Mark Jones
However, on Linux, I also had to add another socket in that is bound to
an endpoint that is for the broadcast address, address_v4::broadcast(),
This might be a red herring, but are you setting the socket options correctly?

boost::asio::socket_base::broadcast option(true);
mainSocket.set_option(option);
broadcastReceiveSocket.set_option(option);
Mark Jones
2011-11-16 14:47:49 UTC
Permalink
Hi Arash,

I have that set on the sockets, but that is only for outgoing packets as far as I can tell from the documentation of the socket option and so I don't think that is applicable in this case.

Mark


From: Arash Partow <***@...>
Subject: Re: Difference in bind ability and broadcast UDP reception between OS
Newsgroups: gmane.comp.lib.boost.asio.user
Date: 2011-11-15 20:12:38 GMT (18 hours and 33 minutes ago)
Post by Mark Jones
However, on Linux, I also had to add another socket in that is bound to
an endpoint that is for the broadcast address, address_v4::broadcast(),
This might be a red herring, but are you setting the socket options correctly?

boost::asio::socket_base::broadcast option(true);
mainSocket.set_option(option);
broadcastReceiveSocket.set_option(option);

Loading...