From b879e0835b3eaca8f23575dfad8a55d7c7722f36 Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Tue, 9 Jun 2020 13:44:42 +0200 Subject: [PATCH] explicitely test for ws2tcpip.h header, fix library detection on windows for inet_ntop with corrent library, guard includes and definitions with configure results, cleanup header inclusion --- Headers/GNUstepBase/config.h.in | 3 +++ Source/GSSocketStream.m | 21 +++++++++++++++------ Source/NSHost.m | 11 ++++++++--- configure | 14 +++++++++++++- configure.ac | 3 ++- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Headers/GNUstepBase/config.h.in b/Headers/GNUstepBase/config.h.in index 26409bfd4..a4657364d 100644 --- a/Headers/GNUstepBase/config.h.in +++ b/Headers/GNUstepBase/config.h.in @@ -785,6 +785,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_WINDOWS_H +/* Define to 1 if you have the header file. */ +#undef HAVE_WS2TCPIP_H + /* Define to 1 if you have the header file. */ #undef HAVE_ZLIB_H diff --git a/Source/GSSocketStream.m b/Source/GSSocketStream.m index 9783b4548..30d61da24 100644 --- a/Source/GSSocketStream.m +++ b/Source/GSSocketStream.m @@ -56,12 +56,21 @@ #endif #ifdef _WIN32 -extern const char *inet_ntop(int, const void *, char *, size_t); -extern int inet_pton(int , const char *, void *); -#define OPTLEN int -#else -#define OPTLEN socklen_t -#endif + #ifdef HAVE_WS2TCPIP_H + #include + #endif // HAVE_WS2TCPIP_H + + #if !defined(HAVE_INET_NTOP) + extern const char *inet_ntop(int, const void *, char *, size_t); + #endif + #if !defined(HAVE_INET_NTOP) + extern int inet_pton(int , const char *, void *); + #endif + + #define OPTLEN int +#else // _WIN32 + #define OPTLEN socklen_t +#endif // _WIN32 unsigned GSPrivateSockaddrLength(struct sockaddr *addr) diff --git a/Source/NSHost.m b/Source/NSHost.m index 8da737918..81a49bf0f 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -39,17 +39,22 @@ #import "Foundation/NSCoder.h" #if defined(_WIN32) -#include +#ifdef HAVE_WS2TCPIP_H #include +#endif // HAVE_WS2TCPIP_H +#if !defined(HAVE_INET_NTOP) extern const char *inet_ntop(int, const void *, char *, size_t); +#endif +#if !defined(HAVE_INET_NTOP) extern int inet_pton(int , const char *, void *); -#else +#endif +#else /* !_WIN32 */ #include #include #include #include #include -#endif /* !_WIN32*/ +#endif /* !_WIN32 */ #ifndef INADDR_NONE #define INADDR_NONE -1 diff --git a/configure b/configure index 70ad993b9..83271eae9 100755 --- a/configure +++ b/configure @@ -9721,6 +9721,18 @@ fi # These used by GSFileHandle.m and distributed objects # On some systems we need -lnsl ... so check for that case. #-------------------------------------------------------------------- +for ac_header in ws2tcpip.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "ws2tcpip.h" "ac_cv_header_ws2tcpip_h" "$ac_includes_default" +if test "x$ac_cv_header_ws2tcpip_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_WS2TCPIP_H 1 +_ACEOF + +fi + +done + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing inet_ntop" >&5 $as_echo_n "checking for library containing inet_ntop... " >&6; } if ${ac_cv_search_inet_ntop+:} false; then : @@ -9745,7 +9757,7 @@ return inet_ntop (); return 0; } _ACEOF -for ac_lib in '' nsl; do +for ac_lib in '' nsl Ws2_32; do if test -z "$ac_lib"; then ac_res="none required" else diff --git a/configure.ac b/configure.ac index e541f8c02..907662c4a 100644 --- a/configure.ac +++ b/configure.ac @@ -2497,7 +2497,8 @@ AC_SUBST(DEFINE_UINTPTR_T) # These used by GSFileHandle.m and distributed objects # On some systems we need -lnsl ... so check for that case. #-------------------------------------------------------------------- -AC_SEARCH_LIBS([inet_ntop],[nsl]) +AC_CHECK_HEADERS(ws2tcpip.h) +AC_SEARCH_LIBS([inet_ntop],[nsl Ws2_32]) AC_CHECK_FUNCS(gethostbyaddr_r inet_aton inet_pton inet_ntop sigaction) USE_ZLIB=0