host-resolver: don't try to resolve a plain v4 address to an IPv6 address
authorVolker RĂ¼melin <vr_strongswan@t-online.de>
Sun, 21 Apr 2013 13:10:39 +0000 (15:10 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 16 May 2013 09:03:37 +0000 (11:03 +0200)
Suppress 'Address family for hostname not supported' errors if a IPv6
client connects in a mixed IPv4/IPv6 environment.

src/libstrongswan/networking/host_resolver.c

index 5e244f1..99a17d1 100644 (file)
@@ -233,10 +233,24 @@ METHOD(host_resolver_t, resolve, host_t*,
                .family = family,
        };
        host_t *result;
+       struct in_addr addr;
 
-       if (family == AF_INET && strchr(name, ':'))
-       {       /* do not try to convert v6 addresses for v4 family */
-               return NULL;
+       switch (family)
+       {
+               case AF_INET:
+                       /* do not try to convert v6 addresses for v4 family */
+                       if (strchr(name, ':'))
+                       {
+                               return NULL;
+                       }
+                       break;
+               case AF_INET6:
+                       /* do not try to convert v4 addresses for v6 family */
+                       if (inet_pton(AF_INET, name, &addr) == 1)
+                       {
+                               return NULL;
+                       }
+                       break;
        }
        this->mutex->lock(this->mutex);
        if (this->disabled)