From: Joe Orton Date: Thu, 25 Aug 2005 15:37:39 +0000 (+0000) Subject: * server/listen.c (IS_INADDR_ANY, IS_IN6ADDR_ANY): New macros. X-Git-Tag: 2.3.0~3077 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f75bd350859ee044c009dda66b2da942db8a541;p=apache * server/listen.c (IS_INADDR_ANY, IS_IN6ADDR_ANY): New macros. (open_listeners): Simplify using the new macros; no functional change. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@240092 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/listen.c b/server/listen.c index cf382f3cd6..b322023f27 100644 --- a/server/listen.c +++ b/server/listen.c @@ -339,6 +339,15 @@ static const char *alloc_listener(process_rec *process, char *addr, return NULL; } +/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the + * IPv4 match-any-address, 0.0.0.0. */ +#define IS_INADDR_ANY(addr) ((addr)->family == APR_INET \ + && (addr)->sa.sin.sin_addr.s_addr == INADDR_ANY) + +/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the + * IPv6 match-any-address, [::]. */ +#define IS_IN6ADDR_ANY(addr) ((addr)->family == APR_INET6 \ + && IN6_IS_ADDR_UNSPECIFIED(&(addr)->sa.sin6.sin6_addr)) /** * Create, open, listen, and bind all sockets. @@ -373,16 +382,13 @@ static int open_listeners(apr_pool_t *pool) * listen (which would generate an error). IPv4 will be handled * on the established IPv6 socket. */ - if (previous != NULL && - lr->bind_addr->family == APR_INET && - lr->bind_addr->sa.sin.sin_addr.s_addr == INADDR_ANY && - lr->bind_addr->port == previous->bind_addr->port && - previous->bind_addr->family == APR_INET6 && - IN6_IS_ADDR_UNSPECIFIED( - &previous->bind_addr->sa.sin6.sin6_addr) && - apr_socket_opt_get(previous->sd, APR_IPV6_V6ONLY, - &v6only_setting) == APR_SUCCESS && - v6only_setting == 0) { + if (previous != NULL + && IS_INADDR_ANY(lr->bind_addr) + && lr->bind_addr->port == previous->bind_addr->port + && IS_IN6ADDR_ANY(previous->bind_addr) + && apr_socket_opt_get(previous->sd, APR_IPV6_V6ONLY, + &v6only_setting) == APR_SUCCESS + && v6only_setting == 0) { /* Remove the current listener from the list */ previous->next = lr->next; @@ -400,12 +406,10 @@ static int open_listeners(apr_pool_t *pool) * error. The user will still get a warning from make_sock * though. */ - if (lr->next != NULL && lr->bind_addr->family == APR_INET6 && - IN6_IS_ADDR_UNSPECIFIED( - &lr->bind_addr->sa.sin6.sin6_addr) && - lr->bind_addr->port == lr->next->bind_addr->port && - lr->next->bind_addr->family == APR_INET && - lr->next->bind_addr->sa.sin.sin_addr.s_addr == INADDR_ANY) { + if (lr->next != NULL + && IS_IN6ADDR_ANY(lr->bind_addr) + && lr->bind_addr->port == lr->next->bind_addr->port + && IS_INADDR_ANY(lr->next->bind_addr)) { /* Remove the current listener from the list */ if (previous) {