Search code examples
ipv6getaddrinfo

Will getaddrinfo() return IPv6 addresses first?


I want to read all the addresses(IPv4 and IPv6) using getaddrinfo(). My question is whether getaddrinfo() returns IPv6 address followed by IPv4 in the list. Assuming that I'm passing AF_UNSPEC to getaddrinfo() and using dual stack.


Solution

  • As already commented by Celada, RFC 3484 gives a suggested ordering for the returned results.

    Specifically for GNU libc, the order can be controlled by /etc/gai.conf and customised as local policy.