From c690c99dd434934a09f38b57d7598c8ecd1231eb Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Wed, 1 Dec 2010 12:08:43 +0100 Subject: Make windows inet_gethost work for ipv6 --- erts/autoconf/win32.config.cache.static | 2 - erts/configure.in | 100 +++++++++++++++++++++++++++----- erts/etc/common/inet_gethost.c | 6 +- 3 files changed, 89 insertions(+), 19 deletions(-) (limited to 'erts') diff --git a/erts/autoconf/win32.config.cache.static b/erts/autoconf/win32.config.cache.static index cc33fc09b3..d25b1df9d9 100755 --- a/erts/autoconf/win32.config.cache.static +++ b/erts/autoconf/win32.config.cache.static @@ -61,7 +61,6 @@ ac_cv_func_fork=${ac_cv_func_fork=no} ac_cv_func_fork_works=${ac_cv_func_fork_works=no} ac_cv_func_fpsetmask=${ac_cv_func_fpsetmask=no} ac_cv_func_fstat=${ac_cv_func_fstat=yes} -ac_cv_func_getaddrinfo=${ac_cv_func_getaddrinfo=no} ac_cv_func_gethostbyaddr=${ac_cv_func_gethostbyaddr=no} ac_cv_func_gethostbyaddr_r=${ac_cv_func_gethostbyaddr_r=no} ac_cv_func_gethostbyname=${ac_cv_func_gethostbyname=no} @@ -71,7 +70,6 @@ ac_cv_func_gethostname=${ac_cv_func_gethostname=no} ac_cv_func_gethrtime=${ac_cv_func_gethrtime=no} ac_cv_func_getipnodebyaddr=${ac_cv_func_getipnodebyaddr=no} ac_cv_func_getipnodebyname=${ac_cv_func_getipnodebyname=no} -ac_cv_func_getnameinfo=${ac_cv_func_getnameinfo=no} ac_cv_func_getpagesize=${ac_cv_func_getpagesize=no} ac_cv_func_gettimeofday=${ac_cv_func_gettimeofday=no} ac_cv_func_gmtime_r=${ac_cv_func_gmtime_r=no} diff --git a/erts/configure.in b/erts/configure.in index 8d629c25ae..544ff9790a 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -1679,18 +1679,66 @@ LIBS="$LIBS $EMU_THR_X_LIBS" dnl Check if we have these, in which case we'll try to build dnl inet_gethost with ipv6 support. -AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes, have_getaddrinfo=no) +AC_CHECK_HEADERS(windows.h) +AC_CHECK_HEADERS(winsock2.h) +AC_CHECK_HEADERS(ws2tcpip.h,[],[],[ +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WINDOWS_H +#include +#endif +]) +dnl AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes, have_getaddrinfo=no) +AC_MSG_CHECKING(for getaddrinfo) +AC_TRY_LINK([ +#include +#include +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WINDOWS_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#ifndef __WIN32__ +#include +#include +#endif +], +[ +getaddrinfo("","",NULL,NULL); +],have_getaddrinfo=yes, have_getaddrinfo=no) if test $have_getaddrinfo = yes; then + AC_MSG_RESULT([yes]) AC_MSG_CHECKING([whether getaddrinfo accepts enough flags]) - AC_TRY_RUN([ + AC_TRY_COMPILE([ #include #include +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WINDOWS_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#ifndef __WIN32__ #include #include -int main(int argc, char **argv) { +#endif +], +[ struct addrinfo hints, *ai; memset(&hints, 0, sizeof(hints)); +#ifndef __WIN32__ hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG); +#else + hints.ai_flags = AI_CANONNAME; +#endif hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET6; if (getaddrinfo("::", NULL, &hints, &ai) == 0) { @@ -1699,26 +1747,48 @@ int main(int argc, char **argv) { } else { exit(1); } -} - ],, have_getaddrinfo=no, - [ - case X$erl_xcomp_getaddrinfo in - X) have_getaddrinfo=cross;; - Xyes|Xno) have_getaddrinfo=$erl_xcomp_getaddrinfo;; - *) AC_MSG_ERROR([Bad erl_xcomp_getaddrinfo value: $erl_xcomp_getaddrinfo]);; - esac - ]) +],, have_getaddrinfo=no) AC_MSG_RESULT($have_getaddrinfo) case $have_getaddrinfo in yes) AC_DEFINE(HAVE_GETADDRINFO, [1], [Define to 1 if you have a good `getaddrinfo' function.]);; - cross) - AC_MSG_WARN([result no guessed because of cross compilation]);; *) ;; esac +else + AC_MSG_RESULT([no]) fi -AC_CHECK_FUNCS([getnameinfo getipnodebyname getipnodebyaddr gethostbyname2]) +AC_MSG_CHECKING(for getnameinfo) +AC_TRY_LINK([ +#include +#include +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WINDOWS_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#ifndef __WIN32__ +#include +#include +#endif +], +[ +getnameinfo(NULL,0,NULL,0,NULL,0,0); +],have_getnameinfo=yes, have_getnameinfo=no) +if test $have_getnameinfo = yes; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_GETNAMEINFO, [1], + [Define to 1 if you have a good `getnameinfo' function.]) +else + AC_MSG_RESULT([no]) +fi + + +AC_CHECK_FUNCS([getipnodebyname getipnodebyaddr gethostbyname2]) AC_CHECK_FUNCS([ieee_handler fpsetmask finite isnan isinf res_gethostbyname dlopen \ pread pwrite writev memmove strerror strerror_r strncasecmp \ diff --git a/erts/etc/common/inet_gethost.c b/erts/etc/common/inet_gethost.c index e095836258..ab24ac1048 100644 --- a/erts/etc/common/inet_gethost.c +++ b/erts/etc/common/inet_gethost.c @@ -65,10 +65,8 @@ #include /* These are not used even if they would exist which they should not */ -#undef HAVE_GETADDRINFO #undef HAVE_GETIPNODEBYNAME #undef HAVE_GETHOSTBYNAME2 -#undef HAVE_GETNAMEINFO #undef HAVE_GETIPNODEBYADDR #else /* Unix */ @@ -1762,7 +1760,11 @@ static int worker_loop(void) struct addrinfo hints; memset(&hints, 0, sizeof(hints)); +#ifdef __WIN32__ + hints.ai_flags = (AI_CANONNAME); +#else hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG); +#endif hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET6; DEBUGF(5, ("Starting getaddrinfo(%s, ...)", data)); -- cgit v1.2.3 From 0d79832e450c49e51f5fd7149f5f72930ef1f966 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Thu, 2 Dec 2010 16:49:19 +0100 Subject: Stop using uncertain flags for getaddrinfo() The AI_V4MAPPED flag is falling out of grace in modern IPv6 stacks, for security reasons, e.g. FreeBSD do not document it any longer. The AI_ADDRCONFIG flag have got unclear semantics on the same OS. --- erts/configure.in | 4 ---- erts/emulator/drivers/common/inet_drv.c | 5 ++++- erts/etc/common/inet_gethost.c | 6 +----- 3 files changed, 5 insertions(+), 10 deletions(-) (limited to 'erts') diff --git a/erts/configure.in b/erts/configure.in index 544ff9790a..f99a86a899 100644 --- a/erts/configure.in +++ b/erts/configure.in @@ -1734,11 +1734,7 @@ if test $have_getaddrinfo = yes; then [ struct addrinfo hints, *ai; memset(&hints, 0, sizeof(hints)); -#ifndef __WIN32__ - hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG); -#else hints.ai_flags = AI_CANONNAME; -#endif hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET6; if (getaddrinfo("::", NULL, &hints, &ai) == 0) { diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c index 18f7cdd15a..6f318e4dfc 100644 --- a/erts/emulator/drivers/common/inet_drv.c +++ b/erts/emulator/drivers/common/inet_drv.c @@ -5811,8 +5811,11 @@ static int sctp_set_opts(inet_descriptor* desc, char* ptr, int len) char *after; # ifdef HAVE_STRUCT_SCTP_PADDRPARAMS_SPP_FLAGS int eflags, cflags, hb_enable, hb_disable, - pmtud_enable, pmtud_disable, + pmtud_enable, pmtud_disable; +# ifdef HAVE_STRUCT_SCTP_PADDRPARAMS_SPP_SACKDELAY + int sackdelay_enable, sackdelay_disable; +# endif # endif CHKLEN(curr, ASSOC_ID_LEN); diff --git a/erts/etc/common/inet_gethost.c b/erts/etc/common/inet_gethost.c index ab24ac1048..8bd9368aa1 100644 --- a/erts/etc/common/inet_gethost.c +++ b/erts/etc/common/inet_gethost.c @@ -1760,11 +1760,7 @@ static int worker_loop(void) struct addrinfo hints; memset(&hints, 0, sizeof(hints)); -#ifdef __WIN32__ - hints.ai_flags = (AI_CANONNAME); -#else - hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG); -#endif + hints.ai_flags = AI_CANONNAME; hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET6; DEBUGF(5, ("Starting getaddrinfo(%s, ...)", data)); -- cgit v1.2.3