httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/test client.c server.c
Date Thu, 09 Nov 2000 15:01:36 GMT
dreid       00/11/09 07:01:36

  Modified:    src/lib/apr/include apr_network_io.h
               src/lib/apr/network_io/beos sockaddr.c
               src/lib/apr/network_io/unix sockaddr.c
               src/lib/apr/network_io/win32 sockaddr.c
               src/lib/apr/test client.c server.c
  Log:
  This is the next step in the conversion of socket address functions to
  take APR_LOCAL/APR_REMOTE and also the addition of a new function to get the
  apr_inaddr_t for a socket.  the new function is needed to help tidy up
  http_vhost.c
  
  Changes to apache code to reflect these follow directly...
  
  Revision  Changes    Path
  1.64      +12 -20    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.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- apr_network_io.h	2000/11/08 14:45:18	1.63
  +++ apr_network_io.h	2000/11/09 15:01:25	1.64
  @@ -407,37 +407,22 @@
   apr_status_t apr_get_port(apr_port_t *port, apr_interface_e which, apr_socket_t *sock);
   
   /**
  - * Associate a local socket addr with an apr socket.
  + * Associate a socket addr with an apr socket.
    * @param sock The socket to use 
  + * @param which Which interface should we set?
    * @param addr The IP address to attach to the socket.
    *             Use APR_ANYADDR to use any IP addr on the machine.
    * @tip This does not bind the two together, it is just telling apr 
    *      that this socket is going to use this address if possible. 
    */
  -apr_status_t apr_set_local_ipaddr(apr_socket_t *sock, const char *addr);
  +apr_status_t apr_set_ipaddr(apr_socket_t *sock, apr_interface_e which, const char *addr);
   
   /**
  - * Associate a remote socket addr with an apr socket.
  - * @param sock The socket to use 
  - * @param addr The IP address to attach to the socket.
  - * @tip This does not make a connection to the remote address, it is just
  - *      telling apr which address apr_connect() should attempt to connect to.
  - */
  -apr_status_t apr_set_remote_ipaddr(apr_socket_t *sock, const char *addr);
  -
  -/**
  - * Return the local IP address associated with an apr socket.
  + * Return the IP address associated with an apr socket.
    * @param addr The local IP address associated with the socket.
    * @param sock The socket to use 
  - */
  -apr_status_t apr_get_local_ipaddr(char **addr, apr_socket_t *sock);
  -
  -/**
  - * Return the remote IP address associated with an apr socket.
  - * @param addr The remote IP address associated with the socket.
  - * @param sock The socket to use 
    */
  -apr_status_t apr_get_remote_ipaddr(char **addr, apr_socket_t *sock);
  +apr_status_t apr_get_ipaddr(char **addr, apr_interface_e which, apr_socket_t *sock);
   
   /**
    * Return the local socket name as a BSD style struct sockaddr_in.
  @@ -571,6 +556,13 @@
    *      have the APR_FILES_AS_SOCKETS macro defined as true.
    */
   apr_status_t apr_socket_from_file(apr_socket_t **newsock, apr_file_t *file);
  +
  +/**
  + * Given a hostname and a port, create an apr_in_addr for it...
  + * @param addr The apr_in_addr structure to return.
  + * @param hostname The hostname to lookup.
  + */
  +apr_status_t apr_get_inaddr(apr_in_addr *addr, char* hostname);
   
   #ifdef __cplusplus
   }
  
  
  
  1.17      +22 -71    apache-2.0/src/lib/apr/network_io/beos/sockaddr.c
  
  Index: sockaddr.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/beos/sockaddr.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- sockaddr.c	2000/11/08 14:45:55	1.16
  +++ sockaddr.c	2000/11/09 15:01:25	1.17
  @@ -58,100 +58,51 @@
   #else
   #include "networkio.h"
   
  -apr_status_t apr_set_port(apr_socket_t *sock, apr_interface_e which, apr_port_t port)
  +static apr_status_t get_local_addr(apr_socket_t *sock)
   {
  -    if (!sock) 
  -        return APR_EBADF;
  -    if (which == APR_LOCAL) 
  -        sock->local_addr->sin_port = htons(port);
  -    else if (APR == APR_REMOTE)
  -        sock->remote_addr->sin_port = htons(port);
  -    else
  -        return APR_EINVAL;
  -    return APR_SUCCESS;
  -}
  -
  -apr_status_t apr_get_port(apr_port_t *port, apr_interface_e which, apr_socket_t *sock)
  -{
  -    if (!sock)
  -        return APR_EBADF;
  -    if (which == APR_LOCAL)
  -        *port = ntohs(sock->local_addr->sin_port);
  -    else if (which == APR_REMOTE)
  -        *port = ntohs(sock->remote_addr->sin_port);
  -    else
  -        return APR_EINVAL;
  -    return APR_SUCCESS;
  -}
  -
  -apr_status_t apr_set_local_ipaddr(apr_socket_t *sock, const char *addr)
  -{
  -    u_long ipaddr;
  +    apr_socklen_t namelen = sizeof(*sock->local_addr);
   
  -    if (!sock) {
  -        return APR_EBADF;
  +    if (getsockname(sock->socketdes, (struct sockaddr *)sock->local_addr,
  +                    &namelen) < 0) {
  +        return errno;
       }
  -    
  -    if (!strcmp(addr, APR_ANYADDR)) {
  -        sock->local_addr->sin_addr.s_addr = htonl(INADDR_ANY);
  +    else {
  +        sock->local_port_unknown = sock->local_interface_unknown = 0;
           return APR_SUCCESS;
       }
  -    
  -    ipaddr = inet_addr(addr);
  -    
  -    if (ipaddr == -1) {
  -        return errno;
  -    }
  -    
  -    sock->local_addr->sin_addr.s_addr = ipaddr;
  -    return APR_SUCCESS;
   }
  +
  +/* Include this here so we already have get_local_addr... */
  +#include "../unix/sa_common.c"
   
  -apr_status_t apr_set_remote_ipaddr(apr_socket_t *sock, const char *addr)
  +apr_status_t apr_set_ipaddr(apr_socket_t *sock, apr_interface_e which, const char *addr)
   {
       u_long ipaddr;
  +    struct sockaddr_in *ptr;
   
  -    if (!sock) {
  -        return APR_EBADF;
  -    }
  +    if (which == APR_LOCAL)
  +        ptr = sock->local_addr;
  +    else if (which == APR_REMOTE)
  +        ptr = sock->remote_addr;
  +    else 
  +        return APR_EINVAL;
       
       if (!strcmp(addr, APR_ANYADDR)) {
  -        sock->remote_addr->sin_addr.s_addr = htonl(INADDR_ANY);
  +        ptr->sin_addr.s_addr = htonl(INADDR_ANY);
           return APR_SUCCESS;
       }
       
       ipaddr = inet_addr(addr);
       
  -    if (ipaddr == (u_long)-1) {
  +    if (ipaddr == -1) {
           return errno;
       }
       
  -    sock->remote_addr->sin_addr.s_addr = ipaddr;
  +    ptr->sin_addr.s_addr = ipaddr;
       return APR_SUCCESS;
   }
  -
  -apr_status_t apr_get_local_ipaddr(char **addr, apr_socket_t *sock)
  -{
  -    if (!sock) {
  -        return APR_EBADF;
  -    }
  -
  -    *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->local_addr->sin_addr));
  -    return APR_SUCCESS;
  -}
  -
  -apr_status_t apr_get_remote_ipaddr(char **addr, apr_socket_t *sock)
  -{
  -    if (!sock) {
  -        return APR_EBADF;
  -    }
  -
  -    *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->remote_addr->sin_addr));
  -    return APR_SUCCESS;
  -}
  -
   
  -apr_status_t apr_get_local_name(struct sockaddr_in **name, apr_socket_t *sock)
  +apr_status_t get_local_name(struct sockaddr_in **name, apr_socket_t *sock)
   {
       if (!sock) {
           return APR_EBADF;
  
  
  
  1.19      +12 -83    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- sockaddr.c	2000/11/08 14:46:04	1.18
  +++ sockaddr.c	2000/11/09 15:01:26	1.19
  @@ -55,18 +55,6 @@
   #include "networkio.h"
   #include "apr_strings.h"
   
  -apr_status_t apr_set_port(apr_socket_t *sock, apr_interface_e which, 
  -                         apr_port_t port)
  -{
  -    if (which == APR_LOCAL)
  -        sock->local_addr->sin_port = htons(port);
  -    else if (which == APR_REMOTE)
  -        sock->remote_addr->sin_port = htons(port);
  -    else
  -        return APR_EINVAL;
  -    return APR_SUCCESS;
  -}
  -
   static apr_status_t get_local_addr(apr_socket_t *sock)
   {
       apr_socklen_t namelen = sizeof(*sock->local_addr);
  @@ -80,36 +68,24 @@
           return APR_SUCCESS;
       }
   }
  -
   
  +/* included here to allow us to use local_addr */
  +#include "sa_common.c"
   
  -apr_status_t apr_get_port(apr_port_t *port, apr_interface_e which, apr_socket_t *sock)
  +apr_status_t apr_set_ipaddr(apr_socket_t *sock, apr_interface_e which, const char *addr)
   {
  -    if (which == APR_LOCAL){
  -        if (sock->local_port_unknown) {
  -            apr_status_t rv = get_local_addr(sock);
  -
  -            if (rv != APR_SUCCESS) {
  -                return rv;
  -            }
  -        }
  -
  -        *port = ntohs(sock->local_addr->sin_port);
  -    } else if (which == APR_REMOTE)
  -        *port = ntohs(sock->remote_addr->sin_port);
  +    u_long ipaddr;
  +    struct sockaddr_in* sa_ptr;
  +    
  +    if (which == APR_LOCAL)
  +        sa_ptr = sock->local_addr;
  +    else if (which == APR_REMOTE)
  +        sa_ptr = sock->remote_addr;
       else
           return APR_EINVAL;
  -    return APR_SUCCESS;
  -}
  -
  -
  -
  -apr_status_t apr_set_local_ipaddr(apr_socket_t *sock, const char *addr)
  -{
  -    u_long ipaddr;
       
       if (!strcmp(addr, APR_ANYADDR)) {
  -        sock->local_addr->sin_addr.s_addr = htonl(INADDR_ANY);
  +        sa_ptr->sin_addr.s_addr = htonl(INADDR_ANY);
           return APR_SUCCESS;
       }
       
  @@ -118,57 +94,10 @@
       if (ipaddr == -1) {
           return errno;
       }
  -    
  -    sock->local_addr->sin_addr.s_addr = ipaddr;
  -    return APR_SUCCESS;
  -}
  -
  -
  -
  -apr_status_t apr_set_remote_ipaddr(apr_socket_t *sock, const char *addr)
  -{
  -    u_long ipaddr;
  -    
  -    if (!strcmp(addr, APR_ANYADDR)) {
  -        sock->remote_addr->sin_addr.s_addr = htonl(INADDR_ANY);
  -        return APR_SUCCESS;
  -    }
  -    
  -    ipaddr = inet_addr(addr);
  -    
  -    if (ipaddr == (u_long)-1) {
  -        return errno;
  -    }
       
  -    sock->remote_addr->sin_addr.s_addr = ipaddr;
  -    return APR_SUCCESS;
  -}
  -
  -
  -
  -apr_status_t apr_get_local_ipaddr(char **addr, apr_socket_t *sock)
  -{
  -    if (sock->local_interface_unknown) {
  -        apr_status_t rv = get_local_addr(sock);
  -
  -        if (rv != APR_SUCCESS) {
  -            return rv;
  -        }
  -    }
  -
  -    *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->local_addr->sin_addr));
  -    return APR_SUCCESS;
  -}
  -
  -
  -
  -apr_status_t apr_get_remote_ipaddr(char **addr, apr_socket_t *sock)
  -{
  -    *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->remote_addr->sin_addr));
  +    sa_ptr->sin_addr.s_addr = ipaddr;
       return APR_SUCCESS;
   }
  -
  -
   
   #if APR_HAVE_NETINET_IN_H
   apr_status_t apr_get_local_name(struct sockaddr_in **name, apr_socket_t *sock)
  
  
  
  1.16      +11 -76    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- sockaddr.c	2000/11/08 22:22:55	1.15
  +++ sockaddr.c	2000/11/09 15:01:26	1.16
  @@ -72,46 +72,23 @@
       }
   }
   
  +/* Include this here so we have get_local_addr defined... */
  +#include "../unix/sa_common.c"
   
  -
  -apr_status_t apr_set_port(apr_socket_t *sock, apr_interface_e which, apr_port_t port)
  +apr_status_t apr_set_ipaddr(apr_socket_t *sock, apr_interface_e which, const char *addr)
   {
  -    if (which == APR_LOCAL)
  -        sock->local_addr->sin_port = htons(port);
  -    else if (which == APR_REMOTE)
  -        sock->remote_addr->sin_port = htons(port);
  -    else
  -        return APR_EINVAL;
  -    return APR_SUCCESS;
  -}
  +    u_long ipaddr;
  +    sockaddr_in *ptr;
   
  -apr_status_t apr_get_port(apr_port_t *port, apr_interface_e which, apr_socket_t *sock)
  -{
       if (which == APR_LOCAL)
  -    {
  -        if (sock->local_port_unknown) {
  -            apr_status_t rv = get_local_addr(sock);
  -
  -            if (rv != APR_SUCCESS) {
  -                return rv;
  -            }
  -        }
  -        *port = ntohs(sock->local_addr->sin_port);
  -    } else if (which == APR_REMOTE)
  -        *port = ntohs(sock->remote_addr->sin_port);
  +        ptr = sock->local_addr;
  +    else if (which == APR_REMOTE)
  +        ptr = sock->remote_addr;
       else
           return APR_EINVAL;
  -
  -    return APR_SUCCESS;
  -}
  -
  -
  -apr_status_t apr_set_local_ipaddr(apr_socket_t *sock, const char *addr)
  -{
  -    u_long ipaddr;
  -    
  + 
       if (!strcmp(addr, APR_ANYADDR)) {
  -        sock->local_addr->sin_addr.s_addr = htonl(INADDR_ANY);
  +        ptr->sin_addr.s_addr = htonl(INADDR_ANY);
           return APR_SUCCESS;
       }
       
  @@ -121,51 +98,9 @@
           return WSAEADDRNOTAVAIL;
       }
       
  -    sock->local_addr->sin_addr.s_addr = ipaddr;
  +    ptr->sin_addr.s_addr = ipaddr;
       return APR_SUCCESS;
   }
  -
  -apr_status_t apr_set_remote_ipaddr(apr_socket_t *sock, const char *addr)
  -{
  -    u_long ipaddr;
  -    
  -    if (!strcmp(addr, APR_ANYADDR)) {
  -        sock->remote_addr->sin_addr.s_addr = htonl(INADDR_ANY);
  -        return APR_SUCCESS;
  -    }
  -    
  -    ipaddr = inet_addr(addr);
  -    
  -    if (ipaddr == INADDR_NONE) {
  -        return WSAEADDRNOTAVAIL;
  -    }
  -    
  -    sock->remote_addr->sin_addr.s_addr = ipaddr;
  -    return APR_SUCCESS;
  -}
  -
  -apr_status_t apr_get_local_ipaddr(char **addr, apr_socket_t *sock)
  -{
  -    if (sock->local_interface_unknown) {
  -        apr_status_t rv = get_local_addr(sock);
  -
  -        if (rv != APR_SUCCESS) {
  -            return rv;
  -        }
  -    }
  -
  -    *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->local_addr->sin_addr));
  -    return APR_SUCCESS;
  -}
  -
  -
  -
  -apr_status_t apr_get_remote_ipaddr(char **addr, apr_socket_t *sock)
  -{
  -    *addr = apr_pstrdup(sock->cntxt, inet_ntoa(sock->remote_addr->sin_addr));
  -    return APR_SUCCESS;
  -}
  -
   
   apr_status_t apr_get_local_name(struct sockaddr_in **name, apr_socket_t *sock)
   {
  
  
  
  1.17      +2 -2      apache-2.0/src/lib/apr/test/client.c
  
  Index: client.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/client.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- client.c	2000/11/08 14:46:50	1.16
  +++ client.c	2000/11/09 15:01:35	1.17
  @@ -136,9 +136,9 @@
       }
       fprintf(stdout, "OK\n");
   
  -    apr_get_remote_ipaddr(&remote_ipaddr, sock);
  +    apr_get_ipaddr(&remote_ipaddr, APR_REMOTE, sock);
       apr_get_port(&remote_port, APR_REMOTE, sock);
  -    apr_get_local_ipaddr(&local_ipaddr, sock);
  +    apr_get_ipaddr(&local_ipaddr, APR_LOCAL, sock);
       apr_get_port(&local_port, APR_LOCAL, sock);
       fprintf(stdout, "\tClient socket: %s:%u -> %s:%u\n", local_ipaddr, local_port, remote_ipaddr,
remote_port);
   
  
  
  
  1.16      +2 -2      apache-2.0/src/lib/apr/test/server.c
  
  Index: server.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/server.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- server.c	2000/11/08 14:47:05	1.15
  +++ server.c	2000/11/09 15:01:35	1.16
  @@ -161,9 +161,9 @@
       }
       fprintf(stdout, "OK\n");
   
  -    apr_get_remote_ipaddr(&remote_ipaddr, sock2);
  +    apr_get_ipaddr(&remote_ipaddr, APR_REMOTE, sock2);
       apr_get_port(&remote_port, APR_REMOTE, sock2);
  -    apr_get_local_ipaddr(&local_ipaddr, sock2);
  +    apr_get_ipaddr(&local_ipaddr, APR_LOCAL, sock2);
       apr_get_port(&local_port, APR_LOCAL, sock2);
       fprintf(stdout, "\tServer socket: %s:%u -> %s:%u\n", local_ipaddr, local_port, remote_ipaddr,
remote_port);
   
  
  
  

Mime
View raw message