Bug 65087 - IPv6 support not detected when compiling on macOS with Xcode >= 12 due to implicit declaration of functions
Summary: IPv6 support not detected when compiling on macOS with Xcode >= 12 due to imp...
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 1.7.0
Hardware: Macintosh All
: P2 major (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-17 09:14 UTC by Ryan Schmidt
Modified: 2021-01-18 15:42 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Schmidt 2021-01-17 09:14:48 UTC
When APR 1.7.0* is compiled with Xcode 12 or later on macOS 10.15 or later (using MacPorts, though that should not matter), IPv6 support is not detected. Output from ./configure includes:


checking for inet_addr... no
checking for inet_network... no

checking for working getnameinfo... no

checking if APR supports IPv6... no -- no getnameinfo


config.log says:


configure:22788: checking for inet_addr
configure:22814: /usr/bin/clang -c -pipe -Os -Werror=implicit-function-declaration -arch x86_64 -I/opt/local/include -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -DDARWIN_10 conftest.c >&5
conftest.c:98:1: error: implicit declaration of function 'inet_addr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
inet_addr("127.0.0.1");
^
1 error generated.


configure:22836: checking for inet_network
configure:22862: /usr/bin/clang -c -pipe -Os -Werror=implicit-function-declaration -arch x86_64 -I/opt/local/include -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -DDARWIN_10 conftest.c >&5
conftest.c:98:1: error: implicit declaration of function 'inet_network' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
inet_network("127.0.0.1");
^
1 error generated.


configure:29708: checking for working getnameinfo
configure:29762: /usr/bin/clang -o conftest -pipe -Os -Werror=implicit-function-declaration -arch x86_64 -I/opt/local/include -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -DDARWIN_10 -L/opt/local/lib -Wl,-headerpad_max_install_names -arch x86_64 conftest.c -lpthread >&5
conftest.c:226:26: error: implicit declaration of function 'inet_addr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    sa.sin_addr.s_addr = inet_addr("127.0.0.1");
                         ^
1 error generated.


These configure checks fail because they don't include the necessary headers, such as <arpa/inet.h>.

The configure checks are written with lines like the following:


#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif


This doesn't work because HAVE_ARPA_INET_H doesn't get defined until later on in the configure script.


The consequence is that APR gets built without IPv6 support, which Apache users have noticed and reported here:

https://lists.macports.org/pipermail/macports-users/2021-January/049311.html


*I know there were other implicit declaration of function problems in 1.7.0, at least some of which have already been addressed by:

https://svn.apache.org/viewvc/apr/apr/trunk/configure.in?r1=1878362&r2=1882979

MacPorts uses a larger patch than that:

https://github.com/macports/macports-ports/blob/a14fc256193020cb92174919db733b10803cc3ca/devel/apr/files/patch-configure.diff

I have not personally attempted to verify whether all of our additional changes are necessary but presumably the committer thought they were.
Comment 1 Daniel J. Luke 2021-01-17 23:05:22 UTC
I don't think this is the whole story - If I start a configure and pause it #define HAVE_ARPA_INET_H 1 is in confdefs.h before the Networking Support or IPv6 Networking support sections are run.

The test for getnameinfo, however, doesn't appear to include arpa/inet.h at all, which is needed to get the definition of inet_addr

If I add it to the test (or force the test to pass by setting ac_cv_working_getnameinfo), and rebuild httpd against the new apr, it starts up just fine and listens on both IPv4 and IPv6. (If I don't rebuild httpd, I get `AH00072: make_sock: could not bind to address 0.0.0.0:80`

This should fix things:

% diff apr_network.m4 apr_network.m4.orig 
--- apr_network.m4.orig	2021-01-17 17:56:35.000000000 -0500
+++ apr_network.m4	2021-01-17 17:57:00.000000000 -0500
@@ -151,9 +151,6 @@
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
 
 int main(void) {
     struct sockaddr_in sa;
Comment 2 Ryan Schmidt 2021-01-18 06:40:52 UTC
Oh ok, thanks.
Comment 3 Yann Ylavic 2021-01-18 15:42:23 UTC
This was fixed in r1882982 and backported to 1.7.x (r1882981).
Will be in the next apr-1.7 release.