rbb         99/04/15 13:08:22

  Modified:    apr/network_io/unix networkio.h sockets.c sockopt.c
               include  apr_network_io.h
               docs     networkio.txt
  Log:
  Fixed hostname stuff in apr.  Also, we are now saving the remote hostname in 
the
  apr structure.
  
  Revision  Changes    Path
  1.5       +1 -1      apache-apr/apr/network_io/unix/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/network_io/unix/networkio.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- networkio.h       1999/04/15 15:41:18     1.4
  +++ networkio.h       1999/04/15 20:08:15     1.5
  @@ -58,7 +58,7 @@
   
   struct socket_t {
       int socketdes;
  -    char hostname[MAXHOSTNAMELEN];
  +    char *remote_hostname;
       struct sockaddr_in *addr;
       size_t addr_len;
   };
  
  
  
  1.5       +12 -10    apache-apr/apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/network_io/unix/sockets.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sockets.c 1999/04/15 15:41:18     1.4
  +++ sockets.c 1999/04/15 20:08:16     1.5
  @@ -60,18 +60,14 @@
   #include <sys/socket.h>
   #include <netinet/tcp.h>
   #include <netinet/in.h>
  +#include <netdb.h>
   
  -
   apr_socket_t *apr_create_tcp_socket(void)
   {
       apr_socket_t *thesocket = (apr_socket_t *)malloc(sizeof(apr_socket_t));
       
       thesocket->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
  -
  -    if (gethostname(thesocket->hostname, MAXHOSTNAMELEN + 1) == -1) { 
  -        free(thesocket);
  -        return NULL;
  -    }
  +    thesocket->remote_hostname = NULL;
   
       thesocket->addr = (struct sockaddr_in *)malloc(sizeof(struct 
sockaddr_in));
       thesocket->addr->sin_family = AF_INET;
  @@ -102,7 +98,8 @@
   apr_status_t apr_close_socket(apr_socket_t *thesocket)
   {
       if (close(thesocket->socketdes) == 0) {
  -        free(thesocket->hostname);
  +        free(thesocket->addr);
  +        free(thesocket->remote_hostname);
           free(thesocket);
           return APR_SUCCESS;
       }
  @@ -136,11 +133,16 @@
   apr_socket_t *apr_accept(const apr_socket_t *sock)
   {
       apr_socket_t *new = (apr_socket_t *)malloc(sizeof(apr_socket_t));
  -
  -    strcpy(new->hostname, sock->hostname);
  +    struct hostent *hptr;
   
  -    new->socketdes = accept(sock->socketdes, (struct sockaddr *)new->addr, 
new->addr_len);
  +    new->socketdes = accept(sock->socketdes, (struct sockaddr *)new->addr, 
&new->addr_len);
   
  +    hptr = gethostbyaddr((char *)&new->addr->sin_addr, sizeof(struct 
in_addr), AF_INET);
  +    if (hptr != NULL) {
  +        new->remote_hostname = strdup(hptr->h_name);
  +    }
  +    
  +    free(hptr);    
       if (new->socketdes >= 0)
           return new;
       free(new);
  
  
  
  1.2       +14 -0     apache-apr/apr/network_io/unix/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/network_io/unix/sockopt.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sockopt.c 1999/04/14 16:38:23     1.1
  +++ sockopt.c 1999/04/15 20:08:17     1.2
  @@ -145,3 +145,17 @@
       return APR_SUCCESS;
   }         
   
  +apr_status_t apr_gethostname(char *buf, int len)
  +{
  +    if (gethostname(buf, len) == -1)
  +        return APR_FAILURE;
  +    else
  +        return APR_SUCCESS;
  +}
  +
  +char *apr_get_remote_hostname(apr_socket_t *sock)
  +{
  +    return sock->remote_hostname;
  +}
  +
  +
  
  
  
  1.8       +3 -0      apache-apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/include/apr_network_io.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- apr_network_io.h  1999/04/15 15:41:20     1.7
  +++ apr_network_io.h  1999/04/15 20:08:20     1.8
  @@ -91,6 +91,9 @@
   apr_status_t apr_listen(apr_socket_t *, apr_int32_t);
   apr_socket_t *apr_accept(const apr_socket_t *);
   
  +char *apr_get_remote_hostname(apr_socket_t *);
  +apr_status_t apr_gethostname(char *, int);
  +
   apr_ssize_t apr_send(apr_socket_t *, const char *, int, time_t);
   apr_ssize_t apr_recv(apr_socket_t *, char *, int, time_t);
   
  
  
  
  1.10      +45 -32    apache-apr/docs/networkio.txt
  
  Index: networkio.txt
  ===================================================================
  RCS file: /home/cvs/apache-apr/docs/networkio.txt,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- networkio.txt     1999/04/15 15:41:19     1.9
  +++ networkio.txt     1999/04/15 20:08:21     1.10
  @@ -130,39 +130,20 @@
        return) new socket that has the accepted connection.
   NOTE:  accepted socket can not accept more connections.  Original socket
          remains open, and can accept more connections.
  -
  -
  -     
  - APRStatus apr_gethostbyname(char *, APRHostEnt)
  -     Lookup a host by name
  + 
  +char *apr_get_remote_hostname(apr_socket_t *)
  +        Get the host name for the remote machine
        Arguments:
  -     arg 1)  string defining the host name of interest
  -     arg 2)  returns an APRHostEnt structure that has been filled out
  -              on success.  On failure, it returns NULL.
  - APRStatus apr_gethostbyaddr(const void *, APRInt32, APRNetAddrValue,
  -                             APRHostEnt)
  -     Lookup a host by address
  -     Arguments:
  -     arg 1)  IP addr of host, not Null-terminated string
  -     arg 2)  length of IP addr
  -     arg 3)  type of address
  -     arg 4)  returns an APRHostEnt structure that has been filled out
  -              on success.  On failure, it returns NULL.
  - APRStatus apr_enumeratehostent(APRUInt32, const APRHostEnt *, APRUInt16,
  - APRNetAddr *, APRInt32);
  -     Evaluate each of the possible address of a Host Entry retrived from
  -     apr_GetHostByName or apr_GetHostByAddr.
  +        arg 1)  socket connection is on.
  +        return) name of remote machine. 
  +
  + apr_status_t apr_gethostname(char *, int)
  +        Get the host name for the machine
        Arguments:
  -     arg 1)  The index of the enumeration.  To start, set to zero.  To
  -             continue, set to last returned value.
  -     arg 2)  pointer to structure return by apr_GetHostBy* Functions.
  -     arg 3)  Port number to be asssigned as part of the APRNetAddr
  -             structure.
  -     arg 4)  Input a pointer to an APRNetAddr struct.  On output, this
  -             struct
  -             is filled in by the runtime if the returned result is > 0.
  -     arg 5) Next value for the index parameter.  If 0, the enumeration
  -             is ended.  APR_FAILURE otherwise.
  +        arg 1)  Buffer to write name to.
  +        arg 2)  Size of buffer.
  +        return) APR_SUCCESS or APR_FAILURE
  +     
    APRStatus apr_familyinet(APRInt16)
        Get the value of the address family for IP
        Arguments:
  @@ -203,12 +184,44 @@
                INADR_LOOPBACK equivalents.
        arg 2)  Port number to be assigned in the struct
        arg 3)  The address of the APRNetAddr struct to be filled out.
  + APRStatus apr_gethostbyname(char *, APRHostEnt)
  +     Lookup a host by name
  +     Arguments:
  +     arg 1)  string defining the host name of interest
  +     arg 2)  returns an APRHostEnt structure that has been filled out
  +              on success.  On failure, it returns NULL.
  + APRStatus apr_gethostbyaddr(const void *, APRInt32, APRNetAddrValue,
  +                             APRHostEnt)
  +     Lookup a host by address
  +     Arguments:
  +     arg 1)  IP addr of host, not Null-terminated string
  +     arg 2)  length of IP addr
  +     arg 3)  type of address
  +     arg 4)  returns an APRHostEnt structure that has been filled out
  +              on success.  On failure, it returns NULL.
  + APRStatus apr_enumeratehostent(APRUInt32, const APRHostEnt *, APRUInt16,
  + APRNetAddr *, APRInt32);
  +     Evaluate each of the possible address of a Host Entry retrived from
  +     apr_GetHostByName or apr_GetHostByAddr.
  +     Arguments:
  +     arg 1)  The index of the enumeration.  To start, set to zero.  To
  +             continue, set to last returned value.
  +     arg 2)  pointer to structure return by apr_GetHostBy* Functions.
  +     arg 3)  Port number to be asssigned as part of the APRNetAddr
  +             structure.
  +     arg 4)  Input a pointer to an APRNetAddr struct.  On output, this
  +             struct
  +             is filled in by the runtime if the returned result is > 0.
  +     arg 5) Next value for the index parameter.  If 0, the enumeration
  +             is ended.  APR_FAILURE otherwise.
  +
  +
   
   **************** IMPLEMENTATION DETAILS *****************
   
   struct apr_socket_t {
       int socketdes
  -    char *hostname
  +    char *remote_hostname
       struct sockaddr *addr
       size_t addr_len
   }
  
  
  

Reply via email to