summaryrefslogtreecommitdiff
path: root/src/test/test-socket-util.c
diff options
context:
space:
mode:
authorRonny Chevalier <chevalier.ronny@gmail.com>2015-03-16 20:24:39 +0100
committerRonny Chevalier <chevalier.ronny@gmail.com>2015-04-08 02:42:50 +0200
commit07916bea0708715bf9cc4c3d9010f2397dd1d62a (patch)
treebf9cf5b542dd59b5ebece082984e22479af2578a /src/test/test-socket-util.c
parent48b0d27aaba8652d104f73d866f281f920b8a624 (diff)
test-socket-util: add test for in_addr_to_string
Diffstat (limited to 'src/test/test-socket-util.c')
-rw-r--r--src/test/test-socket-util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
index 6fb4a40944..f257af445a 100644
--- a/src/test/test-socket-util.c
+++ b/src/test/test-socket-util.c
@@ -231,6 +231,24 @@ static void test_in_addr_prefix_next(void) {
}
+static void test_in_addr_to_string_one(int f, const char *addr) {
+ union in_addr_union ua;
+ _cleanup_free_ char *r = NULL;
+
+ assert_se(in_addr_from_string(f, addr, &ua) >= 0);
+ assert_se(in_addr_to_string(f, &ua, &r) >= 0);
+ printf("test_in_addr_to_string_one: %s == %s\n", addr, r);
+ assert_se(streq(addr, r));
+}
+
+static void test_in_addr_to_string(void) {
+ test_in_addr_to_string_one(AF_INET, "192.168.0.1");
+ test_in_addr_to_string_one(AF_INET, "10.11.12.13");
+ test_in_addr_to_string_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
+ test_in_addr_to_string_one(AF_INET6, "::1");
+ test_in_addr_to_string_one(AF_INET6, "fe80::");
+}
+
static void *connect_thread(void *arg) {
union sockaddr_union *sa = arg;
_cleanup_close_ int fd = -1;
@@ -324,6 +342,7 @@ int main(int argc, char *argv[]) {
test_in_addr_prefix_intersect();
test_in_addr_prefix_next();
+ test_in_addr_to_string();
test_nameinfo_pretty();