Get IPv6 addresses in linux using ioctl

Get IPv6 addresses in linux using ioctl

This probably won't work.

From man 7 netdevice:

SIOCGIFCONF

Return a list of interface (transport layer) addresses. This currently means only addresses of the AF_INET (IPv4) family for compatibility.

[...]

NOTES

[...]

Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7).


Yes, that ioctl is legacy and won't return IPv6. Each platform has a different way of getting the IPv6 ones:

  • Linux, use NETLINK if you're crazy, use getifaddrs if you have a vaguely recent glibc, otherwise read /proc/net/if_inet6 (eg on Android).
  • Darwin or FreeBSD: use getifaddrs.
  • Solaris, use SIOCGLIFCONF.
  • AIX, use SIOCGIFCONF which actually returns IPv4 and IPv6 addresses (because they have an sa_len field in struct sockaddr they can actually support that).

Tags:

Linux

C

Ipv6

Ioctl