[libxml2] http: Simplify IPv6 checks



commit 30c8d9bb235d84f94b899855b7a38563801feb9b
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Mon Sep 5 02:02:54 2022 +0200

    http: Simplify IPv6 checks
    
    This should also enable IPv6 support on Windows. Untested and mostly
    useless anyway, since we don't support HTTPS.

 CMakeLists.txt        |  1 -
 config.h.cmake.in     |  3 ---
 configure.ac          | 15 +++++----------
 include/wsockcompat.h |  4 +++-
 nanohttp.c            | 48 +++++-------------------------------------------
 5 files changed, 13 insertions(+), 58 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f467efe..9eefa206 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/config.h.cmake.in b/config.h.cmake.in
index 3ff1f42a..15a7bce4 100644
--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -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
 
diff --git a/configure.ac b/configure.ac
index eb03a83c..410c22df 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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 
 
diff --git a/include/wsockcompat.h b/include/wsockcompat.h
index b3c97165..141de0c6 100644
--- a/include/wsockcompat.h
+++ b/include/wsockcompat.h
@@ -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
diff --git a/nanohttp.c b/nanohttp.c
index 379f6b40..0678b730 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -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 */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]