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/unix sa_common.c sockets.c
Date Thu, 28 Mar 2002 18:17:02 GMT
trawick     02/03/28 10:17:02

  Modified:    include/arch/os2 networkio.h
               include/arch/unix networkio.h
               include/arch/win32 networkio.h
               network_io/unix sa_common.c sockets.c
  Log:
  clean up the unix networking code by creating a new function
  to set basic info in apr_sockaddr_t and by reducing the amount
  of code that messes with the native sockaddrs within the
  apr_sockaddr_t
  
  prototypes for the new function -- apr_set_sockaddr_vars() --
  were added for Win32 and OS/2 since otherwise they could get
  warnings for the lack of a prototype for the non-static function,
  which resides in sa_common.c
  
  for long-term, we need to look at using apr_set_sockaddr_vars()
  in Win32 and OS/2 code anyway
  
  Revision  Changes    Path
  1.24      +1 -0      apr/include/arch/os2/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/os2/networkio.h,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- networkio.h	13 Mar 2002 20:39:18 -0000	1.23
  +++ networkio.h	28 Mar 2002 18:17:02 -0000	1.24
  @@ -103,6 +103,7 @@
   
   const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size);
   int apr_inet_pton(int af, const char *src, void *dst);
  +void apr_set_sockaddr_vars(apr_sockaddr_t *, int, apr_port_t);
   
   #endif  /* ! NETWORK_IO_H */
   
  
  
  
  1.52      +1 -0      apr/include/arch/unix/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/unix/networkio.h,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- networkio.h	13 Mar 2002 20:39:18 -0000	1.51
  +++ networkio.h	28 Mar 2002 18:17:02 -0000	1.52
  @@ -164,6 +164,7 @@
   const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size);
   int apr_inet_pton(int af, const char *src, void *dst);
   apr_status_t apr_wait_for_io_or_timeout(apr_socket_t *sock, int for_read);
  +void apr_set_sockaddr_vars(apr_sockaddr_t *, int, apr_port_t);
   
   #define apr_is_option_set(mask, option)  ((mask & option) ==option)
   
  
  
  
  1.22      +1 -0      apr/include/arch/win32/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/win32/networkio.h,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- networkio.h	13 Mar 2002 20:39:19 -0000	1.21
  +++ networkio.h	28 Mar 2002 18:17:02 -0000	1.22
  @@ -86,6 +86,7 @@
   
   const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size);
   int apr_inet_pton(int af, const char *src, void *dst);
  +void apr_set_sockaddr_vars(apr_sockaddr_t *, int, apr_port_t);
   
   #endif  /* ! NETWORK_IO_H */
   
  
  
  
  1.53      +17 -31    apr/network_io/unix/sa_common.c
  
  Index: sa_common.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sa_common.c,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- sa_common.c	14 Mar 2002 19:28:15 -0000	1.52
  +++ sa_common.c	28 Mar 2002 18:17:02 -0000	1.53
  @@ -139,8 +139,7 @@
   APR_DECLARE(apr_status_t) apr_sockaddr_port_get(apr_port_t *port,
                                          apr_sockaddr_t *sockaddr)
   {
  -    /* XXX IPv6 - assumes sin_port and sin6_port at same offset */
  -    *port = ntohs(sockaddr->sa.sin.sin_port);
  +    *port = sockaddr->port;
       return APR_SUCCESS;
   }
   
  @@ -148,12 +147,12 @@
                                            apr_sockaddr_t *sockaddr)
   {
       *addr = apr_palloc(sockaddr->pool, sockaddr->addr_str_len);
  -    apr_inet_ntop(sockaddr->sa.sin.sin_family,
  +    apr_inet_ntop(sockaddr->family,
                     sockaddr->ipaddr_ptr,
                     *addr,
                     sockaddr->addr_str_len);
   #if APR_HAVE_IPV6
  -    if (sockaddr->sa.sin.sin_family == AF_INET6 &&
  +    if (sockaddr->family == AF_INET6 &&
           IN6_IS_ADDR_V4MAPPED((struct in6_addr *)sockaddr->ipaddr_ptr)) {
           /* This is an IPv4-mapped IPv6 address; drop the leading
            * part of the address string so we're left with the familiar
  @@ -165,12 +164,15 @@
       return APR_SUCCESS;
   }
   
  -static void set_sockaddr_vars(apr_sockaddr_t *addr, int family)
  +void apr_set_sockaddr_vars(apr_sockaddr_t *addr, int family, apr_port_t port)
   {
       addr->family = family;
  -    /* XXX IPv6: assumes sin_port and sin6_port at same offset */
  -    addr->port = ntohs(addr->sa.sin.sin_port);
       addr->sa.sin.sin_family = family;
  +    if (port) {
  +        /* XXX IPv6: assumes sin_port and sin6_port at same offset */
  +        addr->sa.sin.sin_port = htons(port);
  +        addr->port = port;
  +    }
   
       if (family == APR_INET) {
           addr->salen = sizeof(struct sockaddr_in);
  @@ -319,21 +321,16 @@
                             struct addrinfo *ai, apr_port_t port)
   {
       sa->pool = p;
  -    sa->sa.sin.sin_family = ai->ai_family;
       memcpy(&sa->sa, ai->ai_addr, ai->ai_addrlen);
  -    /* XXX IPv6: assumes sin_port and sin6_port at same offset */
  -    sa->sa.sin.sin_port = htons(port);
  -    set_sockaddr_vars(sa, sa->sa.sin.sin_family);
  +    apr_set_sockaddr_vars(sa, ai->ai_family, port);
   }
   #else
   static void save_addrinfo(apr_pool_t *p, apr_sockaddr_t *sa,
                             struct in_addr ipaddr, apr_port_t port)
   {
       sa->pool = p;
  -    sa->sa.sin.sin_family = AF_INET;
       sa->sa.sin.sin_addr = ipaddr;
  -    sa->sa.sin.sin_port = htons(port);
  -    set_sockaddr_vars(sa, sa->sa.sin.sin_family);
  +    apr_set_sockaddr_vars(sa, AF_INET, port);
   }
   #endif
   
  @@ -395,16 +392,10 @@
           freeaddrinfo(ai_list);
       }
       else {
  -        if (family == APR_UNSPEC) {
  -            (*sa)->sa.sin.sin_family = APR_INET;
  -        }
  -        else {
  -            (*sa)->sa.sin.sin_family = family;
  -        }
           (*sa)->pool = p;
  -        /* XXX IPv6: assumes sin_port and sin6_port at same offset */
  -        (*sa)->sa.sin.sin_port = htons(port);
  -        set_sockaddr_vars(*sa, (*sa)->sa.sin.sin_family);
  +        apr_set_sockaddr_vars(*sa, 
  +                              family == APR_UNSPEC ? APR_INET : family,
  +                              port);
       }
   #else
       if (hostname != NULL) {
  @@ -488,15 +479,10 @@
   #endif
       }
       else {
  -        if (family == APR_UNSPEC) {
  -            (*sa)->sa.sin.sin_family = APR_INET;
  -        }
  -        else {
  -            (*sa)->sa.sin.sin_family = family;
  -        }
           (*sa)->pool = p;
  -        (*sa)->sa.sin.sin_port = htons(port);
  -        set_sockaddr_vars(*sa, (*sa)->sa.sin.sin_family);
  +        apr_set_sockaddr_vars(*sa, 
  +                              family == APR_UNSPEC ? APR_INET : family,
  +                              port);
       }
   #endif
       return APR_SUCCESS;
  
  
  
  1.95      +14 -44    apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- sockets.c	13 Mar 2002 20:39:25 -0000	1.94
  +++ sockets.c	28 Mar 2002 18:17:02 -0000	1.95
  @@ -57,15 +57,17 @@
   #include "apr_portable.h"
   #include "inherit.h"
   
  +#if defined(BEOS) && !defined(BEOS_BONE)
  +#define close closesocket
  +#endif
  +
  +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;
   
  -#if defined(BEOS) && !defined(BEOS_BONE)
  -    if (closesocket(thesocket->socketdes) == 0) {
  -#else
       if (close(thesocket->socketdes) == 0) {
  -#endif
           thesocket->socketdes = -1;
           return APR_SUCCESS;
       }
  @@ -77,35 +79,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 == APR_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 == APR_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);
       sock->netmask = 0;
   #if defined(BEOS) && !defined(BEOS_BONE)
       /* BeOS pre-BONE has TCP_NODELAY on by default and it can't be
  @@ -113,7 +88,8 @@
        */
       sock->netmask |= APR_TCP_NODELAY;
   #endif
  -}                                                                                     
            
  +}
  +
   static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
   {
       *new = (apr_socket_t *)apr_pcalloc(p, sizeof(apr_socket_t));
  @@ -203,7 +179,6 @@
   
   apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *connection_context)
   {
  -    static char generic_inaddr_any[16] = {0}; /* big enough for IPv4 or IPv6 */
       alloc_socket(new, connection_context);
       set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM);
   
  @@ -212,7 +187,6 @@
   #endif
       (*new)->timeout = -1;
       
  -    (*new)->remote_addr->salen = sizeof((*new)->remote_addr->sa);
       (*new)->socketdes = accept(sock->socketdes, 
                                  (struct sockaddr *)&(*new)->remote_addr->sa,
                                  &(*new)->remote_addr->salen);
  @@ -307,17 +281,13 @@
       }
   
       sock->remote_addr = sa;
  -    /* XXX IPv6 assumes sin_port and sin6_port at same offset */
  -    if (sock->local_addr->sa.sin.sin_port == 0) {
  +    if (sock->local_addr->port == 0) {
           /* connect() got us an ephemeral port */
           sock->local_port_unknown = 1;
       }
  -    /* XXX IPv6 to be handled better later... */
  -    if (
  -#if APR_HAVE_IPV6
  -        sock->local_addr->sa.sin.sin_family == APR_INET6 ||
  -#endif
  -        sock->local_addr->sa.sin.sin_addr.s_addr == 0) {
  +    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
            */
  
  
  

Mime
View raw message