aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_address.c
diff options
context:
space:
mode:
authorNeel Chauhan <neel@neelc.org>2018-08-16 08:19:52 -0400
committerteor <teor@torproject.org>2018-08-17 13:37:51 +1000
commit64d9ea1413e541eec36f927494fa296eb368dfaa (patch)
treef6db55fdbb4f0872306a7548e22de9813bbecbe3 /src/test/test_address.c
parentc8aecd14fecc55f5d8a48f793c24e3df68f1483c (diff)
downloadtor-64d9ea1413e541eec36f927494fa296eb368dfaa.tar.gz
tor-64d9ea1413e541eec36f927494fa296eb368dfaa.zip
In addrs_in_same_network_family(), choose IP subnet size based on IP type
Diffstat (limited to 'src/test/test_address.c')
-rw-r--r--src/test/test_address.c33
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
};