0

I am trying to get network interface information from struct ifaddrs

How can I determine if the interface I am looking at is of inet (ipv4) or inet6 (ipv6)?

hari
  • 9,439
  • 27
  • 76
  • 110

3 Answers3

3

You test the ifa_addr->sa_family - it will be AF_INET for IPv4 addresses, and AF_INET6 for IPv6 addresses.

You can then cast the ifa_addr member to either struct sockaddr_in * or struct sockaddr_in6 * as appropriate.

caf
  • 233,326
  • 40
  • 323
  • 462
0

In FreeBSD, assuming you've got kernel support for both, the question of IPv4 vs IPv6 is just a matter of configuration.

The "GENERIC" kernel in FreeBSD includes the "INET6" option, which gives you IPV6. If you haven't rebuilt your kernel and excluded that option, then you have IPv6 on any interface simply by configuring an IPv6 address.

ghoti
  • 45,319
  • 8
  • 65
  • 104
0

You could try to open an IPV6 socket on the interface to see if it supports IPV6.

nerozehl
  • 463
  • 1
  • 7
  • 19