Skip to content

Commit c690c99

Browse files
committed
Make windows inet_gethost work for ipv6
1 parent 07881ee commit c690c99

File tree

3 files changed

+89
-19
lines changed

3 files changed

+89
-19
lines changed

erts/autoconf/win32.config.cache.static

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ ac_cv_func_fork=${ac_cv_func_fork=no}
6161
ac_cv_func_fork_works=${ac_cv_func_fork_works=no}
6262
ac_cv_func_fpsetmask=${ac_cv_func_fpsetmask=no}
6363
ac_cv_func_fstat=${ac_cv_func_fstat=yes}
64-
ac_cv_func_getaddrinfo=${ac_cv_func_getaddrinfo=no}
6564
ac_cv_func_gethostbyaddr=${ac_cv_func_gethostbyaddr=no}
6665
ac_cv_func_gethostbyaddr_r=${ac_cv_func_gethostbyaddr_r=no}
6766
ac_cv_func_gethostbyname=${ac_cv_func_gethostbyname=no}
@@ -71,7 +70,6 @@ ac_cv_func_gethostname=${ac_cv_func_gethostname=no}
7170
ac_cv_func_gethrtime=${ac_cv_func_gethrtime=no}
7271
ac_cv_func_getipnodebyaddr=${ac_cv_func_getipnodebyaddr=no}
7372
ac_cv_func_getipnodebyname=${ac_cv_func_getipnodebyname=no}
74-
ac_cv_func_getnameinfo=${ac_cv_func_getnameinfo=no}
7573
ac_cv_func_getpagesize=${ac_cv_func_getpagesize=no}
7674
ac_cv_func_gettimeofday=${ac_cv_func_gettimeofday=no}
7775
ac_cv_func_gmtime_r=${ac_cv_func_gmtime_r=no}

erts/configure.in

+85-15
Original file line numberDiff line numberDiff line change
@@ -1679,18 +1679,66 @@ LIBS="$LIBS $EMU_THR_X_LIBS"
16791679

