ipv6: always try to convert as a numeric address first
authorAndrew Tridgell <tridge@samba.org>
Thu, 2 Jun 2011 07:10:17 +0000 (17:10 +1000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 6 Jun 2011 02:26:10 +0000 (12:26 +1000)
This avoids unnecessary name lookups, plus it fixes a problem with
using interpret_string_addr*() with the wildcard IPv6 address

lib/util/util_net.c

index 98eef3bd8bc3f1f1e310a25110d0826b4ef760d3..57a0b1e40c32b5ab64f331dacca789558ced01fe 100644 (file)
@@ -54,6 +54,15 @@ bool interpret_string_addr_internal(struct addrinfo **ppres,
 
        /* By default make sure it supports TCP. */
        hints.ai_socktype = SOCK_STREAM;
+
+       /* always try as a numeric host first. This prevents unnecessary name
+        * lookups, and also ensures we accept IPv6 addresses */
+       hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
+       ret = getaddrinfo(str, NULL, &hints, ppres);
+       if (ret == 0) {
+               return true;
+       }
+
        hints.ai_flags = flags;
 
        /* Linux man page on getaddrinfo() says port will be