Consolidated %any(6) host_t parsing
authorMartin Willi <martin@revosec.ch>
Mon, 12 Nov 2012 14:58:39 +0000 (15:58 +0100)
committerMartin Willi <martin@revosec.ch>
Thu, 29 Nov 2012 09:22:52 +0000 (10:22 +0100)
src/libstrongswan/networking/host.c
src/libstrongswan/networking/host_resolver.c

index 3270f0c..ef5c7c0 100644 (file)
@@ -367,13 +367,19 @@ host_t *host_create_from_string_and_family(char *string, int family,
                struct sockaddr_in6 v6;
        } addr;
 
-       if ((family == AF_UNSPEC || family == AF_INET) && streq(string, "%any"))
+       if (family == AF_UNSPEC || family == AF_INET)
        {
-               return host_create_any_port(AF_INET, port);
+               if (streq(string, "%any") || streq(string, "0.0.0.0"))
+               {
+                       return host_create_any_port(AF_INET, port);
+               }
        }
-       if ((family == AF_UNSPEC || family == AF_INET6) && streq(string, "%any6"))
+       if (family == AF_UNSPEC || family == AF_INET6)
        {
-               return host_create_any_port(AF_INET6, port);
+               if (streq(string, "%any6") || streq(string, "::"))
+               {
+                       return host_create_any_port(AF_INET6, port);
+               }
        }
        switch (family)
        {
@@ -392,6 +398,10 @@ host_t *host_create_from_string_and_family(char *string, int family,
                        addr.sockaddr.sa_family = AF_INET6;
                        return host_create_from_sockaddr(&addr.sockaddr);
                case AF_INET:
+                       if (strchr(string, ':'))
+                       {       /* do not try to convert v6 addresses for v4 family */
+                               return NULL;
+                       }
                af_inet:
                        if (inet_pton(AF_INET, string, &addr.v4.sin_addr) != 1)
                        {
index 71aa0b1..5e244f1 100644 (file)
@@ -234,14 +234,6 @@ METHOD(host_resolver_t, resolve, host_t*,
        };
        host_t *result;
 
-       if (streq(name, "%any") || streq(name, "0.0.0.0"))
-       {
-               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;