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.
how can i programmatically check whether an address is multicast or broadcast?
-
02-08-2022 - |
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?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow