From 0b6c6f6a23c063d4ea7a1ae42967bef1684ffea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ronald=20Tschal=C3=A4r?= Date: Sat, 15 Jul 2017 00:48:28 -0700 Subject: [PATCH] Add support for apr < 1.5. apr_sockaddr_is_wildcard() was introduced in apr 1.5, but some systems are still running earlier versions. So for those we provide an implementation ourselves, which is a direct copy-paste of the implementation in apr >= 1.5. This closes issue #7 and obsoletes pull request #4. Thanks to mamanguy and earsdown for initial patch suggestions. --- mod_proxy_protocol.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mod_proxy_protocol.c b/mod_proxy_protocol.c index 0aee596..b644528 100644 --- a/mod_proxy_protocol.c +++ b/mod_proxy_protocol.c @@ -44,6 +44,7 @@ #include "ap_config.h" #include "ap_listen.h" #include "apr_strings.h" +#include "apr_version.h" module AP_MODULE_DECLARE_DATA proxy_protocol_module; @@ -79,6 +80,37 @@ static int pp_hook_pre_config(apr_pool_t *pconf, apr_pool_t *plog, return OK; } +#if !(APR_VERSION_AT_LEAST(1,5,0)) +static APR_DECLARE(int) apr_sockaddr_is_wildcard(const apr_sockaddr_t *addr) +{ + static const char inaddr_any[ +#if APR_HAVE_IPV6 + sizeof(struct in6_addr) +#else + sizeof(struct in_addr) +#endif + ] = {0}; + + if (addr->ipaddr_ptr /* IP address initialized */ + && addr->ipaddr_len <= sizeof inaddr_any) { /* else bug elsewhere? */ + if (!memcmp(inaddr_any, addr->ipaddr_ptr, addr->ipaddr_len)) { + return 1; + } +#if APR_HAVE_IPV6 + if (addr->family == AF_INET6 + && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)addr->ipaddr_ptr)) { + struct in_addr *v4 = (struct in_addr *)&((apr_uint32_t *)addr->ipaddr_ptr)[3]; + + if (!memcmp(inaddr_any, v4, sizeof *v4)) { + return 1; + } + } +#endif + } + return 0; +} +#endif + /* Similar apr_sockaddr_equal, except that it compares ports too. */ static int pp_sockaddr_equal(apr_sockaddr_t *addr1, apr_sockaddr_t *addr2) {