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:
parent
726d6773d4
commit
7dcb69eb1d
14
configure.ac
14
configure.ac
|
@ -310,8 +310,18 @@ elif test -n "$NEEDS_SOCKET" ; then
|
||||||
elif test -n "$NEEDS_NSL" ; then
|
elif test -n "$NEEDS_NSL" ; then
|
||||||
LIBS="$LIBS -lnsl"
|
LIBS="$LIBS -lnsl"
|
||||||
else
|
else
|
||||||
# Needed for MinGW / Windows
|
# Platform dependant options
|
||||||
AC_SEARCH_LIBS(inet_pton, ws2_32)
|
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
|
fi
|
||||||
|
|
||||||
# Check for clock_gettime() used for performance measurement
|
# Check for clock_gettime() used for performance measurement
|
||||||
|
|
19
src/psl.c
19
src/psl.c
|
@ -48,9 +48,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* This is for Windows Vista and later, for inet_pton() */
|
|
||||||
# define _WIN32_WINNT 0x0600
|
|
||||||
|
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
# include <ws2tcpip.h>
|
# include <ws2tcpip.h>
|
||||||
#else
|
#else
|
||||||
|
@ -1578,10 +1575,26 @@ int psl_check_version_number(int version)
|
||||||
/* return whether hostname is an IP address or not */
|
/* return whether hostname is an IP address or not */
|
||||||
static int isip(const char *hostname)
|
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 in_addr addr;
|
||||||
struct in6_addr addr6;
|
struct in6_addr addr6;
|
||||||
|
|
||||||
return inet_pton(AF_INET, hostname, &addr) || inet_pton(AF_INET6, hostname, &addr6);
|
return inet_pton(AF_INET, hostname, &addr) || inet_pton(AF_INET6, hostname, &addr6);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue