Quick question
Is the good practice for getting a broadcast address to use system calls like ioctl()
or getifaddrs()
, or are they obsolete/useless because of the following two reasons?
- I can make a binary OR between the netmask and the IP
- The broadcast address is not always set anyway
Details
I am playing with some UDP broadcast code, both on my Arch Linux machine and on some Ubuntu Docker containers.
I see that some interfaces have the broadcast address set, for instance my wifi interface on Arch Linux (from $ ip addr
):
inet 192.168.0.11/24 brd 192.168.0.255 scope global wlp4s0
And some don't, for instance the eth0
interface on an Ubuntu Docker container:
inet 172.17.0.5/16 scope global eth0
However, if I send packets to 172.17.255.255
, they are actually broadcasted to other machines on the network.
On this question it is said that it is not necessary to set the broadcast address manually. And here, somebody seems to imply that Docker purposely doesn't set the broadcast address, for some reason I don't undertand.
So I get to wonder: what is the right way to detect the broadcast address for a network interface?