user1483918
user1483918

Reputation: 31

Finding subnet mask on Linux in C

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

Upvotes: 3

Views: 8835

Answers (2)

jedwards
jedwards

Reputation: 30200

The ifconfig utility uses ioctl() with the SIOCGIFNETMASK command to get the netmask. But I think Duck's answer is more user-friendly.

Upvotes: 2

Duck
Duck

Reputation: 27542

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

Upvotes: 8

Related Questions