[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Merge remote-tracking branch 'origin/maint-0.2.4'
commit a88f3e24eaf2180ac2f374df81b0261661774c5f
Merge: 6770939 2ac66e5
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon Mar 18 15:29:32 2013 -0400
Merge remote-tracking branch 'origin/maint-0.2.4'
Conflicts:
src/test/test_addr.c
changes/bug8377 | 3 +++
src/common/address.c | 3 ++-
src/test/test_addr.c | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 1 deletions(-)
diff --cc src/test/test_addr.c
index f182bca,fec85a4..106f921
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@@ -853,90 -844,40 +853,125 @@@ test_virtaddrmap(void *data
}
static void
+test_addr_localname(void *arg)
+{
+ (void)arg;
+ tt_assert(tor_addr_hostname_is_local("localhost"));
+ tt_assert(tor_addr_hostname_is_local("LOCALHOST"));
+ tt_assert(tor_addr_hostname_is_local("LocalHost"));
+ tt_assert(tor_addr_hostname_is_local("local"));
+ tt_assert(tor_addr_hostname_is_local("LOCAL"));
+ tt_assert(tor_addr_hostname_is_local("here.now.local"));
+ tt_assert(tor_addr_hostname_is_local("here.now.LOCAL"));
+
+
+ tt_assert(!tor_addr_hostname_is_local(" localhost"));
+ tt_assert(!tor_addr_hostname_is_local("www.torproject.org"));
+ done:
+ ;
+}
+
+static void
+test_addr_dup_ip(void *arg)
+{
+ char *v = NULL;
+ (void)arg;
+#define CHECK(ip, s) do { \
+ v = tor_dup_ip(ip); \
+ tt_str_op(v,==,(s)); \
+ tor_free(v); \
+ } while (0)
+
+ CHECK(0xffffffff, "255.255.255.255");
+ CHECK(0x00000000, "0.0.0.0");
+ CHECK(0x7f000001, "127.0.0.1");
+ CHECK(0x01020304, "1.2.3.4");
+
+#undef CHECK
+ done:
+ tor_free(v);
+}
+
+static void
+test_addr_sockaddr_to_str(void *arg)
+{
+ char *v = NULL;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+ struct sockaddr_storage ss;
+#ifdef HAVE_SYS_UN_H
+ struct sockaddr_un sun;
+#endif
+#define CHECK(sa, s) do { \
+ v = tor_sockaddr_to_str((const struct sockaddr*) &(sa)); \
+ tt_str_op(v,==,(s)); \
+ tor_free(v); \
+ } while (0)
+ (void)arg;
+
+ memset(&ss,0,sizeof(ss));
+ ss.ss_family = AF_UNSPEC;
+ CHECK(ss, "unspec");
+
+ memset(&sin,0,sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = htonl(0x7f808001);
+ sin.sin_port = htons(1234);
+ CHECK(sin, "127.128.128.1:1234");
+
+#ifdef HAVE_SYS_UN_H
+ memset(&sun,0,sizeof(sun));
+ sun.sun_family = AF_UNIX;
+ strlcpy(sun.sun_path, "/here/is/a/path", sizeof(sun.sun_path));
+ CHECK(sun, "unix:/here/is/a/path");
+#endif
+
+ memset(&sin6,0,sizeof(sin6));
+ sin6.sin6_family = AF_INET6;
+ memcpy(sin6.sin6_addr.s6_addr, "\x20\x00\x00\x00\x00\x00\x00\x00"
+ "\x00\x1a\x2b\x3c\x4d\x5e\x00\x01", 16);
+ sin6.sin6_port = htons(1234);
+ CHECK(sin6, "[2000::1a:2b3c:4d5e:1]:1234");
+
+ done:
+ tor_free(v);
+}
+
++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 }
@@@ -945,9 -886,7 +980,10 @@@ struct testcase_t addr_tests[] =
ADDR_LEGACY(ip6_helpers),
ADDR_LEGACY(parse),
{ "virtaddr", test_virtaddrmap, 0, NULL, NULL },
+ { "localname", test_addr_localname, 0, NULL, NULL },
+ { "dup_ip", test_addr_dup_ip, 0, NULL, NULL },
+ { "sockaddr_to_str", test_addr_sockaddr_to_str, 0, NULL, NULL },
+ { "is_loopback", test_addr_is_loopback, 0, NULL, NULL },
END_OF_TESTCASES
};
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits