How Unicast Global Addresses Work for IPv6 on Android Devices

advertisements

I am developing an android app and I need to find Global Unicast Addresses for android device without make any network requests. (that should be easy if we can make network request since we can therefore see the outfacing public ipv6 in header). What I want to see is how to find unicast address before we make network request.

I have used APIs to retrieve all the possible IPv6 from all interfaces. then I focus on the IPs falling into 2000::/3 range. However, sometimes I got only one IPv6 ( which is the right answer), sometimes I got two/multiple address in 2000::/3 range. I assume this scenario might cause by network status changes, but I am not sure.

for example: the API returns me the following two IPv6s

2600:1010:b022:1349:d25c:f9bf:2881:d30c%3%3 and 2600:1010:8043"3aba:67ca:ac76:4a8f:dbdb%9%9

Can anyone tell me how global unicast IPv6 works on android devices? How can I ensure I am getting the real IPv6 and not the temporary one?


With Privacy Extensions, the temporary address is what the rest of the world will normally use. It periodically changes to try to prevent anyone from associating your address with you. How Privacy Extension is implemented is OS dependent, but, generally, you will get a temporary address for a while, change to a new temporary address, and the old temporary address will still be available but deprecated for a while before it goes away. The real address will not change, but it is not normally used where other devices will see it. This behavior is OS-dependent, so your mileage may vary.

The real answer to your question depends on what you intend to do with the address. You may really want the temporary address instead of the DHCP or SLAAC assigned address, but you must then realize it will change.

Also, the %3%3 or %9%9 in your addresses are not really part of an IPv6 address; they are indicators of the interface to which the address is assigned. (A link-local address needs this since the link-local address may be the same on multiple interfaces.) I'm not sure, but you may be looking at two completely different interfaces (connections to different sources like Wi-Fi, and cellular, or two different cellular towers?).