apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Orton <jor...@redhat.com>
Subject [PATCH] use AI_ADDRCONFIG by default
Date Fri, 11 Jul 2003 09:11:49 GMT
Rationale: Using AF_UNSPEC as the default family passed to getaddrinfo()  
is a bad default in many configurations; it means AAAA queries will be
performed, regardless of whether any IPv6 addresses are configured on
any interfaces (on most systems).  The extra DNS queries mean slower
lookups.

The latest revision of the IPv6 socket extensions (RFC 3493) includes a
new flag, AI_ADDRCONFIG, which tells the resolver to only look up IPv6
addresses if the system has IPv6 configured on any interfaces, and
likewise for IPv4.  This is a good default (in fact the Solaris
getaddrinfo already does this AFAICT).

Any objections to this patch?  The application can still ask for just
IPv4 or just IPv6 if it wants, using the _ADDR_OK flags.

* sockaddr.c (call_resolver): Add AI_ADDRCONFIG to flags for AF_UNSPEC
lookups where supported; retry getaddrinfo call if flag is rejected.

Index: sockaddr.c
===================================================================
RCS file: /home/cvs/apr/network_io/unix/sockaddr.c,v
retrieving revision 1.37
diff -u -r1.37 sockaddr.c
--- sockaddr.c	16 Feb 2003 10:10:20 -0000	1.37
+++ sockaddr.c	11 Jul 2003 08:57:29 -0000
@@ -373,7 +373,22 @@
     memset(&hints, 0, sizeof(hints));
     hints.ai_family = family;
     hints.ai_socktype = SOCK_STREAM;
+#ifdef AI_ADDRCONFIG
+    if (family == AF_UNSPEC) {
+        /* By default, only look up addresses using address types for
+         * which a local interface is configured (i.e. no IPv6 if no IPv6
+         * interfaces. */
+        hints.ai_flags = AI_ADDRCONFIG;
+    }
+#endif
     error = getaddrinfo(hostname, NULL, &hints, &ai_list);
+#ifdef AI_ADDRCONFIG
+    if (error == EAI_BADFLAGS && family == AF_UNSPEC) {
+        /* Retry with no flags if AI_ADDRCONFIG was rejected. */
+        hints.ai_flags = 0;
+        error = getaddrinfo(hostname, NULL, &hints, &ai_list);
+    }
+#endif
     if (error) {
 #ifndef WIN32
         if (error == EAI_SYSTEM) {

Mime
View raw message