diff --git a/configure.ac b/configure.ac index 48adf01..6c73de0 100644 --- a/configure.ac +++ b/configure.ac @@ -310,8 +310,18 @@ elif test -n "$NEEDS_SOCKET" ; then elif test -n "$NEEDS_NSL" ; then LIBS="$LIBS -lnsl" else - # Needed for MinGW / Windows - AC_SEARCH_LIBS(inet_pton, ws2_32) + # Platform dependant options + case "${host_os}" in + # MinGW / Windows + *mingw*) + # Select Windows NT/2000 and later, for WSAStringToAddressW() + CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x500" + # Needed for network support + LIBS="$LIBS -lws2_32" + ;; + *) + ;; + esac fi # Check for clock_gettime() used for performance measurement diff --git a/src/psl.c b/src/psl.c index 1665293..ddfd37c 100644 --- a/src/psl.c +++ b/src/psl.c @@ -48,9 +48,6 @@ #include #ifdef _WIN32 -/* This is for Windows Vista and later, for inet_pton() */ -# define _WIN32_WINNT 0x0600 - # include # include #else @@ -1578,10 +1575,26 @@ int psl_check_version_number(int version) /* return whether hostname is an IP address or not */ static int isip(const char *hostname) { +#ifdef _WIN32 + WCHAR wName[INET6_ADDRSTRLEN+1]; + + struct sockaddr_in addr = {0}; + struct sockaddr_in6 addr6 = {0}; + + INT size = sizeof(addr); + INT size6 = sizeof(addr6); + + if (!MultiByteToWideChar(CP_UTF8, 0, hostname, -1, wName, countof(wName))) + return 0; + + return (WSAStringToAddressW(wName, AF_INET, NULL, (struct sockaddr *)&addr, &size) != SOCKET_ERROR) | + (WSAStringToAddressW(wName, AF_INET6, NULL, (struct sockaddr *)&addr6, &size6) != SOCKET_ERROR); +#else struct in_addr addr; struct in6_addr addr6; return inet_pton(AF_INET, hostname, &addr) || inet_pton(AF_INET6, hostname, &addr6); +#endif } /**