rbb         99/04/15 08:41:20

  Modified:    apr/network_io/unix networkio.h sockets.c
               docs     networkio.txt
               include  apr_network_io.h
  Log:
  Cleaned up some memory leaks in network code. And made the sockets know their
  own hostname.
  
  Revision  Changes    Path
  1.4       +1 -2      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- networkio.h       1999/04/14 21:02:06     1.3
  +++ networkio.h       1999/04/15 15:41:18     1.4
  @@ -56,10 +56,9 @@
   #ifndef NETWORK_IO_H
   #define NETWORK_IO_H
   
  -
   struct socket_t {
       int socketdes;
  -    char *hostname;
  +    char hostname[MAXHOSTNAMELEN];
       struct sockaddr_in *addr;
       size_t addr_len;
   };
  
  
  
  1.4       +10 -1     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- sockets.c 1999/04/15 14:57:31     1.3
  +++ sockets.c 1999/04/15 15:41:18     1.4
  @@ -66,9 +66,13 @@
   {
       apr_socket_t *thesocket = (apr_socket_t *)malloc(sizeof(apr_socket_t));
       
  -    thesocket->hostname = NULL;
       thesocket->socketdes = socket(AF_INET ,SOCK_STREAM, IPPROTO_TCP);
   
  +    if (gethostname(thesocket->hostname, MAXHOSTNAMELEN + 1) == -1) { 
  +        free(thesocket);
  +        return NULL;
  +    }
  +
       thesocket->addr = (struct sockaddr_in *)malloc(sizeof(struct 
sockaddr_in));
       thesocket->addr->sin_family = AF_INET;
       thesocket->addr->sin_addr.s_addr = INADDR_ANY;
  @@ -76,6 +80,8 @@
       thesocket->addr_len = sizeof(thesocket->addr);
       
       if (thesocket->socketdes < 0) {
  +        free(thesocket->addr);
  +        free(thesocket);
           return NULL;
       }
       else {
  @@ -131,10 +137,13 @@
   {
       apr_socket_t *new = (apr_socket_t *)malloc(sizeof(apr_socket_t));
   
  +    strcpy(new->hostname, sock->hostname);
  +
       new->socketdes = accept(sock->socketdes, (struct sockaddr *)new->addr, 
new->addr_len);
   
       if (new->socketdes >= 0)
           return new;
  +    free(new);
       return NULL;
   }
   
  
  
  
  1.9       +10 -10    apache-apr/docs/networkio.txt
  
  Index: networkio.txt
  ===================================================================
  RCS file: /home/cvs/apache-apr/docs/networkio.txt,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- networkio.txt     1999/04/15 14:57:30     1.8
  +++ networkio.txt     1999/04/15 15:41:19     1.9
  @@ -133,16 +133,6 @@
   
   
        
  - APRStatus apr_initializenetaddr(APRNetAddrValue, APRUInt16, APRNetAddr);
  -     Initialize the fields of a APRNetAddr.  assigning well known values
  -     as appropriate.  This function only sets up values in the APRNetAddr
  -     structure.  It does not setup the connection.
  -     Arguments:
  -     arg 1)  The value to assign to the IP address portion of the 
  -             APRNetAddr struct.  Can only specify INADDR_ANY and
  -             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:
  @@ -203,6 +193,16 @@
        Arguments:
        arg 1)  The file desc of the socket to retrieve the name for.
        arg 2)  structure to store socket address in.
  + APRStatus apr_initializenetaddr(APRNetAddrValue, APRUInt16, APRNetAddr);
  +     Initialize the fields of a APRNetAddr.  assigning well known values
  +     as appropriate.  This function only sets up values in the APRNetAddr
  +     structure.  It does not setup the connection.
  +     Arguments:
  +     arg 1)  The value to assign to the IP address portion of the 
  +             APRNetAddr struct.  Can only specify INADDR_ANY and
  +             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.
   
   **************** IMPLEMENTATION DETAILS *****************
   
  
  
  
  1.7       +4 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- apr_network_io.h  1999/04/15 14:57:31     1.6
  +++ apr_network_io.h  1999/04/15 15:41:20     1.7
  @@ -64,6 +64,10 @@
   #define MAX_SECS_TO_LINGER 30
   #endif
   
  +#ifndef MAXHOSTNAMELEN
  +#define MAXHOSTNAMELEN 256
  +#endif
  +
   /* Socket option definitions */
   #define APR_SO_LINGER        1
   #define APR_SO_KEEPALIVE     2
  
  
  

Reply via email to