Another possible conflict between the Windows inet_ntop, inet_pton functions and the gnulib ones is at the source code level: When a compilation unit includes first <arpa/inet.h> and then <ws2tcpip.h> (with _WIN32_WINNT >= 0x0600), there would be conflicting declarations of the rpl_inet_ntop or rpl_inet_ntop functions.
This patch fixes it. 2019-06-30 Bruno Haible <br...@clisp.org> inet_ntop, inet_pton: Avoid conflict with native Windows functions. * m4/sys_socket_h.m4 (gl_PREREQ_SYS_H_WS2TCPIP): New macro, extracted from gl_PREREQ_SYS_H_SOCKET. (gl_PREREQ_SYS_H_SOCKET): Invoke it. * m4/arpa_inet_h.m4 (gl_HEADER_ARPA_INET): Invoke gl_PREREQ_SYS_H_WS2TCPIP. * modules/arpa_inet (Files): Add m4/sys_socket_h.m4, m4/socklen.m4. (Makefile.am): Substitute HAVE_WS2TCPIP_H. * lib/arpa_inet.in.h: Include <ws2tcpip.h>. diff --git a/lib/arpa_inet.in.h b/lib/arpa_inet.in.h index 430c3d3..96793ad 100644 --- a/lib/arpa_inet.in.h +++ b/lib/arpa_inet.in.h @@ -49,6 +49,12 @@ #ifndef _@GUARD_PREFIX@_ARPA_INET_H #define _@GUARD_PREFIX@_ARPA_INET_H +/* Get all possible declarations of inet_ntop() and inet_pton(). */ +#if (@GNULIB_INET_NTOP@ || @GNULIB_INET_PTON@ || defined GNULIB_POSIXCHECK) \ + && @HAVE_WS2TCPIP_H@ +# include <ws2tcpip.h> +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ /* The definition of _GL_ARG_NONNULL is copied here. */ diff --git a/m4/arpa_inet_h.m4 b/m4/arpa_inet_h.m4 index 46c7d28..645011d 100644 --- a/m4/arpa_inet_h.m4 +++ b/m4/arpa_inet_h.m4 @@ -1,4 +1,4 @@ -# arpa_inet_h.m4 serial 13 +# arpa_inet_h.m4 serial 14 dnl Copyright (C) 2006, 2008-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -24,6 +24,8 @@ AC_DEFUN([gl_HEADER_ARPA_INET], AC_REQUIRE([gl_FEATURES_H]) + gl_PREREQ_SYS_H_WS2TCPIP + dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[ diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4 index 1ea7b0b..d0a9020 100644 --- a/m4/sys_socket_h.m4 +++ b/m4/sys_socket_h.m4 @@ -1,4 +1,4 @@ -# sys_socket_h.m4 serial 23 +# sys_socket_h.m4 serial 24 dnl Copyright (C) 2005-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -104,17 +104,11 @@ AC_DEFUN([gl_PREREQ_SYS_H_SOCKET], gl_CHECK_NEXT_HEADERS([sys/socket.h]) if test $ac_cv_header_sys_socket_h = yes; then HAVE_SYS_SOCKET_H=1 - HAVE_WS2TCPIP_H=0 else HAVE_SYS_SOCKET_H=0 - if test $ac_cv_header_ws2tcpip_h = yes; then - HAVE_WS2TCPIP_H=1 - else - HAVE_WS2TCPIP_H=0 - fi fi AC_SUBST([HAVE_SYS_SOCKET_H]) - AC_SUBST([HAVE_WS2TCPIP_H]) + gl_PREREQ_SYS_H_WS2TCPIP ]) # Common prerequisites of the <sys/socket.h> replacement and of the @@ -142,6 +136,24 @@ AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2], AC_SUBST([HAVE_WINSOCK2_H]) ]) +# Common prerequisites of the <sys/socket.h> replacement and of the +# <arpa/inet.h> replacement. +# Sets and substitutes HAVE_WS2TCPIP_H. +AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP], +[ + AC_REQUIRE([gl_CHECK_SOCKET_HEADERS]) + if test $ac_cv_header_sys_socket_h = yes; then + HAVE_WS2TCPIP_H=0 + else + if test $ac_cv_header_ws2tcpip_h = yes; then + HAVE_WS2TCPIP_H=1 + else + HAVE_WS2TCPIP_H=0 + fi + fi + AC_SUBST([HAVE_WS2TCPIP_H]) +]) + AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR], [ dnl Use AC_REQUIRE here, so that the default settings are expanded once only. diff --git a/modules/arpa_inet b/modules/arpa_inet index 005690f..317bf8d 100644 --- a/modules/arpa_inet +++ b/modules/arpa_inet @@ -4,6 +4,8 @@ A GNU-like <arpa/inet.h>. Files: lib/arpa_inet.in.h m4/arpa_inet_h.m4 +m4/sys_socket_h.m4 +m4/socklen.m4 Depends-on: include_next @@ -34,6 +36,7 @@ arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \ -e 's/@''GNULIB_INET_NTOP''@/$(GNULIB_INET_NTOP)/g' \ -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \ + -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \ -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \