Find available network interfaces in C/C++?

See the getifaddrs man page. There is an example program towards the end.


If you're looking for this in context of a desktop application, and you want to be notified of changes (e.g. interfaces connecting/disconnecting), consider using DBus to monitor NetworkManager.

http://projects.gnome.org/NetworkManager/developers/api/09/spec.html

You can enumerate interfaces, as well as interface-specific things (like available and connected WiFi access points, configured-but-not-dialed PPP links, and so forth), and if anything changes, you'll receive a notification over the DBus.

(If this is for something more like a server program, where you expect the network configuration to remain more stable, then things like getifaddrs are possibly more appropriate.)