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/unix sa_common.c
Date Sun, 19 Nov 2000 01:21:12 GMT
trawick     00/11/18 17:21:12

  Modified:    src/lib/apr/network_io/unix sa_common.c
  Log:
  apr_getaddrinfo() changes:
  1) fix a Win32 bug in the gethostbyname logic; we need to have a
     WIN32 check to see if we return apr_get_netos_error() instead of
     h_errno + APR_OS_START_SYSERR; this bug was introduced a recently
     when I moved hostname resolution from apr_connect() to this
     function
  2) when the system has getaddrinfo() and we support IPv6, use
     getaddrinfo() instead
  
  Revision  Changes    Path
  1.10      +58 -7     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- sa_common.c	2000/11/18 20:52:28	1.9
  +++ sa_common.c	2000/11/19 01:21:11	1.10
  @@ -204,24 +204,69 @@
           return APR_EINVAL;
       }
       return APR_SUCCESS;
  -    
   }
   
   apr_status_t apr_getaddrinfo(apr_sockaddr_t **sa, const char *hostname, 
                                apr_int32_t family, apr_port_t port,
                                apr_int32_t flags, apr_pool_t *p)
   {
  -    struct hostent *hp;
  -
       (*sa) = (apr_sockaddr_t *)apr_pcalloc(p, sizeof(apr_sockaddr_t));
       if ((*sa) == NULL)
           return APR_ENOMEM;
       (*sa)->pool = p;
  -    (*sa)->sa.sin.sin_family = APR_INET; /* we don't yet support IPv6 */
  -    (*sa)->sa.sin.sin_port = htons(port);
  -    set_sockaddr_vars(*sa, (*sa)->sa.sin.sin_family);
  +    (*sa)->hostname = apr_pstrdup(p, hostname);
   
  +#if defined(HAVE_GETADDRINFO) && APR_HAVE_IPV6
  +    if (hostname != NULL) {
  +        struct addrinfo hints, *ai;
  +        int error;
  +        char num[8];
  +
  +        memset(&hints, 0, sizeof(hints));
  +        hints.ai_flags = AI_CANONNAME;
  +        hints.ai_family = family;
  +        hints.ai_socktype = SOCK_STREAM;
  +        hints.ai_protocol = 0;
  +        apr_snprintf(num, sizeof(num), "%d", port);
  +        error = getaddrinfo(hostname, num, &hints, &ai);
  +        if (error) {
  +            if (error == EAI_SYSTEM) {
  +                return errno;
  +            }
  +            else {
  +                /* XXX fixme!
  +                 * no current way to represent this with APR's error
  +                 * scheme... note that glibc uses negative values for these
  +                 * numbers, perhaps so they don't conflict with h_errno
  +                 * values...  Tru64 uses positive values which conflict
  +                 * with h_errno values
  +                 */
  +                return error + APR_OS_START_SYSERR;
  +            }
  +        }
  +        (*sa)->sa.sin.sin_family = ai->ai_family;
  +        memcpy(&(*sa)->sa, ai->ai_addr, ai->ai_addrlen);
  +    }
  +    else {
  +        if (family == APR_UNSPEC) {
  +            (*sa)->sa.sin.sin_family = APR_INET;
  +        }
  +        else {
  +            (*sa)->sa.sin.sin_family = family;
  +        }
  +    }
  +    set_sockaddr_vars(*sa, (*sa)->sa.sin.sin_family);
  +#else
  +    if (family == APR_UNSPEC) {
  +        (*sa)->sa.sin.sin_family = APR_INET; /* we don't yet support IPv6 here */
  +    }
  +    else {
  +        (*sa)->sa.sin.sin_family = family;
  +    }
  +    set_sockaddr_vars(*sa, (*sa)->sa.sin.sin_family);
       if (hostname != NULL) {
  +        struct hostent *hp;
  +
   #ifndef GETHOSTBYNAME_HANDLES_NAS
           if (*hostname >= '0' && *hostname <= '9' &&
               strspn(hostname, "0123456789.") == strlen(hostname)) {
  @@ -233,7 +278,11 @@
           hp = gethostbyname(hostname);
   
           if (!hp)  {
  +#ifdef WIN32
  +            apr_get_netos_error();
  +#else
               return (h_errno + APR_OS_START_SYSERR);
  +#endif
           }
   
           memcpy((char *)&(*sa)->sa.sin.sin_addr, hp->h_addr_list[0],
  @@ -245,6 +294,8 @@
           }
   #endif
       }
  -   (*sa)->hostname = apr_pstrdup(p, hostname);
  +#endif
  +    /* XXX IPv6: assumes sin_port and sin6_port at same offset */
  +    (*sa)->sa.sin.sin_port = htons(port);
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message