apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r584889 - in /apr/apr/branches/1.2.x: CHANGES include/apr_network_io.h network_io/unix/sendrecv.c network_io/win32/sendrecv.c test/testsockets.c
Date Mon, 15 Oct 2007 20:16:16 GMT
Author: wrowe
Date: Mon Oct 15 13:16:15 2007
New Revision: 584889

URL: http://svn.apache.org/viewvc?rev=584889&view=rev
Log:
Apply both the Unix and Win32 fix, filling in the port and
address after initially providing enough sa space by fixing
the structure length.

Enhances the test introduced by Joe in 467600 to also invert
the original IP structure as an IPv6 entity for IPv4 tests, 
if IPv6 is present.  I settled on a test IP which Win32 just
happens to tollerate if an IPv6 adapter isn't present.

Authors: jorton, wrowe
Backports: 467600 complete

Modified:
    apr/apr/branches/1.2.x/CHANGES
    apr/apr/branches/1.2.x/include/apr_network_io.h
    apr/apr/branches/1.2.x/network_io/unix/sendrecv.c
    apr/apr/branches/1.2.x/network_io/win32/sendrecv.c
    apr/apr/branches/1.2.x/test/testsockets.c

Modified: apr/apr/branches/1.2.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/CHANGES?rev=584889&r1=584888&r2=584889&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.2.x/CHANGES [utf-8] Mon Oct 15 13:16:15 2007
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.2.12
 
+  *) Fix apr_socket_recvfrom() to ensure the peer's port and address
+     is returned through the "from" parameter on Unix and Win32.  
+     [Joe Orton, William Rowe]
+
   *) The WIN32 cleanup routine for shared memory segments could wrongly
      return unknown errors and leak a open handle.
      [Joe Mudd <Joe.Mudd sas.com>]

Modified: apr/apr/branches/1.2.x/include/apr_network_io.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/include/apr_network_io.h?rev=584889&r1=584888&r2=584889&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/include/apr_network_io.h (original)
+++ apr/apr/branches/1.2.x/include/apr_network_io.h Mon Oct 15 13:16:15 2007
@@ -507,7 +507,11 @@
                                             apr_size_t *len);
 
 /**
- * @param from The apr_sockaddr_t to fill in the recipient info
+ * Read data from a socket.  On success, the address of the peer from
+ * which the data was sent is copied into the @param from parameter,
+ * and the @param len parameter is updated to give the number of bytes
+ * written to @param buf.
+ * @param from Updated with the address from which the data was received
  * @param sock The socket to use
  * @param flags The flags to use
  * @param buf  The buffer to use

Modified: apr/apr/branches/1.2.x/network_io/unix/sendrecv.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/network_io/unix/sendrecv.c?rev=584889&r1=584888&r2=584889&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/network_io/unix/sendrecv.c (original)
+++ apr/apr/branches/1.2.x/network_io/unix/sendrecv.c Mon Oct 15 13:16:15 2007
@@ -148,6 +148,8 @@
                                  apr_size_t *len)
 {
     apr_ssize_t rv;
+    
+    from->salen = sizeof(from->sa);
 
     do {
         rv = recvfrom(sock->socketdes, buf, (*len), flags, 
@@ -171,6 +173,9 @@
         (*len) = 0;
         return errno;
     }
+
+    apr_sockaddr_vars_set(from, from->sa.sin.sin_family, 
+                          ntohs(from->sa.sin.sin_port));
 
     (*len) = rv;
     if (rv == 0 && sock->type == SOCK_STREAM) {

Modified: apr/apr/branches/1.2.x/network_io/win32/sendrecv.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/network_io/win32/sendrecv.c?rev=584889&r1=584888&r2=584889&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/network_io/win32/sendrecv.c (original)
+++ apr/apr/branches/1.2.x/network_io/win32/sendrecv.c Mon Oct 15 13:16:15 2007
@@ -190,12 +190,18 @@
 {
     apr_ssize_t rv;
 
+    from->salen = sizeof(from->sa);
+
     rv = recvfrom(sock->socketdes, buf, (int)*len, flags, 
                   (struct sockaddr*)&from->sa, &from->salen);
     if (rv == SOCKET_ERROR) {
         (*len) = 0;
         return apr_get_netos_error();
     }
+
+    apr_sockaddr_vars_set(from, from->sa.sin.sin_family, 
+                          ntohs(from->sa.sin.sin_port));
+
     (*len) = rv;
     if (rv == 0 && sock->type == SOCK_STREAM)
         return APR_EOF;

Modified: apr/apr/branches/1.2.x/test/testsockets.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/test/testsockets.c?rev=584889&r1=584888&r2=584889&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/test/testsockets.c (original)
+++ apr/apr/branches/1.2.x/test/testsockets.c Mon Oct 15 13:16:15 2007
@@ -103,8 +103,8 @@
 }
 #endif
 
-static void sendto_receivefrom_helper(abts_case *tc, const char *addr, 
-                                      const char *junkaddr, int family)
+static void sendto_receivefrom_helper(abts_case *tc, const char *addr,
+                                      int family)
 {
     apr_status_t rv;
     apr_socket_t *sock = NULL;
@@ -157,9 +157,16 @@
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     ABTS_SIZE_EQUAL(tc, STRLEN, len);
 
-    /* fill the "from" sockaddr with a random address to ensure that
-     * recvfrom sets it up properly. */
-    rv = apr_sockaddr_info_get(&from, junkaddr, family, 4242, 0, p);
+    /* fill the "from" sockaddr with a random address from another
+     * family to ensure that recvfrom sets it up properly. */
+#if APR_HAVE_IPV6
+    if (family == APR_INET)
+        rv = apr_sockaddr_info_get(&from, "3ffE:816e:abcd:1234::1",
+                                   APR_INET6, 4242, 0, p);
+    else
+#else
+        rv = apr_sockaddr_info_get(&from, "127.1.2.3", APR_INET, 4242, 0, p);
+#endif
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
 
     len = 80;
@@ -180,7 +187,7 @@
 static void sendto_receivefrom(abts_case *tc, void *data)
 {
     int failed;
-    sendto_receivefrom_helper(tc, "127.0.0.1",  "127.1.2.3", APR_INET);
+    sendto_receivefrom_helper(tc, "127.0.0.1", APR_INET);
     failed = tc->failed; tc->failed = 0;
     ABTS_TRUE(tc, !failed);
 }
@@ -189,7 +196,7 @@
 static void sendto_receivefrom6(abts_case *tc, void *data)
 {
     int failed;
-    sendto_receivefrom_helper(tc, "::1", "FA0E::1234:127.1.2.3", APR_INET6);
+    sendto_receivefrom_helper(tc, "::1", APR_INET6);
     failed = tc->failed; tc->failed = 0;
     ABTS_TRUE(tc, !failed);
 }



Mime
View raw message