Inquiry about Address Ordering in CFHostGetAddressing Function

I have a query regarding the CFHostGetAddressing function that I'm using to retrieve addresses from a host. Specifically, I am curious about the predefined order of IPs in the array returned by this function when multiple IPs are present for a host.

Here are my questions:

  1. In the case where both IPV6 and IPV4 addresses are present for a host, does the CFHostGetAddressing function return the addresses array with IPV6 at the 0th index and IPV4 following it?
  2. If a mapped IPv6 address is present along with an IPV4 address, does the function prioritize placing the mapped IPv6 address first in the addresses array, followed by the IPV4 address?

I would appreciate it if someone could provide insights into any defined order for these scenarios. Additionally, if there is documentation or a reference page specifying this order, kindly point me in the right direction.

Thank you in advance for your assistance.

Apple’s naïve DNS APIs, like CFHost, return the addresses from most to least preferred. However, my general advice is that you not rely on this ordering and instead use a Happy Eyeballs algorithm that’ll avoid long delays regardless of what DNS gives you. The best way to do this is to use one of Apple’s connect-by-name APIs. If you can’t do that, you have to implement Happy Eyeballs yourself.

TN3151 Choosing the right networking API goes into this in some detail, particularly in the Connect by name and BSD Sockets best practices sections.


Stepping back, why are you using CFHost at all? It’s well on its path to deprecation. My general advice:

  • If you’re working with Apple APIs, use a connect-by-name API.

  • If you’re stuck with BSD Sockets, use getaddrinfo [1].

  • If you want to do this asynchronously, using the DNS-SD routine DNSServiceGetAddrInfo.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] As currently implemented, it’ll return results in the same order as CFHost.

@eskimo Than you for your detailed response.

When we say "** Apple’s naïve DNS APIs, like CFHost, return the addresses from most to least preferred **" what does it mean? My queries:

  1. When both IPV6 and IPV4 addresses are present for a host, does the CFHostGetAddressing function return the addresses array with IPV6 at the 0th index and IPV4 following it?
  2. If a mapped IPv6 address is present along with an IPV4 address, does the function prioritize placing the mapped IPv6 address first(0th index) in the addresses array, followed by the IPV4 address(1st index)?
Inquiry about Address Ordering in CFHostGetAddressing Function
 
 
Q