Windows: decrease minimum version to NT2000

Use WSAStringToAddressW() instead of inet_pton()

Undefine _WIN32_WINNT before (re)define it.
Fix if this macro is already declared somewhere.

Just add Winsock, no need to test anymore.

The number of characters must be used.

Use countof() macro instead

Improved fixes for Windows
This commit is contained in:
carlo-bramini 2019-01-09 15:30:50 +01:00 committed by Carlo Bramini
parent 726d6773d4
commit 7dcb69eb1d
2 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -48,9 +48,6 @@
#include <sys/stat.h>
#ifdef _WIN32
/* This is for Windows Vista and later, for inet_pton() */
# define _WIN32_WINNT 0x0600
# include <winsock2.h>
# include <ws2tcpip.h>
#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
}
/**