From: Giovanni Bechis Date: Wed, 5 Aug 2026 09:00:00 +0000 (+0000) Subject: OpenBSD doesn't support connect() to INADDR_ANY and returns EINVAL (22), X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6de657d26a2da0b754a23a7baddae62f35b57fb;p=thirdparty%2Fapache%2Fhttpd.git OpenBSD doesn't support connect() to INADDR_ANY and returns EINVAL (22), fallback to 127.0.0.1 if lp->bind_addr is INADDR_ANY and that connect() fails with EINVAL bz #69857 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1936893 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm_unix.c b/server/mpm_unix.c index ed4555ad0b..416f3f22d6 100644 --- a/server/mpm_unix.c +++ b/server/mpm_unix.c @@ -674,6 +674,34 @@ static apr_status_t dummy_connection(ap_pod_t *pod) } rv = apr_socket_connect(sock, lp->bind_addr); +#ifdef __OpenBSD__ + /* OpenBSD's connect() returns EINVAL when the target address is the + * wildcard address (INADDR_ANY / IN6ADDR_ANY), + * Retry against the loopback address in that case. */ + if (rv != APR_SUCCESS && APR_STATUS_IS_EINVAL(rv)) { + int is_wildcard = 0; + + if (lp->bind_addr->family == APR_INET) { + is_wildcard = (lp->bind_addr->sa.sin.sin_addr.s_addr == INADDR_ANY); + } +#if APR_HAVE_IPV6 + else if (lp->bind_addr->family == APR_INET6) { + is_wildcard = IN6_IS_ADDR_UNSPECIFIED(&lp->bind_addr->sa.sin6.sin6_addr); + } +#endif + + if (is_wildcard) { + apr_sockaddr_t *loopback; + const char *ip = (lp->bind_addr->family == APR_INET6) ? "::1" : "127.0.0.1"; + + rv = apr_sockaddr_info_get(&loopback, ip, lp->bind_addr->family, + lp->bind_addr->port, 0, p); + if (rv == APR_SUCCESS) { + rv = apr_socket_connect(sock, loopback); + } + } + } +#endif /* __OpenBSD__ */ if (rv != APR_SUCCESS) { int log_level = APLOG_WARNING;