Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect temporary ipv6 address crossplatform

I want to detect if an address is temporary ipv6 address, i using getifaddrs to get the list of addresses but don't know how to get that info from there. And if possible i want that to work for linux, osx, solaris and windows.

I have seems that in Linux IFA_F_TEMPORARY is set in inet6_ifaddr->ifa_flags, but not sure if how can i get that from the ifaddrs returned by getifaddrs.

Seems that on OSX i need octl with SIOCSIFINFO_FLAGS, and i have no idea about Solaris or Windows.

has any body a sample code that could do that.

like image 876
José Avatar asked Jul 24 '13 12:07

José


People also ask

Why do I have so many temporary IPv6 addresses?

It's completely normal to have multiple IPv6 addresses on one device. A device generates new 64 bits every once in a while and uses that in the IPv6 address. Because new addresses are generated regularly the addresses are marked as temporary interfaces.

How often does a temporary IPv6 address change?

This random number becomes the interface ID segment of the IPv6 address. A link-local address is not generated with the temporary address as the interface ID. Be aware that temporary addresses have a default preferred lifetime of one day.

Can you track IPv6 address?

To use the IPv6 traceroute tool, simply select Trace 6, enter the IP address or hostname and click Do. 4or6 - This tool allows you to select whether to perform an IPv4 or IPv6 traceroute specifically. Additionally, you can also select the auto option.


1 Answers

Updated (Aug 3, 2016): After searching on and off for the past couple months on this question (because I'm actually in need of this answer myself). I believe I have found the Windows-centric answer. I've only tested this on Windows 10, so I don't know about older versions. But this API shouldn't have changed if someone wants to verify it for me :-)

All _IP_ADAPTER_UNICAST_ADDRESS structures have an enumeration for the address prefix and suffix. I've now bothered to look at them and they are the entire key to solving this issue!

What is a Temporary IPv6 address....it's an address with a RANDOM SUFFIX! So for all IPv6 addresses in a IP_ADAPTER_UNICAST_ADDRESS look at the IP_SUFFIX_ORIGIN see if it is IpSuffixOriginRandom. Thats...it.

I'm really still shocked at how little there on this topic online and this will be a huge issue in a few years for network application developers if no one knows how to solve this issue for server-side applications (even ones running on consumer PCs)

You heard the answer here first!!!


(Original Answer): I've been looking at this exact topic for a cross-platform application as well. I think I've found "a" way to filter IPv6 temporary addresses in Windows. Basically RFC 4941 claims temporary addresses must:

  1. Have a Valid Lifetime less than the "Public" Address
  2. Have a Preferred Lifetime less than the "Public" Address

So for C++, when using a function like GetAdaptersAddresses you can look in the PIP_ADAPTER_ADDRESSES struct for the _IP_ADAPTER_UNICAST_ADDRESS struct and evaluate the ValidLifetime and PreferredLifetime members. After filtering for address type (if you need to know Local-Link vs Public) you can keep a running tally of the largest lifetime. The largest life time (per adapter) should be the public address!

To see the address lifetime info quickly run the Windows terminal command: netsh interface ipv6 show address

You can see all temporary addresses are much smaller than the defaulted SLAAC lifetimes.

I'm working with this assumption for now until testing proves otherwise. All Temporary addresses are based on the public and so cannot out live it.

Hope this helps

like image 72
Josh Avatar answered Sep 16 '22 11:09

Josh