1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-09 04:58:16 +03:00

http: Simplify IPv6 checks

This should also enable IPv6 support on Windows. Untested and mostly
useless anyway, since we don't support HTTPS.
This commit is contained in:
Nick Wellnhofer 2022-09-05 02:02:54 +02:00
parent 9e5a016ef0
commit 30c8d9bb23
5 changed files with 13 additions and 58 deletions

View File

@ -151,7 +151,6 @@ if (NOT MSVC)
check_include_files(fcntl.h HAVE_FCNTL_H)
check_function_exists(fpclass HAVE_FPCLASS)
check_function_exists(ftime HAVE_FTIME)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
check_include_files(inttypes.h HAVE_INTTYPES_H)
check_function_exists(isascii HAVE_ISASCII)

View File

@ -25,9 +25,6 @@
/* Define to 1 if you have the `ftime' function. */
#cmakedefine HAVE_FTIME 1
/* Define if getaddrinfo is there */
#cmakedefine HAVE_GETADDRINFO 1
/* Define to 1 if you have the `gettimeofday' function. */
#cmakedefine HAVE_GETTIMEOFDAY 1

View File

@ -410,10 +410,14 @@ if test $enable_ipv6 = yes; then
#include <winsock2.h>
#else
#include <sys/socket.h>
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#endif
]], [[
struct sockaddr_storage ss;
socket(AF_INET6, SOCK_STREAM, 0)
socket(AF_INET6, SOCK_STREAM, 0);
getaddrinfo(0, 0, 0, 0);
]])],
have_ipv6=yes,
have_ipv6=no
@ -463,15 +467,6 @@ if test $enable_ipv6 = yes; then
AC_MSG_WARN(ss_family and __ss_family not found)
fi
fi
_libs=$LIBS
AC_SEARCH_LIBS([getaddrinfo], [bsd socket inet], [
if test "$ac_cv_search_getaddrinfo" != "none required"; then
NET_LIBS="$NET_LIBS $ac_cv_search_getaddrinfo"
fi
AC_DEFINE([HAVE_GETADDRINFO], [], [Define if getaddrinfo is there])],
[:], [$NET_LIBS])
LIBS=$_libs
fi
fi

View File

@ -25,7 +25,9 @@
/* Check if ws2tcpip.h is a recent version which provides getaddrinfo() */
#if defined(GetAddrInfo)
#include <wspiapi.h>
#define HAVE_GETADDRINFO
#ifndef SUPPORT_IP6
#define SUPPORT_IP6
#endif
#endif
#ifndef XML_SOCKLEN_T

View File

@ -177,20 +177,6 @@ static int socket_errno(void) {
#endif
}
#ifdef SUPPORT_IP6
static
int have_ipv6(void) {
SOCKET s;
s = socket (AF_INET6, SOCK_STREAM, 0);
if (s != INVALID_SOCKET) {
close (s);
return (1);
}
return (0);
}
#endif
/**
* xmlNanoHTTPInit:
*
@ -1021,24 +1007,19 @@ xmlNanoHTTPConnectHost(const char *host, int port)
struct sockaddr_in sockin;
#ifdef SUPPORT_IP6
struct in6_addr ia6;
struct sockaddr_in6 sockin6;
#endif
SOCKET s;
memset (&sockin, 0, sizeof(sockin));
#ifdef SUPPORT_IP6
memset (&sockin6, 0, sizeof(sockin6));
#endif
#if defined(HAVE_GETADDRINFO) && defined(SUPPORT_IP6) && !defined(_WIN32)
if (have_ipv6 ())
#endif
#if defined(HAVE_GETADDRINFO) && (defined(SUPPORT_IP6) || defined(_WIN32))
#if defined(SUPPORT_IP6)
{
int status;
struct addrinfo hints, *res, *result;
memset (&sockin6, 0, sizeof(sockin6));
result = NULL;
memset (&hints, 0,sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
@ -1059,8 +1040,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
memcpy (&sockin, res->ai_addr, res->ai_addrlen);
sockin.sin_port = htons (port);
addr = (struct sockaddr *)&sockin;
#ifdef SUPPORT_IP6
} else if (have_ipv6 () && (res->ai_family == AF_INET6)) {
} else if (res->ai_family == AF_INET6) {
if ((size_t)res->ai_addrlen > sizeof(sockin6)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
freeaddrinfo (result);
@ -1069,7 +1049,6 @@ xmlNanoHTTPConnectHost(const char *host, int port)
memcpy (&sockin6, res->ai_addr, res->ai_addrlen);
sockin6.sin6_port = htons (port);
addr = (struct sockaddr *)&sockin6;
#endif
} else
continue; /* for */
@ -1083,11 +1062,7 @@ xmlNanoHTTPConnectHost(const char *host, int port)
if (result)
freeaddrinfo (result);
}
#endif
#if defined(HAVE_GETADDRINFO) && defined(SUPPORT_IP6) && !defined(_WIN32)
else
#endif
#if !defined(HAVE_GETADDRINFO) || !defined(_WIN32)
#else
{
struct hostent *h;
struct in_addr ia;
@ -1149,19 +1124,6 @@ xmlNanoHTTPConnectHost(const char *host, int port)
sockin.sin_addr = ia;
sockin.sin_port = (unsigned short)htons ((unsigned short)port);
addr = (struct sockaddr *) &sockin;
#ifdef SUPPORT_IP6
} else if (have_ipv6 () && (h->h_addrtype == AF_INET6)) {
/* AAAA records (IPv6) */
if ((unsigned int) h->h_length > sizeof(ia6)) {
__xmlIOErr(XML_FROM_HTTP, 0, "address size mismatch\n");
return INVALID_SOCKET;
}
memcpy (&ia6, h->h_addr_list[i], h->h_length);
sockin6.sin6_family = h->h_addrtype;
sockin6.sin6_addr = ia6;
sockin6.sin6_port = htons (port);
addr = (struct sockaddr *) &sockin6;
#endif
} else
break; /* for */