unit-tests: Add a simple thread_cancel() test
[strongswan.git] / src / libstrongswan / networking / host_resolver.c
index c12becc..99a17d1 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "host_resolver.h"
 
-#include <debug.h>
 #include <library.h>
+#include <utils/debug.h>
 #include <threading/condvar.h>
 #include <threading/mutex.h>
 #include <threading/thread.h>
@@ -225,33 +225,6 @@ static void *resolve_hosts(private_host_resolver_t *this)
        return NULL;
 }
 
-/**
- * Try to convert IP addresses directly
- */
-static host_t *try_numeric_lookup(char *name, int family)
-{
-       struct addrinfo hints, *result;
-       int error;
-       host_t *host;
-
-       memset(&hints, 0, sizeof(hints));
-       hints.ai_family = family;
-       hints.ai_socktype = SOCK_DGRAM;
-       hints.ai_flags = AI_NUMERICHOST;
-
-       error = getaddrinfo(name, NULL, &hints, &result);
-       if (error != 0)
-       {       /* not an IP address */
-               return NULL;
-       }
-       else
-       {       /* result is a linked list, but we use only the first address */
-               host = host_create_from_sockaddr(result->ai_addr);
-               freeaddrinfo(result);
-       }
-       return host;
-}
-
 METHOD(host_resolver_t, resolve, host_t*,
        private_host_resolver_t *this, char *name, int family)
 {
@@ -260,23 +233,24 @@ METHOD(host_resolver_t, resolve, host_t*,
                .family = family,
        };
        host_t *result;
+       struct in_addr addr;
 
-       if (streq(name, "%any") || streq(name, "0.0.0.0"))
+       switch (family)
        {
-               return host_create_any(family ? family : AF_INET);
-       }
-       if (streq(name, "%any6") || streq(name, "::"))
-       {
-               return host_create_any(family ? family : AF_INET6);
-       }
-       if (family == AF_INET && strchr(name, ':'))
-       {       /* do not try to convert v6 addresses for v4 family */
-               return NULL;
-       }
-       result = try_numeric_lookup(name, family);
-       if (result)
-       {       /* shortcut for numeric IP addresses */
-               return result;
+               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)