in C++ linux application, how can I get the network interface reffering to each IP on my machine? IP contains: static IP and dynamic IP
Note: I can't use the system call getnameinfo
10x
in C++ linux application, how can I get the network interface reffering to each IP on my machine? IP contains: static IP and dynamic IP
Note: I can't use the system call getnameinfo
10x
You can use the getifaddrs call; however, note that this only retrieves one address per interface. If that's not sufficient, use the rtnetlink protocol over a netlink socket; libnetlink may make this easier.
getifaddrs() is implemented (on Linux) using netlink. It's the right interface (and it can return multiple addresses per interface - they just appear in multiple struct ifaddrs).It's quite tricky to do this, I believe you need to have root access. You need to issue an ioctl (something like SIOCGIFCONF) which then returns you a list of all interfaces, and then you can issue further ioctl calls to extract status information, etc.
ip addr shows it using netlink sockets; and, of course, /bin/ip is not setuid :)