c++ linux - getting the interface from IP
in C++ linux application, how can I get the network interface reffering to each IP on my machine? IP contains: static IP and dy开发者_运维百科namic 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.
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.
精彩评论