سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top