Finding subnet mask on Linux in C

user1483918 picture user1483918 · Jun 26, 2012 · Viewed 7k times · Source

I am interested in finding the subnet mask of the local host programatically in Linux preferably through the native C api.

Answer

Duck picture Duck · Jun 26, 2012

getifaddrs() will give you a list of your network interfaces and the field ifa_netmask should be the mask for each.