From: Amos Jeffries Date: Sun, 21 Dec 2014 16:28:17 +0000 (-0800) Subject: Windows: fix getaddrinfo, getnameinfo, inet_ntop and inet_pton detection X-Git-Tag: merge-candidate-3-v1~415 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55d7d5e968f2f089574e776f17918712c0877c05;p=thirdparty%2Fsquid.git Windows: fix getaddrinfo, getnameinfo, inet_ntop and inet_pton detection These API symbols are not always defined as functions, and in varying locations. AC_REPLACE_FUNCS cannot handle that kind of complexity so we must use AC_CHECK_DECL instead and provide the sequence of #include necessary to identify their existence. --- diff --git a/compat/Makefile.am b/compat/Makefile.am index 80669a21eb..805ccb9117 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -31,11 +31,15 @@ libcompat_squid_la_SOURCES = \ eui64_aton.h \ eui64_aton.c \ fdsetsize.h \ + getaddrinfo.cc \ getaddrinfo.h \ + getnameinfo.cc \ getnameinfo.h \ GnuRegex.c \ GnuRegex.h \ + inet_ntop.cc \ inet_ntop.h \ + inet_pton.cc \ inet_pton.h \ initgroups.h \ memrchr.cc \ diff --git a/compat/compat.h b/compat/compat.h index 03dd7f64cd..dee3253320 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -87,6 +87,10 @@ #include "compat/assert.h" #include "compat/compat_shared.h" +#include "compat/getaddrinfo.h" +#include "compat/getnameinfo.h" +#include "compat/inet_ntop.h" +#include "compat/inet_pton.h" #include "compat/stdvarargs.h" /* cstdio has a bunch of problems with 64-bit definitions */ diff --git a/compat/getaddrinfo.c b/compat/getaddrinfo.cc similarity index 98% rename from compat/getaddrinfo.c rename to compat/getaddrinfo.cc index 4d46ffc5dd..7f030f90f2 100644 --- a/compat/getaddrinfo.c +++ b/compat/getaddrinfo.cc @@ -49,15 +49,12 @@ /* An emulation of the RFC 2553 / Posix getaddrinfo resolver interface. */ -#if !HAVE_GETADDRINFO +#if !HAVE_DECL_GETADDRINFO /* Need to turn off Posix features in glibc to build this */ #undef _POSIX_C_SOURCE #undef _XOPEN_SOURCE -#include "compat/getaddrinfo.h" -#include "compat/inet_pton.h" - #if HAVE_STRING_H #include #endif @@ -332,5 +329,5 @@ xgai_strerror (int ecode) return eai_descr[ecode]; } -#endif /* HAVE_GETADDRINFO */ +#endif /* HAVE_DECL_GETADDRINFO */ diff --git a/compat/getaddrinfo.h b/compat/getaddrinfo.h index 0b5af56bbc..2e17d48b32 100644 --- a/compat/getaddrinfo.h +++ b/compat/getaddrinfo.h @@ -49,7 +49,7 @@ /* Structure and prototypes taken from RFC 2553 */ /* These functions are provided by the OS */ -#if !HAVE_GETADDRINFO +#if !HAVE_DECL_GETADDRINFO /* SG 23/09/2007: On Windows the following definitions are already available, may be that @@ -112,6 +112,6 @@ SQUIDCEXTERN const char *xgai_strerror (int code); #define gai_strerror xgai_strerror #endif -#endif /* HAVE_GETADDRINFO */ +#endif /* HAVE_DECL_GETADDRINFO */ #endif /* _getaddrinfo_h */ diff --git a/compat/getnameinfo.c b/compat/getnameinfo.cc similarity index 99% rename from compat/getnameinfo.c rename to compat/getnameinfo.cc index 100354a57d..dd17c5f521 100644 --- a/compat/getnameinfo.c +++ b/compat/getnameinfo.cc @@ -81,10 +81,7 @@ * - gethostbyaddr() is usually not thread safe. */ -#if !HAVE_GETNAMEINFO - -#include "compat/getaddrinfo.h" -#include "compat/inet_ntop.h" +#if !HAVE_DECL_GETNAMEINFO #if HAVE_SYS_SOCKET_H #include @@ -424,5 +421,5 @@ int flags; return n; } #endif /* INET6 */ -#endif +#endif /* HAVE_DECL_GETNAMEINFO */ diff --git a/compat/getnameinfo.h b/compat/getnameinfo.h index 605f6ca112..f09df8c6bf 100644 --- a/compat/getnameinfo.h +++ b/compat/getnameinfo.h @@ -9,7 +9,7 @@ #ifndef _getnameinfo_h #define _getnameinfo_h -#if !HAVE_GETNAMEINFO +#if !HAVE_DECL_GETNAMEINFO // RFC 2553 / Posix resolver // Reconstructed from KAME getnameinfo.c @@ -22,6 +22,6 @@ SQUIDCEXTERN int xgetnameinfo(const struct sockaddr *sa, int flags ); #define getnameinfo xgetnameinfo -#endif /* HAVE_GETNAMEINFO */ +#endif /* HAVE_DECL_GETNAMEINFO */ #endif /* _getnameinfo_h */ diff --git a/compat/inet_ntop.c b/compat/inet_ntop.cc similarity index 99% rename from compat/inet_ntop.c rename to compat/inet_ntop.cc index a99ae61ec2..1ea6580362 100644 --- a/compat/inet_ntop.c +++ b/compat/inet_ntop.cc @@ -29,8 +29,7 @@ #include "squid.h" -#if !HAVE_INET_NTOP -#include "inet_ntop.h" +#if !HAVE_DECL_INET_NTOP /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -253,5 +252,5 @@ size_t size; return (dst); } -#endif /* HAVE_INET_NTOP */ +#endif /* HAVE_DECL_INET_NTOP */ diff --git a/compat/inet_ntop.h b/compat/inet_ntop.h index 454a8a8bd9..7ae80a9691 100644 --- a/compat/inet_ntop.h +++ b/compat/inet_ntop.h @@ -10,7 +10,7 @@ #define _INC_INET_NTOP_H /* Use the system provided version where possible */ -#if !HAVE_INET_NTOP +#if !HAVE_DECL_INET_NTOP /* char * * inet_ntop(af, src, dst, size) @@ -23,6 +23,6 @@ SQUIDCEXTERN const char * xinet_ntop(int af, const void *src, char *dst, size_t size); #define inet_ntop xinet_ntop -#endif +#endif /* HAVE_DECL_INET_NTOP */ #endif /* _INC_INET_NTOP_H */ diff --git a/compat/inet_pton.c b/compat/inet_pton.cc similarity index 99% rename from compat/inet_pton.c rename to compat/inet_pton.cc index 7e158b805c..8090903b0b 100644 --- a/compat/inet_pton.c +++ b/compat/inet_pton.cc @@ -26,7 +26,7 @@ #include "squid.h" -#if !HAVE_INET_PTON +#if !HAVE_DECL_INET_PTON /* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") @@ -274,5 +274,5 @@ u_char *dst; return (1); } -#endif /* HAVE_INET_PTON */ +#endif /* HAVE_DECL_INET_PTON */ diff --git a/compat/inet_pton.h b/compat/inet_pton.h index d0d46c49c6..30f563ecc1 100644 --- a/compat/inet_pton.h +++ b/compat/inet_pton.h @@ -10,7 +10,7 @@ #define _INC_INET_PTON_H /* Use the system provided version where possible */ -#if !HAVE_INET_PTON +#if !HAVE_DECL_INET_PTON /* int * inet_pton(af, src, dst) @@ -26,6 +26,6 @@ SQUIDCEXTERN int xinet_pton(int af, const char *src, void *dst); #define inet_pton xinet_pton -#endif +#endif /* HAVE_DECL_INET_PTON */ #endif /* _INC_INET_NTOP_H */ diff --git a/compat/os/mswindows.h b/compat/os/mswindows.h index 1d3e6eb2fe..0f31a2d52a 100644 --- a/compat/os/mswindows.h +++ b/compat/os/mswindows.h @@ -621,6 +621,13 @@ getsockopt(int s, int l, int o, void * v, socklen_t * n) } #define getsockopt(s,l,o,v,n) Squid::getsockopt(s,l,o,v,n) +inline char * +inet_ntop(int af, const void *src, char *dst, size_t size) +{ + return (char*)InetNtopA(af, const_cast(src), dst, size); +} +#define inet_ntop(a,s,d,l) Squid::inet_ntop(a,s,d,l) + /* Simple ioctl() emulation */ inline int ioctl(int s, int c, void * a) diff --git a/configure.ac b/configure.ac index bc586c6b99..bcf67bbf68 100644 --- a/configure.ac +++ b/configure.ac @@ -3346,17 +3346,42 @@ AC_CHECK_FUNCS(\ dnl ... and some we provide local replacements for AC_REPLACE_FUNCS(\ drand48 \ - inet_ntop \ - inet_pton \ initgroups \ - getaddrinfo \ - getnameinfo \ psignal \ strerror \ strtoll \ tempnam \ ) +AC_CHECK_DECLS([getaddrinfo,getnameinfo,inet_ntop,inet_pton],,,[ +/* + * BSD requires sys/types.h, sys/socket.h, netinet/in.h, netdb.h, arpa/inet.h + * Linux requires sys/types.h, sys/socket.h, arpa/inet.h + * Windows requires sys/socket.h, winsock2.h, ws2tcpip.h + */ +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_NETINET_IN_H +#include +#endif +#if HAVE_SYS_SOCKET_H +#include +#endif +#if HAVE_NETDB_H +#include +#endif +#if HAVE_ARPA_INET_H +#include +#endif +#if HAVE_WINSOCK2_H +#include +#endif +#if HAVE_WS2TCPIP_H +#include +#endif +]) + # Magic which checks whether we are forcing a type of comm loop we # are actually going to (ab)use. # Mostly ripped from squid-commloops, thanks to adrian and benno diff --git a/helpers/negotiate_auth/kerberos/negotiate_kerberos_auth.cc b/helpers/negotiate_auth/kerberos/negotiate_kerberos_auth.cc index 58bd591cd3..bf209decf6 100644 --- a/helpers/negotiate_auth/kerberos/negotiate_kerberos_auth.cc +++ b/helpers/negotiate_auth/kerberos/negotiate_kerberos_auth.cc @@ -36,8 +36,6 @@ */ #include "squid.h" -#include "compat/getaddrinfo.h" -#include "compat/getnameinfo.h" #include "rfc1738.h" #if HAVE_GSSAPI diff --git a/helpers/negotiate_auth/kerberos/negotiate_kerberos_pac.cc b/helpers/negotiate_auth/kerberos/negotiate_kerberos_pac.cc index d084ee4a18..d5078b78eb 100644 --- a/helpers/negotiate_auth/kerberos/negotiate_kerberos_pac.cc +++ b/helpers/negotiate_auth/kerberos/negotiate_kerberos_pac.cc @@ -36,8 +36,6 @@ */ #include "squid.h" -#include "compat/getaddrinfo.h" -#include "compat/getnameinfo.h" #include "rfc1738.h" #include "negotiate_kerberos.h" diff --git a/lib/rfc3596.c b/lib/rfc3596.c index 6cae278680..5544ea3b59 100644 --- a/lib/rfc3596.c +++ b/lib/rfc3596.c @@ -7,7 +7,6 @@ */ #include "squid.h" -#include "compat/inet_pton.h" #include "util.h" #if HAVE_UNISTD_H diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 999e2db20f..9ce8f51d23 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -28,7 +28,6 @@ #include "clientStream.h" #include "comm/Connection.h" #include "comm/Write.h" -#include "compat/inet_pton.h" #include "err_detail_type.h" #include "errorpage.h" #include "fd.h" diff --git a/src/ip/Address.cc b/src/ip/Address.cc index e4bb1b2d20..1cf2d1e892 100644 --- a/src/ip/Address.cc +++ b/src/ip/Address.cc @@ -9,8 +9,6 @@ /* DEBUG: section 14 IP Storage and Handling */ #include "squid.h" -#include "compat/getaddrinfo.h" -#include "compat/inet_ntop.h" #include "Debug.h" #include "ip/Address.h" #include "ip/tools.h" diff --git a/test-suite/pconn-banger.c b/test-suite/pconn-banger.c index e0e49f1115..d3224bf7f7 100644 --- a/test-suite/pconn-banger.c +++ b/test-suite/pconn-banger.c @@ -7,7 +7,6 @@ */ #include "squid.h" -#include "compat/getaddrinfo.h" #if HAVE_UNISTD_H #include