Index: subversion/libsvn_ra_svn/client.c
===================================================================
--- subversion/libsvn_ra_svn/client.c	(révision 15353)
+++ subversion/libsvn_ra_svn/client.c	(copie de travail)
@@ -99,33 +99,54 @@
 {
   apr_sockaddr_t *sa;
   apr_status_t status;
-  int family = APR_INET;
-  
-  /* Make sure we have IPV6 support first before giving apr_sockaddr_info_get
-     APR_UNSPEC, because it may give us back an IPV6 address even if we can't
-     create IPV6 sockets.  */  
 
+  /* There seems to be a short coming in Apache Runtime so that you cannot
+     resolve both IPv6 and IPv4 properly as getaddrinfo(). If you don't
+     specify a socket family (APR_UNSPEC), it will return either an IPv6
+     socket address or an IPv4 address but can't return both (the API design
+     doesn't allow such a thing).
+     The unfortunate consequence is that we must try IPv6 and IPv4
+     explicitly separately. Checking whether the host has an IPv6 stack is
+     not sufficient, as more and more hosts have an IPv6 stack but no IPv6
+     connectivity (ie. IPv6 socket() succeeds, but IPv6 connect() fails).
+
+     ###  As for many other dual-stack programs, there is no clear policy
+     as to which error should be reported if both IPv4 and IPv6 fails.
+     OpenSSH prints both error messages. Most other programs only print the
+     last one (normally the IPv4 one). We do that too for now. */
+
 #if APR_HAVE_IPV6
+  /* Resolve the AAAA hostname. */
+  status = apr_sockaddr_info_get(&sa, hostname, APR_INET6, port, 0, pool);
+  if (status == 0)
+  {
+    /* Create the IPv6 socket. */
 #ifdef MAX_SECS_TO_LINGER
-  status = apr_socket_create(sock, APR_INET6, SOCK_STREAM, pool);
+    /* ### old APR interface */
+    status = apr_socket_create(sock, sa->family, SOCK_STREAM, pool);
 #else
-  status = apr_socket_create(sock, APR_INET6, SOCK_STREAM,
-                             APR_PROTO_TCP, pool);
+    status = apr_socket_create(sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, 
+                               pool);
 #endif
-  if (status == 0)
+    if (status == 0)
     {
-      apr_socket_close(*sock);
-      family = APR_UNSPEC;
+      status = apr_socket_connect(*sock, sa);
+      if (status == 0)
+        return SVN_NO_ERROR; /* IPv6 works */
+      else
+        apr_socket_close(*sock);
     }
+  }
 #endif
+  /* IPv6 failed - fallback to IPv4 */
 
-  /* Resolve the hostname. */
-  status = apr_sockaddr_info_get(&sa, hostname, family, port, 0, pool);
+  /* Resolve the A hostname. */
+  status = apr_sockaddr_info_get(&sa, hostname, APR_INET, port, 0, pool);
   if (status)
     return svn_error_createf(status, NULL, _("Unknown hostname '%s'"),
                              hostname);
 
-  /* Create the socket. */
+  /* Create the IPv4 socket. */
 #ifdef MAX_SECS_TO_LINGER
   /* ### old APR interface */
   status = apr_socket_create(sock, sa->family, SOCK_STREAM, pool);


