apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject [PATCH] a little network_io cleanup for Win32
Date Thu, 28 Mar 2002 18:29:15 GMT
not tested, not even compiled

Index: network_io/win32/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/win32/sockets.c,v
retrieving revision 1.73
diff -u -r1.73 sockets.c
--- network_io/win32/sockets.c	13 Mar 2002 20:39:25 -0000	1.73
+++ network_io/win32/sockets.c	28 Mar 2002 18:29:59 -0000
@@ -59,6 +59,8 @@
 #include "apr_portable.h"
 #include <string.h>
 
+static char generic_inaddr_any[16] = {0}; /* big enough for IPv4 or IPv6 */
+
 static apr_status_t socket_cleanup(void *sock)
 {
     apr_socket_t *thesocket = sock;
@@ -75,35 +77,8 @@
 static void set_socket_vars(apr_socket_t *sock, int family, int type)
 {
     sock->type = type;
-    sock->local_addr->family = family;
-    sock->local_addr->sa.sin.sin_family = family;
-    sock->remote_addr->family = family;
-    sock->remote_addr->sa.sin.sin_family = family;
-
-    if (family == AF_INET) {
-        sock->local_addr->salen = sizeof(struct sockaddr_in);
-        sock->local_addr->addr_str_len = 16;
-        sock->local_addr->ipaddr_ptr = &(sock->local_addr->sa.sin.sin_addr);
-        sock->local_addr->ipaddr_len = sizeof(struct in_addr);
-
-        sock->remote_addr->salen = sizeof(struct sockaddr_in);
-        sock->remote_addr->addr_str_len = 16;
-        sock->remote_addr->ipaddr_ptr = &(sock->remote_addr->sa.sin.sin_addr);
-        sock->remote_addr->ipaddr_len = sizeof(struct in_addr);
-    }
-#if APR_HAVE_IPV6
-    else if (family == AF_INET6) {
-        sock->local_addr->salen = sizeof(struct sockaddr_in6);
-        sock->local_addr->addr_str_len = 46;
-        sock->local_addr->ipaddr_ptr = &(sock->local_addr->sa.sin6.sin6_addr);
-        sock->local_addr->ipaddr_len = sizeof(struct in6_addr);
-
-        sock->remote_addr->salen = sizeof(struct sockaddr_in6);
-        sock->remote_addr->addr_str_len = 46;
-        sock->remote_addr->ipaddr_ptr = &(sock->remote_addr->sa.sin6.sin6_addr);
-        sock->remote_addr->ipaddr_len = sizeof(struct in6_addr);
-    }
-#endif
+    apr_set_sockaddr_vars(sock->local_addr, family, 0);
+    apr_set_sockaddr_vars(sock->remote_addr, family, 0);
 }                                                                                       
          
 static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
 {
@@ -244,6 +219,7 @@
     (*new)->disconnected = 0;
 
     (*new)->sock = s;
+    /* XXX next line looks bogus w.r.t. AF_INET6 support */
     (*new)->remote_addr->salen = sizeof((*new)->remote_addr->sa);
     memcpy (&(*new)->remote_addr->sa, &sa, salen);
     *(*new)->local_addr = *sock->local_addr;
@@ -270,7 +246,9 @@
     }
 
     if (sock->local_interface_unknown ||
-        sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
+        !memcmp(sock->local_addr->ipaddr_ptr,
+                generic_inaddr_any,
+                sock->local_addr->ipaddr_len)) {
         /* If the interface address inside the listening socket's local_addr wasn't
          * up-to-date, we don't know local interface of the connected socket either.
          *
@@ -349,8 +327,12 @@
     if (sock->local_addr->sa.sin.sin_port == 0) {
         sock->local_port_unknown = 1;
     }
-    if (sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
-        /* must be using free-range port */
+    if (!memcmp(sock->local_addr->ipaddr_ptr,
+                generic_inaddr_any,
+                sock->local_addr->ipaddr_len) {
+        /* not bound to specific local interface; connect() had to assign
+         * one for the socket
+         */
         sock->local_interface_unknown = 1;
     }
     return APR_SUCCESS;

-- 
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...

Mime
View raw message