Browse Source

rm ENABLE_IPV6

ithewei 3 years ago
parent
commit
0ec0480111
6 changed files with 10 additions and 31 deletions
  1. 0 5
      CMakeLists.txt
  2. 0 4
      Makefile.in
  3. 9 17
      base/hsocket.c
  4. 0 2
      config.ini
  5. 1 2
      config.mk
  6. 0 1
      configure

+ 0 - 5
CMakeLists.txt

@@ -17,7 +17,6 @@ option(WITH_HTTP_SERVER "compile http/server" ON)
 option(WITH_HTTP_CLIENT "compile http/client" ON)
 option(WITH_MQTT "compile mqtt" OFF)
 
-option(ENABLE_IPV6 "ipv6" ON)
 option(ENABLE_UDS "Unix Domain Socket" OFF)
 option(USE_MULTIMAP "MultiMap" OFF)
 
@@ -101,10 +100,6 @@ else()
     add_definitions(-DNDEBUG)
 endif()
 
-if(ENABLE_IPV6)
-    add_definitions(-DENABLE_IPV6)
-endif()
-
 if(ENABLE_UDS)
     add_definitions(-DENABLE_UDS)
 endif()

+ 0 - 4
Makefile.in

@@ -129,10 +129,6 @@ else
 	CPPFLAGS += -DNDEBUG
 endif
 
-ifeq ($(ENABLE_IPV6), yes)
-	CPPFLAGS += -DENABLE_IPV6
-endif
-
 ifeq ($(ENABLE_UDS), yes)
 	CPPFLAGS += -DENABLE_UDS
 endif

+ 9 - 17
base/hsocket.c

@@ -59,32 +59,24 @@ int ResolveAddr(const char* host, sockaddr_u* addr) {
         return 0;
     }
 
-#ifdef ENABLE_IPV6
     if (inet_pton(AF_INET6, host, &addr->sin6.sin6_addr) == 1) {
         addr->sa.sa_family = AF_INET6; // host is ipv6
     }
+
     struct addrinfo* ais = NULL;
-    struct addrinfo hint;
-    hint.ai_flags = 0;
-    hint.ai_family = AF_UNSPEC;
-    hint.ai_socktype = 0;
-    hint.ai_protocol = 0;
     int ret = getaddrinfo(host, NULL, NULL, &ais);
-    if (ret != 0 || ais == NULL || ais->ai_addrlen == 0 || ais->ai_addr == NULL) {
+    if (ret != 0 || ais == NULL || ais->ai_addr == NULL || ais->ai_addrlen == 0) {
         printd("unknown host: %s err:%d:%s\n", host, ret, gai_strerror(ret));
         return ret;
     }
-    memcpy(addr, ais->ai_addr, ais->ai_addrlen);
-    freeaddrinfo(ais);
-#else
-    struct hostent* phe = gethostbyname(host);
-    if (phe == NULL) {
-        printd("unknown host %s err:%d\n", host, h_errno);
-        return -h_errno;
+    struct addrinfo* pai = ais;
+    while (pai != NULL) {
+        if (pai->ai_family == AF_INET) break;
+        pai = pai->ai_next;
     }
-    addr->sin.sin_family = AF_INET;
-    memcpy(&addr->sin.sin_addr, phe->h_addr_list[0], phe->h_length);
-#endif
+    if (pai == NULL) pai = ais;
+    memcpy(addr, pai->ai_addr, pai->ai_addrlen);
+    freeaddrinfo(ais);
     return 0;
 }
 

+ 0 - 2
config.ini

@@ -16,8 +16,6 @@ WITH_HTTP_CLIENT=yes
 WITH_MQTT=no
 
 # features
-# base/hsocket.c: replace gethostbyname with getaddrinfo
-ENABLE_IPV6=yes
 # base/hsocket.h: Unix Domain Socket
 ENABLE_UDS=no
 # base/RAII.cpp: Windows MiniDumpWriteDump

+ 1 - 2
config.mk

@@ -8,7 +8,6 @@ WITH_HTTP=yes
 WITH_HTTP_SERVER=yes
 WITH_HTTP_CLIENT=yes
 WITH_MQTT=no
-ENABLE_IPV6=yes
 ENABLE_UDS=no
 ENABLE_WINDUMP=no
 USE_MULTIMAP=no
@@ -18,4 +17,4 @@ WITH_OPENSSL=no
 WITH_GNUTLS=no
 WITH_MBEDTLS=no
 WITH_KCP=no
-CONFIG_DATE=20220224
+CONFIG_DATE=20220224

+ 0 - 1
configure

@@ -26,7 +26,6 @@ modules:
   --with-mqtt           compile mqtt module?            (DEFAULT: $WITH_MQTT)
 
 features:
-  --enable-ipv6         enable IPv6?                    (DEFAULT: $ENABLE_IPV6)
   --enable-uds          enable Unix Domain Socket?      (DEFAULT: $ENABLE_UDS)
   --enable-windump      enable Windows coredump?        (DEFAULT: $ENABLE_WINDUMP)