You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@locus.apache.org on 2000/12/15 20:20:14 UTC

cvs commit: httpd-2.0/server config.c vhost.c

trawick     00/12/15 11:20:14

  Modified:    include  httpd.h
               server   config.c vhost.c
  Log:
  move closer to IPv6 support by changing the server_addr_rec
  representation of the bound address to something which handles
  IPv6; this also allows us to switch to APR resolver routines
  in places instead of calling gethostbyname() and gethostbyaddr()
  directly
  
  Issues remaining with this set of changes:
  
  1) apr_snprintf()'s %pA formatting needs to change to take
     apr_sockaddr_t * instead of sockaddr_in * -OR- just get rid
     of that type of formatting
  2) apr_get_inaddr() is no longer used and should be removed
  
  Revision  Changes    Path
  1.126     +1 -1      httpd-2.0/include/httpd.h
  
  Index: httpd.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/include/httpd.h,v
  retrieving revision 1.125
  retrieving revision 1.126
  diff -u -r1.125 -r1.126
  --- httpd.h	2000/12/15 13:28:51	1.125
  +++ httpd.h	2000/12/15 19:20:09	1.126
  @@ -898,7 +898,7 @@
       /** The next server in the list */
       server_addr_rec *next;
       /** The bound address, for this server */
  -    apr_in_addr_t host_addr;
  +    apr_sockaddr_t *host_addr;
       /** The bound port, for this server */
       apr_port_t host_port;
       /** The name given in <VirtualHost> */
  
  
  
  1.88      +4 -1      httpd-2.0/server/config.c
  
  Index: config.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/config.c,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- config.c	2000/11/26 04:47:30	1.87
  +++ config.c	2000/12/15 19:20:10	1.88
  @@ -1634,6 +1634,7 @@
   
   static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
   {
  +    apr_status_t rv;
       server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
   
       apr_open_stderr(&s->error_log, p);
  @@ -1653,7 +1654,9 @@
       s->next = NULL;
       s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
       /* NOT virtual host; don't match any real network interface */
  -    s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
  +    rv = apr_getaddrinfo(&s->addrs->host_addr,
  +                         NULL, APR_INET, 0, 0, p);
  +    ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
       s->addrs->host_port = 0;	/* matches any port */
       s->addrs->virthost = "";	/* must be non-NULL */
       s->names = s->wild_names = NULL;
  
  
  
  1.42      +29 -21    httpd-2.0/server/vhost.c
  
  Index: vhost.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/vhost.c,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- vhost.c	2000/12/14 18:47:30	1.41
  +++ vhost.c	2000/12/15 19:20:12	1.42
  @@ -186,11 +186,12 @@
   static const char *get_addresses(apr_pool_t *p, const char *w_,
   				 server_addr_rec ***paddr, apr_port_t port)
   {
  -    apr_in_addr_t my_addr;
  +    apr_sockaddr_t *my_addr;
       server_addr_rec *sar;
       char *t;
       int i;
       char *w;
  +    apr_status_t rv;
   
       if (*w_ == 0)
   	return NULL;
  @@ -212,9 +213,12 @@
   
       if (strcasecmp(w, "_default_") == 0
           || strcmp(w, "255.255.255.255") == 0) {
  -        my_addr.s_addr = DEFAULT_VHOST_ADDR;
  +        rv = apr_getaddrinfo(&my_addr, NULL, APR_INET, port, 0, p);
  +        ap_assert(rv == APR_SUCCESS); /* must be bug or out of storage */
  +        my_addr->sa.sin.sin_addr.s_addr = DEFAULT_VHOST_ADDR;
       } else {
  -        if (apr_get_inaddr(&my_addr, w) != APR_SUCCESS) {
  +        rv = apr_getaddrinfo(&my_addr, w, APR_INET, port, 0, p);
  +        if (rv != APR_SUCCESS) {
               ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, NULL,
                   "Cannot resolve host name %s --- ignoring!", w);
               return NULL;
  @@ -376,7 +380,7 @@
       bucket = hash_inaddr(addr);
       for (trav = iphash_table[bucket]; trav; trav = trav->next) {
   	server_addr_rec *sar = trav->sar;
  -	if ((sar->host_addr.s_addr == addr)
  +	if ((sar->host_addr->sa.sin.sin_addr.s_addr == addr)
   	    && (sar->host_port == 0 || sar->host_port == port
   		|| port == 0)) {
   	    return trav;
  @@ -407,17 +411,17 @@
       int len;
       char buf[MAX_STRING_LEN];
   
  -    if (ic->sar->host_addr.s_addr == DEFAULT_VHOST_ADDR) {
  +    if (ic->sar->host_addr->sa.sin.sin_addr.s_addr == DEFAULT_VHOST_ADDR) {
   	len = apr_snprintf(buf, sizeof(buf), "_default_:%u",
   		ic->sar->host_port);
       }
  -    else if (ic->sar->host_addr.s_addr == INADDR_ANY) {
  +    else if (ic->sar->host_addr->sa.sin.sin_addr.s_addr == INADDR_ANY) {
   	len = apr_snprintf(buf, sizeof(buf), "*:%u",
   		ic->sar->host_port);
       }
       else {
   	len = apr_snprintf(buf, sizeof(buf), "%pA:%u",
  -		&ic->sar->host_addr, ic->sar->host_port);
  +		ic->sar->host_addr, ic->sar->host_port);
       }
       if (ic->sar->host_port == 0) {
   	buf[len-1] = '*';
  @@ -546,10 +550,10 @@
        * occured in the config file, we'll copy it in that order.
        */
       for (sar = name_vhost_list; sar; sar = sar->next) {
  -	unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
  +	unsigned bucket = hash_inaddr(sar->host_addr->sa.sin.sin_addr.s_addr);
   	ipaddr_chain *ic = new_ipaddr_chain(p, NULL, sar);
   
  -	if (sar->host_addr.s_addr != INADDR_ANY) {
  +	if (sar->host_addr->sa.sin.sin_addr.s_addr != INADDR_ANY) {
   	    *iphash_table_tail[bucket] = ic;
   	    iphash_table_tail[bucket] = &ic->next;
   	}
  @@ -577,8 +581,8 @@
   	for (sar = s->addrs; sar; sar = sar->next) {
   	    ipaddr_chain *ic;
   
  -	    if (sar->host_addr.s_addr == DEFAULT_VHOST_ADDR
  -		|| sar->host_addr.s_addr == INADDR_ANY) {
  +	    if (sar->host_addr->sa.sin.sin_addr.s_addr == DEFAULT_VHOST_ADDR
  +		|| sar->host_addr->sa.sin.sin_addr.s_addr == INADDR_ANY) {
   		ic = find_default_server(sar->host_port);
   		if (!ic || !add_name_vhost_config(p, main_s, s, sar, ic)) {
   		    if (ic && ic->sar->host_port != 0) {
  @@ -594,10 +598,10 @@
   	    }
   	    else {
   		/* see if it matches something we've already got */
  -		ic = find_ipaddr(&sar->host_addr, sar->host_port);
  +		ic = find_ipaddr(&sar->host_addr->sa.sin.sin_addr, sar->host_port);
   
   		if (!ic) {
  -		    unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
  +		    unsigned bucket = hash_inaddr(sar->host_addr->sa.sin.sin_addr.s_addr);
   
   		    ic = new_ipaddr_chain(p, s, sar);
   		    ic->next = *iphash_table_tail[bucket];
  @@ -633,20 +637,24 @@
   		    apr_pstrdup(p, "bogus_host_without_forward_dns");
   	    }
   	    else {
  -		struct hostent *h;
  +		apr_status_t rv;
  +                char *hostname;
   
  -		if ((h = gethostbyaddr((char *) &(s->addrs->host_addr),
  -					sizeof(struct in_addr), APR_INET))) {
  -		    s->server_hostname = apr_pstrdup(p, (char *) h->h_name);
  +                rv = apr_getnameinfo(&hostname, s->addrs->host_addr, 0);
  +                if (rv == APR_SUCCESS) {
  +                    s->server_hostname = apr_pstrdup(p, hostname);
   		}
   		else {
   		    /* again, what can we do?  They didn't specify a
   		       ServerName, and their DNS isn't working. -djg */
  +                    char *ipaddr_str;
  +
  +                    apr_get_ipaddr(&ipaddr_str, s->addrs->host_addr);
   		    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_s,
  -			    "Failed to resolve server name "
  -			    "for %s (check DNS) -- or specify an explicit "
  -			    "ServerName",
  -			    inet_ntoa(s->addrs->host_addr));
  +                                 "Failed to resolve server name "
  +                                 "for %s (check DNS) -- or specify an explicit "
  +                                 "ServerName",
  +                                 ipaddr_str);
   		    s->server_hostname =
   			apr_pstrdup(p, "bogus_host_without_reverse_dns");
   		}