16801680
dnl Check if we have these, in which case we'll try to build
16811681
dnl inet_gethost with ipv6 support.
1682-
AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes, have_getaddrinfo=no)
1682+
AC_CHECK_HEADERS(windows.h)
1683+
AC_CHECK_HEADERS(winsock2.h)
1684+
AC_CHECK_HEADERS(ws2tcpip.h,[],[],[
1685+
#ifdef HAVE_WINSOCK2_H
1686+
#include <winsock2.h>
1687+
#endif
1688+
#ifdef HAVE_WINDOWS_H
1689+
#include <windows.h>
1690+
#endif
1691+
])
1692+
dnl AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes, have_getaddrinfo=no)
1693+
AC_MSG_CHECKING(for getaddrinfo)
1694+
AC_TRY_LINK([
1695+
#include <stdlib.h>
1696+
#include <string.h>
1697+
#ifdef HAVE_WINSOCK2_H
1698+
#include <winsock2.h>
1699+
#endif
1700+
#ifdef HAVE_WINDOWS_H
1701+
#include <windows.h>
1702+
#endif
1703+
#ifdef HAVE_WS2TCPIP_H
1704+
#include <ws2tcpip.h>
1705+
#endif
1706+
#ifndef __WIN32__
1707+
#include <sys/socket.h>
1708+
#include <netdb.h>
1709+
#endif
1710+
],
1711+
[
1712+
getaddrinfo("","",NULL,NULL);
1713+
],have_getaddrinfo=yes, have_getaddrinfo=no)
16831714
if test $have_getaddrinfo = yes; then
1715+
AC_MSG_RESULT([yes])
16841716
AC_MSG_CHECKING([whether getaddrinfo accepts enough flags])
1685-
AC_TRY_RUN([
1717+
AC_TRY_COMPILE([
16861718
#include <stdlib.h>
16871719
#include <string.h>
1720+
#ifdef HAVE_WINSOCK2_H
1721+
#include <winsock2.h>
1722+
#endif
1723+
#ifdef HAVE_WINDOWS_H
1724+
#include <windows.h>
1725+
#endif
1726+
#ifdef HAVE_WS2TCPIP_H
1727+
#include <ws2tcpip.h>
1728+
#endif
1729+
#ifndef __WIN32__
16881730
#include <sys/socket.h>
16891731
#include <netdb.h>
1690-
int main(int argc, char **argv) {
1732+
#endif
1733+
],
1734+
[
16911735
struct addrinfo hints, *ai;
16921736
memset(&hints, 0, sizeof(hints));
1737+
#ifndef __WIN32__
16931738
hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG);
1739+
#else
1740+
hints.ai_flags = AI_CANONNAME;
1741+
#endif
16941742
hints.ai_socktype = SOCK_STREAM;
16951743
hints.ai_family = AF_INET6;
16961744
if (getaddrinfo("::", NULL, &hints, &ai) == 0) {
@@ -1699,26 +1747,48 @@ int main(int argc, char **argv) {
16991747
} else {
17001748
exit(1);
17011749
}
1702-
}
1703-
],, have_getaddrinfo=no,
1704-
[
1705-
case X$erl_xcomp_getaddrinfo in
1706-
X) have_getaddrinfo=cross;;
1707-
Xyes|Xno) have_getaddrinfo=$erl_xcomp_getaddrinfo;;
1708-
*) AC_MSG_ERROR([Bad erl_xcomp_getaddrinfo value: $erl_xcomp_getaddrinfo]);;
1709-
esac
1710-
])
1750+
],, have_getaddrinfo=no)
17111751
AC_MSG_RESULT($have_getaddrinfo)
17121752
case $have_getaddrinfo in
17131753
yes)
17141754
AC_DEFINE(HAVE_GETADDRINFO, [1],
17151755
[Define to 1 if you have a good `getaddrinfo' function.]);;
1716-
cross)
1717-
AC_MSG_WARN([result no guessed because of cross compilation]);;
17181756
*) ;;
17191757
esac
1758+
else
1759+
AC_MSG_RESULT([no])
17201760
fi
1721-
AC_CHECK_FUNCS([getnameinfo getipnodebyname getipnodebyaddr gethostbyname2])
1761+
AC_MSG_CHECKING(for getnameinfo)
1762+
AC_TRY_LINK([
1763+
#include <stdlib.h>
1764+
#include <string.h>
1765+
#ifdef HAVE_WINSOCK2_H
1766+
#include <winsock2.h>
1767+
#endif
1768+
#ifdef HAVE_WINDOWS_H
1769+
#include <windows.h>
1770+
#endif
1771+
#ifdef HAVE_WS2TCPIP_H
1772+
#include <ws2tcpip.h>
1773+
#endif
1774+
#ifndef __WIN32__
1775+
#include <sys/socket.h>
1776+
#include <netdb.h>
1777+
#endif
1778+
],
1779+
[
1780+
getnameinfo(NULL,0,NULL,0,NULL,0,0);
1781+
],have_getnameinfo=yes, have_getnameinfo=no)
1782+
if test $have_getnameinfo = yes; then
1783+
AC_MSG_RESULT([yes])
1784+
AC_DEFINE(HAVE_GETNAMEINFO, [1],
1785+
[Define to 1 if you have a good `getnameinfo' function.])
1786+
else
1787+
AC_MSG_RESULT([no])
1788+
fi
1789+
1790+
1791+
AC_CHECK_FUNCS([getipnodebyname getipnodebyaddr gethostbyname2])
17221792

17231793
AC_CHECK_FUNCS([ieee_handler fpsetmask finite isnan isinf res_gethostbyname dlopen \
17241794
pread pwrite writev memmove strerror strerror_r strncasecmp \

erts/etc/common/inet_gethost.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@
6565
#include <stdlib.h>
6666

6767
/* These are not used even if they would exist which they should not */
68-
#undef HAVE_GETADDRINFO
6968
#undef HAVE_GETIPNODEBYNAME
7069
#undef HAVE_GETHOSTBYNAME2
71-
#undef HAVE_GETNAMEINFO
7270
#undef HAVE_GETIPNODEBYADDR
7371

7472
#else /* Unix */
@@ -1762,7 +1760,11 @@ static int worker_loop(void)
17621760
struct addrinfo hints;
17631761

17641762
memset(&hints, 0, sizeof(hints));
1763+
#ifdef __WIN32__
1764+
hints.ai_flags = (AI_CANONNAME);
1765+
#else
17651766
hints.ai_flags = (AI_CANONNAME|AI_V4MAPPED|AI_ADDRCONFIG);
1767+
#endif
17661768
hints.ai_socktype = SOCK_STREAM;
17671769
hints.ai_family = AF_INET6;
17681770
DEBUGF(5, ("Starting getaddrinfo(%s, ...)", data));

0 commit comments

Comments
 (0)