|
@@ -53,9 +53,17 @@ test_addr_basic(void)
|
|
|
char tmpbuf[TOR_ADDR_BUF_LEN];
|
|
|
const char *ip = "176.192.208.224";
|
|
|
struct in_addr in;
|
|
|
- tor_inet_pton(AF_INET, ip, &in);
|
|
|
- tor_inet_ntop(AF_INET, &in, tmpbuf, sizeof(tmpbuf));
|
|
|
+
|
|
|
+
|
|
|
+ test_eq(tor_inet_pton(AF_INET, ip, &in), 1);
|
|
|
+ test_eq_ptr(tor_inet_ntop(AF_INET, &in, tmpbuf, sizeof(tmpbuf)), &tmpbuf);
|
|
|
test_streq(tmpbuf, ip);
|
|
|
+
|
|
|
+
|
|
|
+ test_streq(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip) + 1), ip);
|
|
|
+
|
|
|
+
|
|
|
+ test_eq_ptr(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip)), NULL);
|
|
|
}
|
|
|
|
|
|
done:
|
|
@@ -179,6 +187,29 @@ test_addr_ip6_helpers(void)
|
|
|
|
|
|
|
|
|
|
|
|
+ {
|
|
|
+ const char *ip = "2001::1234";
|
|
|
+ const char *ip_ffff = "::ffff:192.168.1.2";
|
|
|
+
|
|
|
+
|
|
|
+ test_eq(tor_inet_pton(AF_INET6, ip, &a1), 1);
|
|
|
+ test_eq_ptr(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)), &buf);
|
|
|
+ test_streq(buf, ip);
|
|
|
+
|
|
|
+
|
|
|
+ test_eq(tor_inet_pton(AF_INET6, ip_ffff, &a2), 1);
|
|
|
+ test_eq_ptr(tor_inet_ntop(AF_INET6, &a2, buf, sizeof(buf)), &buf);
|
|
|
+ test_streq(buf, ip_ffff);
|
|
|
+
|
|
|
+
|
|
|
+ test_streq(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)+1), ip);
|
|
|
+ test_streq(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)+1),
|
|
|
+ ip_ffff);
|
|
|
+
|
|
|
+
|
|
|
+ test_eq_ptr(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)), NULL);
|
|
|
+ test_eq_ptr(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)), NULL);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)&sa_storage;
|