You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jf...@apache.org on 2008/08/21 11:20:21 UTC

svn commit: r687661 - /tomcat/connectors/trunk/jni/native/src/address.c

Author: jfclere
Date: Thu Aug 21 02:20:21 2008
New Revision: 687661

URL: http://svn.apache.org/viewvc?rev=687661&view=rev
Log:
When apr_sockaddr_info_get returns several address and we want to
bind() to all IP of the machine we should use the IPv6 address for
that. The mapping IPv4 to IPv6 will then bind() to all addresses.

Modified:
    tomcat/connectors/trunk/jni/native/src/address.c

Modified: tomcat/connectors/trunk/jni/native/src/address.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jni/native/src/address.c?rev=687661&r1=687660&r2=687661&view=diff
==============================================================================
--- tomcat/connectors/trunk/jni/native/src/address.c (original)
+++ tomcat/connectors/trunk/jni/native/src/address.c Thu Aug 21 02:20:21 2008
@@ -30,6 +30,7 @@
     apr_pool_t *p = J2P(pool, apr_pool_t *);
     TCN_ALLOC_CSTRING(hostname);
     apr_sockaddr_t *sa = NULL;
+    apr_sockaddr_t *sl = NULL;
     apr_int32_t f;
 
 
@@ -38,10 +39,26 @@
     TCN_THROW_IF_ERR(apr_sockaddr_info_get(&sa,
             J2S(hostname), f, (apr_port_t)port,
             (apr_int32_t)flags, p), sa);
+    sl = sa;
+    /* 
+     * apr_sockaddr_info_get may return several address so this is not
+     * go to work in some cases (but as least it works for Linux)
+     * XXX: with AP_ENABLE_V4_MAPPED it is going to work otherwise it won't.
+     */
+#if APR_HAVE_IPV6
+    if (hostname == NULL) {
+        /* Try all address using IPV6 one */
+        while (sl) {
+            if (sl->family == APR_INET6)
+                break; /* Done */
+            sl = sl->next;
+        }
+    }
+#endif
 
 cleanup:
     TCN_FREE_CSTRING(hostname);
-    return P2J(sa);
+    return P2J(sl);
 }
 
 TCN_IMPLEMENT_CALL(jstring, Address, getnameinfo)(TCN_STDARGS,



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org