Question

Given an address on which to listen for incoming data, I want to be able to set the proper socket options to listen for incoming data via broadcast or multicast depending on the address I am given. I know multicast adheres to a certain range, so is checking that the address falls within the range from 224.0.0.0 to 239.255.255.255 sufficient to distinguish this or could a broadcast address fall within that range?

Was it helpful?

Solution

Yes. You can simply check the first octet of the IPv4 address, if it starts with 1110, it is an IPv4 multicast address. Beware of host vs network byte ordering when checking an IPv4 address represented in binary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top