about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--sysdeps/posix/getaddrinfo.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 3cbd0334dd..3121d3bb65 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -2435,7 +2435,11 @@ getaddrinfo (const char *name, const char *service,
       return EAI_FAMILY;
     }
 
-  if (naddrs > 1)
+  /* We don't want to sort the localhost addresses used for passive
+     binding; if the caller asked for both address types, we want to
+     return IPv6+IPv4 before IPv4, because if we bind to IPv4 first,
+     the IPv6 bind will fail.  */
+  if (naddrs > 1 && (name || (hints->ai_flags & AI_PASSIVE) == 0))
     {
       /* Read the config file.  */
       __libc_once_define (static, once);