Enumerate all network interfaces with IPs on FreeB

2019-03-01 12:10发布

问题:

My application needs to list all network interafaces on a machine and their IPs, IPv4 and IPv6.

I can get all interfaces with IPv4 IPs using ioctl(SIOCGIFCONF), but I need the IPv6 IPs, too.

On Linux, those can get gotten from /proc/net/if_inet6, but where would I get them on FreeBSD ?

回答1:

getifaddrs(3) provides portable way to get network addresses and interface names.