httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/network_io/win32 sockaddr.c sockets.c sockopt.c
Date Thu, 16 Nov 2000 01:51:37 GMT
trawick     00/11/15 17:51:37

  Modified:    src/lib/apr/include apr_network_io.h
               src/lib/apr/include/arch/unix networkio.h
               src/lib/apr/network_io/unix sa_common.c sockaddr.c sockets.c
                        sockopt.c
               src/lib/apr/include/arch/win32 networkio.h
               src/lib/apr/network_io/win32 sockaddr.c sockets.c sockopt.c
  Log:
  This is a small step toward's David Reid's IPv6 patch.  I started
  with the part of David's patch which uses apr_sockaddr_t instead of
  sockaddr_in inside apr_socket_t, got everything to compile (and seem
  to run properly on Unix), and simplified some of the code which
  allocates storage for apr_socket_t and fills out fields in
  apr_sockaddr_t.
  
  I didn't add all the code from the patch that supports IPv6
  throughout.  I didn't add any of the API enhancements.
  
  This includes a port of the code to Win32.  I'll later commit the
  required changes for OS/2.
  
  Submitted by:	David Reid
  Reviewed by:	Jeff Trawick
  
  Revision  Changes    Path
  1.70      +4 -1      apache-2.0/src/lib/apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- apr_network_io.h	2000/11/15 18:11:34	1.69
  +++ apr_network_io.h	2000/11/16 01:51:33	1.70
  @@ -158,11 +158,14 @@
   #endif
       } sa;
       apr_socklen_t sa_len;          /* How big is the sockaddr we're using? */
  +    int ipaddr_len;                /* How big is the ip address structure
  +                                    * we're using? 
  +                                    */
       int addr_str_len;              /* How big should the address buffer be?
                                       * 16 for v4 or 46 for v6
                                       * used in inet_ntop...
                                       */
  -     void *ipaddr_ptr;              /* This points to the IP address
  +    void *ipaddr_ptr;              /* This points to the IP address
                                       * structure within the appropriate
                                       * sockaddr structure.
                                       */
  
  
  
  1.34      +2 -3      apache-2.0/src/lib/apr/include/arch/unix/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/arch/unix/networkio.h,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- networkio.h	2000/09/29 04:03:20	1.33
  +++ networkio.h	2000/11/16 01:51:34	1.34
  @@ -122,9 +122,8 @@
   struct apr_socket_t {
       apr_pool_t *cntxt;
       int socketdes;
  -    struct sockaddr_in *local_addr;
  -    struct sockaddr_in *remote_addr;
  -    apr_socklen_t addr_len;
  +    apr_sockaddr_t *local_addr;
  +    apr_sockaddr_t *remote_addr;
       apr_interval_time_t timeout; 
   #ifndef HAVE_POLL
       int connected;
  
  
  
  1.5       +14 -8     apache-2.0/src/lib/apr/network_io/unix/sa_common.c
  
  Index: sa_common.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sa_common.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sa_common.c	2000/11/11 06:05:59	1.4
  +++ sa_common.c	2000/11/16 01:51:35	1.5
  @@ -68,10 +68,11 @@
   apr_status_t apr_set_port(apr_socket_t *sock, apr_interface_e which, 
                            apr_port_t port)
   {
  +        /* XXX IPv6 */
       if (which == APR_LOCAL)
  -        sock->local_addr->sin_port = htons(port);
  +        sock->local_addr->sa.sin.sin_port = htons(port);
       else if (which == APR_REMOTE)
  -        sock->remote_addr->sin_port = htons(port);
  +        sock->remote_addr->sa.sin.sin_port = htons(port);
       else
           return APR_EINVAL;
       return APR_SUCCESS;
  @@ -89,9 +90,10 @@
               }
           }
   
  -        *port = ntohs(sock->local_addr->sin_port);
  +        /* XXX IPv6 */
  +        *port = ntohs(sock->local_addr->sa.sin.sin_port);
       } else if (which == APR_REMOTE)
  -        *port = ntohs(sock->remote_addr->sin_port);
  +        *port = ntohs(sock->remote_addr->sa.sin.sin_port);
       else
           return APR_EINVAL;
       return APR_SUCCESS;
  @@ -107,9 +109,11 @@
                   return rv;
               }
           }
  -        *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->local_addr->sin_addr));
  +        /* XXX IPv6 */
  +        *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->local_addr->sa.sin.sin_addr));
       } else if (which == APR_REMOTE)
  -        *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->remote_addr->sin_addr));
  +        /* XXX IPv6 */
  +        *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->remote_addr->sa.sin.sin_addr));
       else 
           return APR_EINVAL;
   
  @@ -149,9 +153,11 @@
               }
           }
   
  -        *addr = *(apr_in_addr_t*)&sock->local_addr->sin_addr;
  +        /* XXX IPv6 */
  +        *addr = *(apr_in_addr_t *)&sock->local_addr->sa.sin.sin_addr;
       } else if (which == APR_REMOTE) {
  -        *addr = *(apr_in_addr_t*)&sock->remote_addr->sin_addr;
  +        /* XXX IPv6 */
  +        *addr = *(apr_in_addr_t *)&sock->remote_addr->sa.sin.sin_addr;
       } else {
           return APR_EINVAL;
       }
  
  
  
  1.20      +9 -7      apache-2.0/src/lib/apr/network_io/unix/sockaddr.c
  
  Index: sockaddr.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockaddr.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- sockaddr.c	2000/11/09 15:01:26	1.19
  +++ sockaddr.c	2000/11/16 01:51:35	1.20
  @@ -75,12 +75,13 @@
   apr_status_t apr_set_ipaddr(apr_socket_t *sock, apr_interface_e which, const char *addr)
   {
       u_long ipaddr;
  -    struct sockaddr_in* sa_ptr;
  -    
  +    struct sockaddr_in *sa_ptr;
  +
  +    /* XXX IPv6 */
       if (which == APR_LOCAL)
  -        sa_ptr = sock->local_addr;
  +        sa_ptr = &sock->local_addr->sa.sin;
       else if (which == APR_REMOTE)
  -        sa_ptr = sock->remote_addr;
  +        sa_ptr = &sock->remote_addr->sa.sin;
       else
           return APR_EINVAL;
       
  @@ -100,6 +101,7 @@
   }
   
   #if APR_HAVE_NETINET_IN_H
  +/* XXX IPv6 */
   apr_status_t apr_get_local_name(struct sockaddr_in **name, apr_socket_t *sock)
   {
       if (sock->local_port_unknown || sock->local_interface_unknown) {
  @@ -110,15 +112,15 @@
           }
       }
   
  -    *name = sock->local_addr;
  +    *name = &sock->local_addr->sa.sin;
       return APR_SUCCESS;
   }
   
  -
   
  +/* XXX IPv6 */
   apr_status_t apr_get_remote_name(struct sockaddr_in **name, apr_socket_t *sock)
   {
  -    *name = sock->remote_addr;
  +    *name = &sock->remote_addr->sa.sin;
       return APR_SUCCESS;
   }
   #endif
  
  
  
  1.55      +74 -51    apache-2.0/src/lib/apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- sockets.c	2000/11/02 03:02:49	1.54
  +++ sockets.c	2000/11/16 01:51:35	1.55
  @@ -67,33 +67,65 @@
       }
   }
   
  -apr_status_t apr_create_tcp_socket(apr_socket_t **new, apr_pool_t *cont)
  +static void set_socket_vars(apr_socket_t *sock, int family)
   {
  -    (*new) = (apr_socket_t *)apr_pcalloc(cont, sizeof(apr_socket_t));
  +    sock->local_addr->sa.sin.sin_family = family;
  +    sock->remote_addr->sa.sin.sin_family = family;
   
  -    if ((*new) == NULL) {
  -        return APR_ENOMEM;
  +    if (family == AF_INET) {
  +        sock->local_addr->sa_len = 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->sa_len = 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->sa_len = 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->sa_len = 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);
       }
  -    (*new)->cntxt = cont; 
  -    (*new)->local_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt,
  -                         sizeof(struct sockaddr_in));
  -    (*new)->remote_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt,
  -                          sizeof(struct sockaddr_in));
  +#endif
  +}                                                                                     
            
  +static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
  +{
  +    *new = (apr_socket_t *)apr_pcalloc(p, sizeof(apr_socket_t));
  +    (*new)->cntxt = p;
  +    (*new)->local_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
  +                                                       sizeof(apr_sockaddr_t));
  +    (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
  +                                                        sizeof(apr_sockaddr_t));
  +}
  +
  +apr_status_t apr_create_tcp_socket(apr_socket_t **new, apr_pool_t *cont)
  +{
  +    int family = AF_INET;
  +    int proto = IPPROTO_TCP;
  +    int type = SOCK_STREAM;
   
  +    alloc_socket(new, cont);
  +
       if ((*new)->local_addr == NULL || (*new)->remote_addr == NULL) {
           return APR_ENOMEM;
       }
  - 
  -    (*new)->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
   
  -    (*new)->local_addr->sin_family = AF_INET;
  -    (*new)->remote_addr->sin_family = AF_INET;
  +    (*new)->socketdes = socket(family, type, proto);
   
  -    (*new)->addr_len = sizeof(*(*new)->local_addr);
  -    
       if ((*new)->socketdes < 0) {
           return errno;
       }
  +    set_socket_vars(*new, family);
  +
       (*new)->timeout = -1;
       apr_register_cleanup((*new)->cntxt, (void *)(*new), 
                           socket_cleanup, apr_null_cleanup);
  @@ -113,10 +145,12 @@
   
   apr_status_t apr_bind(apr_socket_t *sock)
   {
  -    if (bind(sock->socketdes, (struct sockaddr *)sock->local_addr, sock->addr_len)
== -1)
  +    if (bind(sock->socketdes, 
  +             (struct sockaddr *)&sock->local_addr->sa, sock->local_addr->sa_len)
== -1)
           return errno;
       else {
  -        if (sock->local_addr->sin_port == 0) { /* no need for ntohs() when comparing
w/ 0 */
  +        /* XXX fix me for IPv6 */
  +        if (sock->local_addr->sa.sin.sin_port == 0) { /* no need for ntohs() when
comparing w/ 0 */
               sock->local_port_unknown = 1; /* kernel got us an ephemeral port */
           }
           return APR_SUCCESS;
  @@ -133,28 +167,22 @@
   
   apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *connection_context)
   {
  -    (*new) = (apr_socket_t *)apr_pcalloc(connection_context, 
  -                            sizeof(apr_socket_t));
  +    alloc_socket(new, connection_context);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family);
   
  -    (*new)->cntxt = connection_context;
  -    (*new)->local_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt, 
  -                 sizeof(struct sockaddr_in));
  -
  -    (*new)->remote_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt, 
  -                 sizeof(struct sockaddr_in));
  -    (*new)->addr_len = sizeof(struct sockaddr_in);
   #ifndef HAVE_POLL
       (*new)->connected = 1;
   #endif
       (*new)->timeout = -1;
       
  -    (*new)->socketdes = accept(sock->socketdes, (struct sockaddr *)(*new)->remote_addr,
  -                        &(*new)->addr_len);
  +    (*new)->remote_addr->sa_len = sizeof((*new)->remote_addr->sa);
  +    (*new)->socketdes = accept(sock->socketdes, 
  +                               (struct sockaddr *)&(*new)->remote_addr->sa,
  +                               &(*new)->remote_addr->sa_len);
   
       if ((*new)->socketdes < 0) {
           return errno;
       }
  -
       *(*new)->local_addr = *sock->local_addr;
   
       if (sock->local_port_unknown) {
  @@ -163,7 +191,8 @@
       }
   
       if (sock->local_interface_unknown ||
  -        sock->local_addr->sin_addr.s_addr == 0) {
  +        /* XXX IPv6 issue */
  +        sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
           /* 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.
            *
  @@ -189,8 +218,7 @@
   #ifndef GETHOSTBYNAME_HANDLES_NAS
           if (*hostname >= '0' && *hostname <= '9' &&
               strspn(hostname, "0123456789.") == strlen(hostname)) {
  -            sock->remote_addr->sin_addr.s_addr = inet_addr(hostname);
  -            sock->addr_len = sizeof(*sock->remote_addr);
  +            sock->remote_addr->sa.sin.sin_addr.s_addr = inet_addr(hostname);
           }
           else {
   #endif
  @@ -199,26 +227,30 @@
           if (!hp)  {
               return (h_errno + APR_OS_START_SYSERR);
           }
  -    
  -        memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0], 
  +
  +        /* XXX IPv6: move name resolution out of this function */
  +        memcpy((char *)&sock->remote_addr->sa.sin.sin_addr, hp->h_addr_list[0],

                  hp->h_length);
   
  -        sock->addr_len = sizeof(*sock->remote_addr);
   #ifndef GETHOSTBYNAME_HANDLES_NAS
           }
   #endif
       }
   
  -    if ((connect(sock->socketdes, (const struct sockaddr *)sock->remote_addr,
  -        sock->addr_len) < 0) && (errno != EINPROGRESS)) {
  +    if ((connect(sock->socketdes, 
  +                 (const struct sockaddr *)&sock->remote_addr->sa.sin,
  +                 sock->remote_addr->sa_len) < 0) &&
  +        (errno != EINPROGRESS)) {
           return errno;
       }
       else {
  -        if (sock->local_addr->sin_port == 0) {
  +        /* XXX IPv6 */
  +        if (sock->local_addr->sa.sin.sin_port == 0) {
               /* connect() got us an ephemeral port */
               sock->local_port_unknown = 1;
           }
  -        if (sock->local_addr->sin_addr.s_addr == 0) {
  +        /* XXX IPv6 */
  +        if (sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
               /* not bound to specific local interface; connect() had to assign
                * one for the socket
                */
  @@ -252,18 +284,9 @@
                              apr_pool_t *cont)
   {
       if ((*sock) == NULL) {
  -        (*sock) = (apr_socket_t *)apr_pcalloc(cont, sizeof(apr_socket_t));
  -        (*sock)->cntxt = cont;
  -        (*sock)->local_addr = (struct sockaddr_in *)apr_pcalloc((*sock)->cntxt,
  -                             sizeof(struct sockaddr_in));
  -        (*sock)->remote_addr = (struct sockaddr_in *)apr_pcalloc((*sock)->cntxt,
  -                              sizeof(struct sockaddr_in));
  -
  -        if ((*sock)->local_addr == NULL || (*sock)->remote_addr == NULL) {
  -            return APR_ENOMEM;
  -        }
  -     
  -        (*sock)->addr_len = sizeof(*(*sock)->local_addr);
  +        alloc_socket(sock, cont);
  +        /* XXX IPv6 figure out the family here! */
  +        set_socket_vars(*sock, AF_INET);
           (*sock)->timeout = -1;
       }
       (*sock)->local_port_unknown = (*sock)->local_interface_unknown = 1;
  
  
  
  1.37      +2 -2      apache-2.0/src/lib/apr/network_io/unix/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockopt.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- sockopt.c	2000/11/10 16:11:13	1.36
  +++ sockopt.c	2000/11/16 01:51:35	1.37
  @@ -208,9 +208,9 @@
       apr_in_addr_t sa_ptr;
   
       if (which == APR_LOCAL)
  -        sa_ptr = sock->local_addr->sin_addr;
  +        sa_ptr = sock->local_addr->sa.sin.sin_addr;
       else if (which == APR_REMOTE)
  -        sa_ptr = sock->remote_addr->sin_addr;
  +        sa_ptr = sock->remote_addr->sa.sin.sin_addr;
       else
           return APR_EINVAL;
   
  
  
  
  1.14      +2 -3      apache-2.0/src/lib/apr/include/arch/win32/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/arch/win32/networkio.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- networkio.h	2000/08/02 05:26:31	1.13
  +++ networkio.h	2000/11/16 01:51:36	1.14
  @@ -61,9 +61,8 @@
   struct apr_socket_t {
       apr_pool_t *cntxt;
       SOCKET sock;
  -    struct sockaddr_in *local_addr;
  -    struct sockaddr_in *remote_addr;
  -    size_t addr_len;
  +    apr_sockaddr_t *local_addr;
  +    apr_sockaddr_t *remote_addr;
       apr_interval_time_t timeout;
       apr_int32_t disconnected;
       int local_port_unknown;
  
  
  
  1.19      +6 -6      apache-2.0/src/lib/apr/network_io/win32/sockaddr.c
  
  Index: sockaddr.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockaddr.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- sockaddr.c	2000/11/11 06:05:59	1.18
  +++ sockaddr.c	2000/11/16 01:51:36	1.19
  @@ -60,9 +60,9 @@
   
   static apr_status_t get_local_addr(apr_socket_t *sock)
   {
  -    size_t namelen = sizeof(*sock->local_addr);
  +    size_t namelen = sizeof(sock->local_addr->sa);
   
  -    if (getsockname(sock->sock, (struct sockaddr *)sock->local_addr,
  +    if (getsockname(sock->sock, (struct sockaddr *)&sock->local_addr->sa,
                       &namelen) < 0) {
           return apr_get_netos_error();
       }
  @@ -81,9 +81,9 @@
       struct sockaddr_in *ptr;
   
       if (which == APR_LOCAL)
  -        ptr = sock->local_addr;
  +        ptr = &sock->local_addr->sa.sin;
       else if (which == APR_REMOTE)
  -        ptr = sock->remote_addr;
  +        ptr = &sock->remote_addr->sa.sin;
       else
           return APR_EINVAL;
    
  @@ -112,7 +112,7 @@
           }
       }
   
  -    *name = sock->local_addr;
  +    *name = &sock->local_addr->sa.sin;
       return APR_SUCCESS;
   }
   
  @@ -120,6 +120,6 @@
   
   apr_status_t apr_get_remote_name(struct sockaddr_in **name, apr_socket_t *sock)
   {
  -    *name = sock->remote_addr;
  +    *name = &sock->remote_addr->sa.sin;
       return APR_SUCCESS;
   }
  
  
  
  1.40      +63 -55    apache-2.0/src/lib/apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockets.c,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- sockets.c	2000/11/02 03:02:50	1.39
  +++ sockets.c	2000/11/16 01:51:36	1.40
  @@ -59,7 +59,6 @@
   #include "apr_portable.h"
   #include <string.h>
   
  -
   static apr_status_t socket_cleanup(void *sock)
   {
       apr_socket_t *thesocket = sock;
  @@ -73,22 +72,57 @@
       return APR_SUCCESS;
   }
   
  +static void set_socket_vars(apr_socket_t *sock, int family)
  +{
  +    sock->local_addr->sa.sin.sin_family = family;
  +    sock->remote_addr->sa.sin.sin_family = family;
  +
  +    if (family == AF_INET) {
  +        sock->local_addr->sa_len = 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->sa_len = 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->sa_len = 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->sa_len = 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
  +}                                                                                     
            
  +static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
  +{
  +    *new = (apr_socket_t *)apr_pcalloc(p, sizeof(apr_socket_t));
  +    (*new)->cntxt = p;
  +    (*new)->local_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
  +                                                       sizeof(apr_sockaddr_t));
  +    (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
  +                                                        sizeof(apr_sockaddr_t));
  +}
  +
   apr_status_t apr_create_tcp_socket(apr_socket_t **new, apr_pool_t *cont)
   {
  -    (*new) = (apr_socket_t *)apr_pcalloc(cont, sizeof(apr_socket_t));
  +    alloc_socket(new, cont);
   
       if ((*new) == NULL) {
           return APR_ENOMEM;
       }
  -    (*new)->cntxt = cont; 
  -    (*new)->local_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt,
  -                                                          sizeof(struct sockaddr_in));
  -    (*new)->remote_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt,
  -                          sizeof(struct sockaddr_in));
  -
       if (((*new)->local_addr == NULL) || ((*new)->remote_addr == NULL)) {
           return APR_ENOMEM;
       }
  +
       /* For right now, we are not using socket groups.  We may later.
        * No flags to use when creating a socket, so use 0 for that parameter as well.
        */
  @@ -96,14 +130,8 @@
       if ((*new)->sock == INVALID_SOCKET) {
           return apr_get_netos_error();
       }
  +    set_socket_vars(*new, AF_INET);
   
  -    (*new)->local_addr->sin_family = AF_INET;
  -    (*new)->remote_addr->sin_family = AF_INET;
  -
  -    (*new)->addr_len = sizeof(*(*new)->local_addr);
  -
  -    (*new)->local_addr->sin_port = 0;   
  -
       (*new)->timeout = -1;
       (*new)->disconnected = 0;
   
  @@ -147,11 +175,13 @@
   
   apr_status_t apr_bind(apr_socket_t *sock)
   {
  -    if (bind(sock->sock, (struct sockaddr *)sock->local_addr, sock->addr_len)
== -1) {
  +    if (bind(sock->sock, 
  +             (struct sockaddr *)&sock->local_addr->sa, 
  +             sock->local_addr->sa_len) == -1) {
           return apr_get_netos_error();
       }
       else {
  -        if (sock->local_addr->sin_port == 0) {
  +        if (sock->local_addr->sa.sin.sin_port == 0) {
               sock->local_port_unknown = 1; /* ephemeral port */
           }
           return APR_SUCCESS;
  @@ -168,27 +198,20 @@
   
   apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *connection_context)
   {
  -    (*new) = (apr_socket_t *)apr_pcalloc(connection_context, 
  -                            sizeof(apr_socket_t));
  +    alloc_socket(new, connection_context);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family);
   
  -    (*new)->cntxt = connection_context;
  -    (*new)->local_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt, 
  -                 sizeof(struct sockaddr_in));
  -    (*new)->remote_addr = (struct sockaddr_in *)apr_pcalloc((*new)->cntxt,
  -                 sizeof(struct sockaddr_in));
  -    memcpy((*new)->local_addr, sock->local_addr, sizeof(struct sockaddr_in));
  -
  -    (*new)->addr_len = sizeof(struct sockaddr_in);
       (*new)->timeout = -1;   
       (*new)->disconnected = 0;
   
  -    (*new)->sock = accept(sock->sock, (struct sockaddr *)(*new)->local_addr,
  -                        &(*new)->addr_len);
  +    (*new)->remote_addr->sa_len = sizeof((*new)->remote_addr->sa);
  +    (*new)->sock = accept(sock->sock, 
  +                          (struct sockaddr *)&(*new)->remote_addr->sa,
  +                          &(*new)->remote_addr->sa_len);
   
       if ((*new)->sock == INVALID_SOCKET) {
           return apr_get_netos_error();
       }
  -
       *(*new)->local_addr = *sock->local_addr;
   
       if (sock->local_port_unknown) {
  @@ -197,7 +220,7 @@
       }
   
       if (sock->local_interface_unknown ||
  -        sock->local_addr->sin_addr.s_addr == 0) {
  +        sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
           /* 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.
            *
  @@ -225,22 +248,20 @@
       if (hostname != NULL) {
           if (*hostname >= '0' && *hostname <= '9' && 
               strspn(hostname, "0123456789.") == strlen(hostname)) {
  -            sock->remote_addr->sin_addr.s_addr = inet_addr(hostname);
  +            sock->remote_addr->sa.sin.sin_addr.s_addr = inet_addr(hostname);
           }
           else {
               hp = gethostbyname(hostname);
               if (!hp)  {
                   return apr_get_netos_error();
               }
  -            memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0],
hp->h_length);
  -            sock->addr_len = sizeof(*sock->remote_addr);
  +            memcpy((char *)&sock->remote_addr->sa.sin.sin_addr, hp->h_addr_list[0],

  +                   hp->h_length);
           }
       }
       
  -    sock->remote_addr->sin_family = AF_INET;
  -
  -    if (connect(sock->sock, (const struct sockaddr *)sock->remote_addr, 
  -                sock->addr_len) == SOCKET_ERROR) {
  +    if (connect(sock->sock, (const struct sockaddr *)&sock->remote_addr->sa.sin,
  +                sock->remote_addr->sa_len) == SOCKET_ERROR) {
           lasterror = apr_get_netos_error();
           if (lasterror != APR_FROM_OS_ERROR(WSAEWOULDBLOCK)) {
               return lasterror;
  @@ -253,10 +274,10 @@
           }
       }
       /* connect was OK .. amazing */
  -    if (sock->local_addr->sin_port == 0) {
  +    if (sock->local_addr->sa.sin.sin_port == 0) {
           sock->local_port_unknown = 1;
       }
  -    if (sock->local_addr->sin_addr.s_addr == 0) {
  +    if (sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
           /* must be using free-range port */
           sock->local_interface_unknown = 1;
       }
  @@ -283,22 +304,9 @@
   apr_status_t apr_put_os_sock(apr_socket_t **sock, apr_os_sock_t *thesock, 
                              apr_pool_t *cont)
   {
  -    if (cont == NULL) {
  -        return APR_ENOPOOL;
  -    }
       if ((*sock) == NULL) {
  -        (*sock) = (apr_socket_t *)apr_pcalloc(cont, sizeof(apr_socket_t));
  -        (*sock)->cntxt = cont;
  -        (*sock)->local_addr = (struct sockaddr_in *)apr_pcalloc((*sock)->cntxt,
  -                             sizeof(struct sockaddr_in));
  -        (*sock)->remote_addr = (struct sockaddr_in *)apr_pcalloc((*sock)->cntxt,
  -                              sizeof(struct sockaddr_in));
  -
  -        if ((*sock)->local_addr == NULL || (*sock)->remote_addr == NULL) {
  -            return APR_ENOMEM;
  -        }
  -     
  -        (*sock)->addr_len = sizeof(*(*sock)->local_addr);
  +        alloc_socket(sock, cont);
  +        set_socket_vars(*sock, AF_INET);
           (*sock)->timeout = -1;
           (*sock)->disconnected = 0;
       }
  
  
  
  1.29      +2 -2      apache-2.0/src/lib/apr/network_io/win32/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockopt.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- sockopt.c	2000/11/10 20:17:24	1.28
  +++ sockopt.c	2000/11/16 01:51:36	1.29
  @@ -207,9 +207,9 @@
       apr_in_addr_t sa_ptr;
   
       if (which == APR_LOCAL)
  -        sa_ptr = sock->local_addr->sin_addr;
  +        sa_ptr = sock->local_addr->sa.sin.sin_addr;
       else if (which == APR_REMOTE)
  -        sa_ptr = sock->remote_addr->sin_addr;
  +        sa_ptr = sock->remote_addr->sa.sin.sin_addr;
       else
           return APR_EINVAL;
   
  
  
  

Mime
View raw message