IPv6 on iOS
iOS 4 and IPv6
iOS 4 incorporated the full network stack of the CoreOS, that means, basically, support for IPv6.
Apple has added initial support for DHCPv6 for DNS server addresses, search domains, etc. Essentially, the Core Network layer uses the stateless capability of IPv6 to gather the IP address, but uses DHCPv6 to get other important information.
Any code that uses CFNetwork, already complies with IPv6. The same may not be true for legacy code. In that case, or if you need to write your own code to deal with the network, there are a few things to take care of, particularly, you should never assume how an IP address is going to look like:
- Storing data structures should support 128bits IP addresses
- Use address independent hostnames lookups (
getaddrinfo) - Use
sockaddrs, notin_addr/in6_addr - Listen only to IPv6 connections
- avoid using functions/data structures that are IPv4 specific
You might get different responses from DNS servers. A combination of IPv4 and IPv6 as a response to a DNS resolution query is very likely. And if you are storing IP addresses, you need to make sure to support these two types. You can’t know for sure how an IP address is going to look like, they might be 128bits. Use only address independent API for hostnames lookups (getaddrinfo). And since you cannot know for sure the structure of the address, you should first call getaddrinfo, then allocate your socket, and perform the connection. Because Apple translates the IPv4 connections to IPv6, you don’t need to listen to v4 anymore.