apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/network_io/win32 sockets.c
Date Mon, 01 Apr 2002 14:18:22 GMT
trawick     02/04/01 06:18:22

  Modified:    network_io/os2 sockets.c
               network_io/win32 sockets.c
  Log:
  simplify sockaddr manipulation code a little bit
  
  point out some possible bugs (see "XXX" comments)
  
  Revision  Changes    Path
  1.52      +4 -29     apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/sockets.c,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- sockets.c	13 Mar 2002 20:39:24 -0000	1.51
  +++ sockets.c	1 Apr 2002 14:18:22 -0000	1.52
  @@ -87,35 +87,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_sockaddr_vars_set(sock->local_addr, family, 0);
  +    apr_sockaddr_vars_set(sock->remote_addr, family, 0);
   }
   
   static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
  @@ -223,6 +196,8 @@
       if ((*new)->socketdes < 0) {
           return APR_OS2_STATUS(sock_errno());
       }
  +    /* XXX fix up any pointers which are no longer valid (or just call
  +     *     apr_sockaddr_vars_set() to do it */
       (*new)->remote_addr->port = ntohs((*new)->remote_addr->sa.sin.sin_port);
       apr_pool_cleanup_register((*new)->cntxt, (void *)(*new), 
                           socket_cleanup, apr_pool_cleanup_null);
  
  
  
  1.74      +14 -32    apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- sockets.c	13 Mar 2002 20:39:25 -0000	1.73
  +++ sockets.c	1 Apr 2002 14:18:22 -0000	1.74
  @@ -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_sockaddr_vars_set(sock->local_addr, family, 0);
  +    apr_sockaddr_vars_set(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;
  
  
  

Mime
View raw message