diff options
Diffstat (limited to 'src/test/test_address.c')
-rw-r--r-- | src/test/test_address.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/test_address.c b/src/test/test_address.c index abe7c2c0ad..7e2ccc1b5a 100644 --- a/src/test/test_address.c +++ b/src/test/test_address.c @@ -24,6 +24,8 @@ #endif /* defined(HAVE_IFCONF_TO_SMARTLIST) */ #include "core/or/or.h" +#include "feature/nodelist/nodelist.h" +#include "lib/net/address.h" #include "lib/net/address.h" #include "test/test.h" #include "test/log_test_helpers.h" @@ -1139,6 +1141,36 @@ test_address_tor_addr_eq_ipv4h(void *ignored) tor_free(a); } +static void +test_address_tor_addr_in_same_network_family(void *ignored) +{ + (void)ignored; + tor_addr_t a, b; + + tor_addr_parse(&a, "8.8.8.8"); + tor_addr_parse(&b, "8.8.4.4"); + tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 1); + + tor_addr_parse(&a, "8.8.8.8"); + tor_addr_parse(&b, "1.1.1.1"); + tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0); + + tor_addr_parse(&a, "8.8.8.8"); + tor_addr_parse(&b, "2001:4860:4860::8844"); + tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0); + + tor_addr_parse(&a, "2001:4860:4860::8888"); + tor_addr_parse(&b, "2001:4860:4860::8844"); + tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 1); + + tor_addr_parse(&a, "2001:4860:4860::8888"); + tor_addr_parse(&b, "2001:470:20::2"); + tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0); + + done: + return; +} + #define ADDRESS_TEST(name, flags) \ { #name, test_address_ ## name, flags, NULL, NULL } @@ -1170,6 +1202,7 @@ struct testcase_t address_tests[] = { ADDRESS_TEST(tor_addr_to_ipv4n, 0), ADDRESS_TEST(tor_addr_to_mapped_ipv4h, 0), ADDRESS_TEST(tor_addr_eq_ipv4h, 0), + ADDRESS_TEST(tor_addr_in_same_network_family, 0), END_OF_TESTCASES }; |