Consolidated %any(6) host_t parsing

This commit is contained in:
Martin Willi
2012-11-29 10:22:52 +01:00
parent 98d0fd25a8
commit 7277e4719e
2 changed files with 14 additions and 12 deletions
+14 -4
View File
@@ -367,13 +367,19 @@ host_t *host_create_from_string_and_family(char *string, int family,
struct sockaddr_in6 v6; struct sockaddr_in6 v6;
} addr; } 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) switch (family)
{ {
@@ -392,6 +398,10 @@ host_t *host_create_from_string_and_family(char *string, int family,
addr.sockaddr.sa_family = AF_INET6; addr.sockaddr.sa_family = AF_INET6;
return host_create_from_sockaddr(&addr.sockaddr); return host_create_from_sockaddr(&addr.sockaddr);
case AF_INET: case AF_INET:
if (strchr(string, ':'))
{ /* do not try to convert v6 addresses for v4 family */
return NULL;
}
af_inet: af_inet:
if (inet_pton(AF_INET, string, &addr.v4.sin_addr) != 1) if (inet_pton(AF_INET, string, &addr.v4.sin_addr) != 1)
{ {
@@ -234,14 +234,6 @@ METHOD(host_resolver_t, resolve, host_t*,
}; };
host_t *result; 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, ':')) if (family == AF_INET && strchr(name, ':'))
{ /* do not try to convert v6 addresses for v4 family */ { /* do not try to convert v6 addresses for v4 family */
return NULL; return NULL;