You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2006/10/25 12:54:44 UTC

svn commit: r467600 - in /apr/apr/trunk: CHANGES include/apr_network_io.h network_io/unix/sendrecv.c test/testsockets.c

Author: jorton
Date: Wed Oct 25 03:54:41 2006
New Revision: 467600

URL: http://svn.apache.org/viewvc?view=rev&rev=467600
Log:
Fixes for the implementation, documentation and test case for
apr_socket_recvfrom();

* network_io/unix/sendrecv.c (apr_socket_recvfrom): Reset the socklen
argument correctly before calling recvfrom.  On success, update all
the sockaddr variables for the address returned, not just the port.

* include/apr_network_io.h (apr_socket_recvfrom): Document a little
better.

* test/testsockets.c (sendto_receivefrom): Check that the address is
set correctly.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_network_io.h
    apr/apr/trunk/network_io/unix/sendrecv.c
    apr/apr/trunk/test/testsockets.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?view=diff&rev=467600&r1=467599&r2=467600
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Wed Oct 25 03:54:41 2006
@@ -1,4 +1,8 @@
 Changes for APR 1.3.0
+
+  *) Fix apr_socket_recvfrom() to ensure the peer's address is returned
+     through the "from" parameter.  [Joe Orton]
+
   *) Fix error checking in kqueue, epoll and event port versions of
      apr_pollset_create.  PR 40660, 40661, 40662
      [Larry Cipriani <lvc lucent.com>]

Modified: apr/apr/trunk/include/apr_network_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_network_io.h?view=diff&rev=467600&r1=467599&r2=467600
==============================================================================
--- apr/apr/trunk/include/apr_network_io.h (original)
+++ apr/apr/trunk/include/apr_network_io.h Wed Oct 25 03:54:41 2006
@@ -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/trunk/network_io/unix/sendrecv.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sendrecv.c?view=diff&rev=467600&r1=467599&r2=467600
==============================================================================
--- apr/apr/trunk/network_io/unix/sendrecv.c (original)
+++ apr/apr/trunk/network_io/unix/sendrecv.c Wed Oct 25 03:54:41 2006
@@ -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, 
@@ -172,7 +174,7 @@
         return errno;
     }
 
-    from->port = ntohs(from->sa.sin.sin_port);
+    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/trunk/test/testsockets.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testsockets.c?view=diff&rev=467600&r1=467599&r2=467600
==============================================================================
--- apr/apr/trunk/test/testsockets.c (original)
+++ apr/apr/trunk/test/testsockets.c Wed Oct 25 03:54:41 2006
@@ -159,8 +159,9 @@
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     ABTS_INT_EQUAL(tc, STRLEN, len);
 
-    /* Zero out the port so we can be sure it's been set by recvfrom. */
-    from->port = 0;
+    /* fill the "from" sockaddr with a random address to ensure that
+     * recvfrom sets it up properly. */
+    apr_sockaddr_info_get(&from, "127.1.2.3", APR_INET, 4242, 0, p);
 
     len = 80;
     rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len);