Reputation: 1031
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
Upvotes: 1
Views: 1792
Reputation: 33645
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.
Upvotes: 2
Reputation: 231373
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.
Upvotes: 3