From: Justin Erenkrantz Date: Fri, 15 Aug 2003 02:25:41 +0000 (+0000) Subject: Change Listen directive to bind to all addresses returned by X-Git-Tag: pre_ajp_proxy~1269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c46cea082693d214b2fd5631ea851079093f61d4;p=apache Change Listen directive to bind to all addresses returned by apr_sockaddr_info_get when a hostname is not specified. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100999 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 152c5c23d1..111fa74c37 100644 --- a/CHANGES +++ b/CHANGES @@ -2,9 +2,12 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Change Listen directive to bind to all addresses when a hostname is + not specified. [Justin Erenkrantz] + *) Correct failure with Listen directives on machines with IPv6 enabled. [Colm MacCárthaigh , Justin Erenkrantz] - + *) Fix a link failure in mod_ssl when the OpenSSL libraries contain the ENGINE functions but the engine header files are missing. [Cliff Woolley] diff --git a/server/listen.c b/server/listen.c index c91da9f8db..10aca871ff 100644 --- a/server/listen.c +++ b/server/listen.c @@ -232,16 +232,18 @@ static apr_status_t close_listeners_on_exec(void *v) static const char *alloc_listener(process_rec *process, char *addr, apr_port_t port) { ap_listen_rec **walk; - ap_listen_rec *new; apr_status_t status; - apr_port_t oldport; apr_sockaddr_t *sa; + int found_listener = 0; /* see if we've got an old listener for this address:port */ - for (walk = &old_listeners; *walk; walk = &(*walk)->next) { + for (walk = &old_listeners; *walk;) { sa = (*walk)->bind_addr; /* Some listeners are not real so they will not have a bind_addr. */ if (sa) { + ap_listen_rec *new; + apr_port_t oldport; + apr_sockaddr_port_get(&oldport, sa); /* If both ports are equivalent, then if their names are equivalent, * then we will re-use the existing record. @@ -253,16 +255,20 @@ static const char *alloc_listener(process_rec *process, char *addr, apr_port_t p *walk = new->next; new->next = ap_listeners; ap_listeners = new; - return NULL; + found_listener = 1; + continue; } } + + walk = &(*walk)->next; + } + + if (found_listener) { + return NULL; } - /* this has to survive restarts */ - new = apr_palloc(process->pool, sizeof(ap_listen_rec)); - new->active = 0; - if ((status = apr_sockaddr_info_get(&new->bind_addr, addr, APR_UNSPEC, - port, 0, process->pool)) + if ((status = apr_sockaddr_info_get(&sa, addr, APR_UNSPEC, port, 0, + process->pool)) != APR_SUCCESS) { ap_log_perror(APLOG_MARK, APLOG_CRIT, status, process->pool, "alloc_listener: failed to set up sockaddr for %s", @@ -270,33 +276,40 @@ static const char *alloc_listener(process_rec *process, char *addr, apr_port_t p return "Listen setup failed"; } - while (new->bind_addr) { + while (sa) { + ap_listen_rec *new; + + /* this has to survive restarts */ + new = apr_palloc(process->pool, sizeof(ap_listen_rec)); + new->active = 0; + new->bind_addr = sa; + + /* Go to the next sockaddr. */ + sa = sa->next; + status = apr_socket_create(&new->sd, new->bind_addr->family, SOCK_STREAM, process->pool); + #if APR_HAVE_IPV6 /* What could happen is that we got an IPv6 address, but this system * doesn't actually support IPv6. Try the next address. */ if (status != APR_SUCCESS && !addr && new->bind_addr->family == APR_INET6) { - new->bind_addr = new->bind_addr->next; + continue; } - else { - break; - } -#else - break; #endif - } + if (status != APR_SUCCESS) { + ap_log_perror(APLOG_MARK, APLOG_CRIT, status, process->pool, + "alloc_listener: failed to get a socket for %s", + addr); + return "Listen setup failed"; + } - if (status != APR_SUCCESS) { - ap_log_perror(APLOG_MARK, APLOG_CRIT, status, process->pool, - "alloc_listener: failed to get a socket for %s", addr); - return "Listen setup failed"; + new->next = ap_listeners; + ap_listeners = new; } - new->next = ap_listeners; - ap_listeners = new; return NULL; }