diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-03-18 15:27:50 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-03-18 15:27:50 -0400 |
commit | ebb95d0f781e21a694a8de386ed0b75984b247d4 (patch) | |
tree | b60cf5c9e2ac7b5075c4cb108a71d6a618369750 /src | |
parent | c6ca199888102a825f004f8613331f97525da486 (diff) | |
parent | 165b2c0123f0ffb1f9507aaa31cdd536b91bccdf (diff) | |
download | tor-ebb95d0f781e21a694a8de386ed0b75984b247d4.tar.gz tor-ebb95d0f781e21a694a8de386ed0b75984b247d4.zip |
Merge remote-tracking branch 'public/bug8377' into maint-0.2.3
Diffstat (limited to 'src')
-rw-r--r-- | src/common/address.c | 3 | ||||
-rw-r--r-- | src/test/test_addr.c | 36 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/common/address.c b/src/common/address.c index e88869f1d8..df26f61f8f 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -779,7 +779,8 @@ tor_addr_is_loopback(const tor_addr_t *addr) case AF_INET6: { /* ::1 */ uint32_t *a32 = tor_addr_to_in6_addr32(addr); - return (a32[0] == 0) && (a32[1] == 0) && (a32[2] == 0) && (a32[3] == 1); + return (a32[0] == 0) && (a32[1] == 0) && (a32[2] == 0) && + (ntohl(a32[3]) == 1); } case AF_INET: /* 127.0.0.1 */ diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 9007a23c5c..e3f38073ec 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -623,12 +623,48 @@ test_addr_ip6_helpers(void) ; } +static void +test_addr_is_loopback(void *data) +{ + static const struct loopback_item { + const char *name; + int is_loopback; + } loopback_items[] = { + { "::1", 1 }, + { "127.0.0.1", 1 }, + { "127.99.100.101", 1 }, + { "128.99.100.101", 0 }, + { "8.8.8.8", 0 }, + { "0.0.0.0", 0 }, + { "::2", 0 }, + { "::", 0 }, + { "::1.0.0.0", 0 }, + { NULL, 0 } + }; + + int i; + tor_addr_t addr; + (void)data; + + for (i=0; loopback_items[i].name; ++i) { + tt_int_op(tor_addr_parse(&addr, loopback_items[i].name), >=, 0); + tt_int_op(tor_addr_is_loopback(&addr), ==, loopback_items[i].is_loopback); + } + + tor_addr_make_unspec(&addr); + tt_int_op(tor_addr_is_loopback(&addr), ==, 0); + + done: + ; +} + #define ADDR_LEGACY(name) \ { #name, legacy_test_helper, 0, &legacy_setup, test_addr_ ## name } struct testcase_t addr_tests[] = { ADDR_LEGACY(basic), ADDR_LEGACY(ip6_helpers), + { "is_loopback", test_addr_is_loopback, 0, NULL, NULL }, END_OF_TESTCASES }; |