getifaddrs never specifies broadcast addresses

Apple “Feedback” #12149764.

According to man 3 getifaddrs:

The ifa_dstaddr field references the destination address on a P2P interface, if one exists, otherwise it contains the broadcast address.

In my testing the ifa_dstaddr field is never non-null. I’m not sure I have any suitably configured P2P interfaces, but I definitely have interfaces with broadcast capabilities and getifaddrs reports them as having no broadcast address (even though it correctly notes they support broadcasting, in ifa_flags).

This is on macOS Ventura 13.3.1. I have no idea if this applies to other versions of macOS, or other OS’s.

It appears there’s a workaround, though – the broadcast address is deterministic based on the IP address & netmask, according to Wikipedia, so you don’t technically need getifaddrs to spell it out for you. That’s for AF_INET (IPv4) networks. IPv6 doesn’t really have the same notion of a broadcast address anyway, and for other network types I have no idea if the concept applies or if there’s workarounds for this getifaddr bug.

Leave a Comment