Merge pull request #124 from carlo-bramini/fix-older-windows

Fix older windows
This commit is contained in:
Tim Rühsen 2019-03-26 12:55:25 +01:00 committed by GitHub
commit 19359c6733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}
/**