I trying to get IPv6 addresses in my linux OS like following:
sd = Socket_m(AF_INET6_m, SOCK_DGRAM_m, 0);
ifc.ifc_buf = buffer_p;
ifc.ifc_len = buffSize;
Ioctl_m(sd, SIOCGIFCONF, &ifc);
It works succesfully if any IPv4 address are configured for interface, but if interface has only one IPv6 address it is not returned by ioctl.
For example, I unable to get IPv6 address of the followith interface because only IPv6 address is configured:
br1 Link encap:Ethernet HWaddr 00:10:18:2D:BB:34
inet6 addr: fe80::210:18ff:fe2d:be54/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:194244850 errors:0 dropped:0 overruns:0 frame:0
TX packets:72005 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12331900995 (11760.6 Mb) TX bytes:6192406 (5.9 Mb)
To check whether a CS Linux server is running IPv4 or IPv6, use the command ifconfig -a and look at the IP address or addresses in the output.
DESCRIPTION. The inet6 family is an updated version of inet(4) family. While inet(4) implements Internet Protocol version 4, inet6 implements Internet Protocol version 6. inet6 is a collection of protocols layered atop the Internet Protocol version 6 (IPv6) transport layer, and utilizing the IPv6 address format.
An IPv6 address is a 128-bit alphanumeric value that identifies an endpoint device in an Internet Protocol Version 6 (IPv6) network. IPv6 is the successor to a previous addressing infrastructure, IPv4, which had limitations IPv6 was designed to overcome.
Yes, that ioctl is legacy and won't return IPv6. Each platform has a different way of getting the IPv6 ones:
getifaddrs
if you have a vaguely recent glibc, otherwise read /proc/net/if_inet6
(eg on Android).getifaddrs
.SIOCGLIFCONF
.SIOCGIFCONF
which actually returns IPv4 and IPv6 addresses (because they have an sa_len
field in struct sockaddr
they can actually support that).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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With