apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1081120 - in /apr/apr/trunk: network_io/unix/sockaddr.c test/testsock.c
Date Sun, 13 Mar 2011 14:12:03 GMT
Author: trawick
Date: Sun Mar 13 14:12:03 2011
New Revision: 1081120

URL: http://svn.apache.org/viewvc?rev=1081120&view=rev
Log:
apr_sockaddr_info_get() on AIX: Fix a problem which could set
the port field in the native socket address to 1 when 0 was
specified.

An AIX-specific hack to work around a service name limitation
used "1" as the service name, but the 1 was not replaced later.

PR: 46964

Modified:
    apr/apr/trunk/network_io/unix/sockaddr.c
    apr/apr/trunk/test/testsock.c

Modified: apr/apr/trunk/network_io/unix/sockaddr.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sockaddr.c?rev=1081120&r1=1081119&r2=1081120&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sockaddr.c (original)
+++ apr/apr/trunk/network_io/unix/sockaddr.c Sun Mar 13 14:12:03 2011
@@ -58,6 +58,15 @@ struct apr_ipsubnet_t {
 #define GETHOSTBYNAME_BUFLEN 512
 #endif
 
+#ifdef _AIX
+/* Some levels of AIX getaddrinfo() don't like servname = "0", so
+ * set servname to "1" when port is 0 and fix it up later.
+ */
+#define AIX_SERVNAME_HACK 1
+#else
+#define AIX_SERVNAME_HACK 0
+#endif
+
 #ifdef _WIN32_WCE
 /* XXX: BS solution.  Need an HAVE_GETSERVBYNAME and actually
  * do something here, to provide the obvious proto mappings.
@@ -138,6 +147,11 @@ void apr_sockaddr_vars_set(apr_sockaddr_
         addr->sa.sin.sin_port = htons(port);
         addr->port = port;
     }
+#if AIX_SERVNAME_HACK
+    else {
+        addr->sa.sin.sin_port = htons(port);
+    }
+#endif
 
     if (family == APR_INET) {
         addr->salen = sizeof(struct sockaddr_in);
@@ -339,16 +353,12 @@ static apr_status_t call_resolver(apr_so
         hints.ai_flags |= AI_NUMERICHOST;
 #endif
 #else
-#ifdef _AIX
-        /* But current AIX getaddrinfo() doesn't like servname = "0";
-         * the "1" won't hurt since we use the port parameter to fill
-         * in the returned socket addresses later
-         */
+#if AIX_SERVNAME_HACK
         if (!port) {
             servname = "1";
         }
         else
-#endif /* _AIX */
+#endif /* AIX_SERVNAME_HACK */
         servname = apr_itoa(p, port);
 #endif /* OSF1 */
     }

Modified: apr/apr/trunk/test/testsock.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testsock.c?rev=1081120&r1=1081119&r2=1081120&view=diff
==============================================================================
--- apr/apr/trunk/test/testsock.c (original)
+++ apr/apr/trunk/test/testsock.c Sun Mar 13 14:12:03 2011
@@ -80,6 +80,12 @@ static void test_addr_info(abts_case *tc
     rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, 80, 0, p);
     APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);
     ABTS_STR_EQUAL(tc, "127.0.0.1", sa->hostname);
+
+    rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_UNSPEC, 0, 0, p);
+    APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);
+    ABTS_STR_EQUAL(tc, "127.0.0.1", sa->hostname);
+    ABTS_INT_EQUAL(tc, 0, sa->port);
+    ABTS_INT_EQUAL(tc, 0, ntohs(sa->sa.sin.sin_port));
 }
 
 static void test_serv_by_name(abts_case *tc, void *data)



Mime
View raw message