Commit 13343bc8 authored by Pekka Pessi's avatar Pekka Pessi

bnf.c: fixed host_is_local() checks.

darcs-hash:20061109163307-65a35-c024f84124c649e4593525d0bb13a588f2c95c31.gz
parent f5fb77aa
......@@ -740,15 +740,25 @@ int host_is_valid(char const *string)
*/
int host_is_local(char const *host)
{
if (host_ip6_reference(host))
size_t n;
if (host_is_ip6_reference(host))
return (strcmp(host, "[::1]") == 0);
else if (host_is_ip6_address(host))
return (strcmp(host, "::1") == 0);
else if (host_is_ip4_address(host))
return (strncmp(host, "127.", 4) == 0);
else
return (strcasecmp(host, "localhost") == 0 ||
strcasecmp(host, "localhost.localdomain") == 0);
n = span_domain(host);
return
n >= 9 /* strlen("localhost") */ &&
strncasecmp(host, "localhost", 9) == 0 &&
(n == 9 ||
((n == 10 || /* localhost. */
n == 21 || /* strlen("localhost.localdomain") */
n == 22) && /* strlen("localhost.localdomain.") */
strncasecmp(host + 9, ".localdomain.", n - 9) == 0));
}
/** Return true if @a string has domain name in "invalid." domain.
......
......@@ -295,6 +295,7 @@ int host_test(void)
TEST(host_is_local("126.0.0.0"), 0);
TEST(host_is_local("127.0.0.0"), 1);
TEST(host_is_local("127.0.0.2"), 1);
TEST(host_is_local("0.0.0.0"), 0);
TEST(host_is_local("::1"), 1);
TEST(host_is_local("::1"), 1);
......@@ -304,6 +305,9 @@ int host_test(void)
TEST(host_is_local("localhost.domain.org"), 0);
TEST(host_is_local("localhost"), 1);
TEST(host_is_local("localhost.localdomain"), 1);
TEST(host_is_local("localhost."), 1);
TEST(host_is_local("localhost.localdomain."), 1);
TEST(host_is_local("localhost.localdomain.org"), 0);
TEST(host_has_domain_invalid("invalid"), 1);
TEST(host_has_domain_invalid("invalid."), 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment