I am interested in finding the subnet mask of the local host programatically in Linux preferably through the native C api.
getifaddrs() will give you a list of your network interfaces and the field ifa_netmask should be the mask for each.
The ifconfig utility uses ioctl() with the SIOCGIFNETMASK command to get the netmask. But I think Duck's answer is more user-friendly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With