diff options
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/network_test.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index d65b8100..35209bea 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -23,6 +23,7 @@ START_TEST(test_addr_resolv_localhost) | |||
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | const char localhost[] = "localhost"; | 25 | const char localhost[] = "localhost"; |
26 | int localhost_split = 0; | ||
26 | 27 | ||
27 | IP ip; | 28 | IP ip; |
28 | ip_init(&ip, 0); | 29 | ip_init(&ip, 0); |
@@ -39,27 +40,35 @@ START_TEST(test_addr_resolv_localhost) | |||
39 | ip_init(&ip, 1); | 40 | ip_init(&ip, 1); |
40 | res = addr_resolve(localhost, &ip, NULL); | 41 | res = addr_resolve(localhost, &ip, NULL); |
41 | 42 | ||
42 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 43 | if (res < 1) { |
43 | 44 | res = addr_resolve("ip6-localhost", &ip, NULL); | |
44 | if (res > 0) { | 45 | localhost_split = 1; |
45 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); | ||
46 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); | ||
47 | } | 46 | } |
48 | 47 | ||
49 | ip_init(&ip, 1); | ||
50 | ip.family = AF_UNSPEC; | ||
51 | IP extra; | ||
52 | ip_reset(&extra); | ||
53 | res = addr_resolve(localhost, &ip, &extra); | ||
54 | |||
55 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | 48 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); |
56 | 49 | ||
57 | if (res > 0) { | 50 | if (res > 0) { |
58 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); | 51 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); |
59 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); | 52 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); |
53 | } | ||
60 | 54 | ||
61 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family); | 55 | if (!localhost_split) { |
62 | ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); | 56 | ip_init(&ip, 1); |
57 | ip.family = AF_UNSPEC; | ||
58 | IP extra; | ||
59 | ip_reset(&extra); | ||
60 | res = addr_resolve(localhost, &ip, &extra); | ||
61 | ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); | ||
62 | |||
63 | if (res > 0) { | ||
64 | ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); | ||
65 | ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); | ||
66 | |||
67 | ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family); | ||
68 | ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); | ||
69 | } | ||
70 | } else { | ||
71 | printf("Localhost seems to be split in two.\n"); | ||
63 | } | 72 | } |
64 | } | 73 | } |
65 | END_TEST | 74 | END_TEST |