Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top