سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

The answer is here:

http://tools.ietf.org/html/rfc6724

Operating systems should (and mostly do) follow this standard or the previous version of it. While getaddrinfo() chooses the destination address, the kernel then selects the source address if the application doesn't bind to a specific one.

By default, global native IPv6 addresses are preferred over all IPv4 addresses.

That actually depends on the name server and OS. getaddrinfo() fetches the dns resolution info from the name server. If your name server orders IPv6 addresses before IPv4 addresses it will return IPv6 addresses before IPv4 addresses.

By default IPv6 addresses has better priority than IPv4 addresses. @Pavel Simerda wrote- "By default, global native IPv6 addresses are preferred over all IPv4 addresses."

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top