From 9035325e566c47e83700f88b1ff6376dce0068e8 Mon Sep 17 00:00:00 2001 From: Roman Yepishev Date: Sat, 27 Feb 2016 11:45:02 -0500 Subject: Remove magic numbers from addr_resolve * Add #defines for INET/INET6 returns * Remove magic number 3 - exact AF_INET/INET6 result found. * Updated network_test.c --- auto_tests/network_test.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'auto_tests/network_test.c') diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index c1ac8084..adf0189a 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -28,7 +28,7 @@ START_TEST(test_addr_resolv_localhost) int localhost_split = 0; IP ip; - ip_init(&ip, 0); + ip_init(&ip, /* ipv6? */ 0); int res = addr_resolve(localhost, &ip, NULL); @@ -39,10 +39,10 @@ START_TEST(test_addr_resolv_localhost) ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr)); } - ip_init(&ip, 1); + ip_init(&ip, /* ipv6? */ 1); res = addr_resolve(localhost, &ip, NULL); - if (res < 1) { + if (!(res & TOX_ADDR_RESOLVE_INET6)) { res = addr_resolve("ip6-localhost", &ip, NULL); localhost_split = 1; } @@ -50,12 +50,12 @@ START_TEST(test_addr_resolv_localhost) ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); if (res > 0) { - ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); + ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6 (%u), got %u.", AF_INET6, ip.family); ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); } if (!localhost_split) { - ip_init(&ip, 1); + ip_init(&ip, /* ipv6? */ 1); ip.family = AF_UNSPEC; IP extra; ip_reset(&extra); @@ -63,10 +63,10 @@ START_TEST(test_addr_resolv_localhost) ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno)); if (res > 0) { - ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6, got %u.", ip.family); + ck_assert_msg(ip.family == AF_INET6, "Expected family AF_INET6 (%u), got %u.", AF_INET6, ip.family); ck_assert_msg(!memcmp(&ip.ip6, &in6addr_loopback, sizeof(IP6)), "Expected ::1, got %s.", ip_ntoa(&ip)); - ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET, got %u.", extra.family); + ck_assert_msg(extra.family == AF_INET, "Expected family AF_INET (%u), got %u.", AF_INET, extra.family); ck_assert_msg(extra.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(extra.ip4.in_addr)); } } else { -- cgit v1.2.3 From 32d86978fd9894913c9acae70a96373bea45c8b7 Mon Sep 17 00:00:00 2001 From: Roman Yepishev Date: Sat, 27 Feb 2016 12:07:04 -0500 Subject: Remove unused main() arguments --- auto_tests/network_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'auto_tests/network_test.c') diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index adf0189a..e3b47ea2 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -144,7 +144,7 @@ Suite *network_suite(void) return s; } -int main(int argc, char *argv[]) +int main() { srand((unsigned int) time(NULL)); -- cgit v1.2.3 From c886f906a8094b1c636446004162b9e0674923bd Mon Sep 17 00:00:00 2001 From: Roman Yepishev Date: Sat, 27 Feb 2016 14:32:49 -0500 Subject: Move argument comments to the end of line --- auto_tests/network_test.c | 6 +++--- toxcore/network.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'auto_tests/network_test.c') diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index e3b47ea2..b88b0e8c 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -28,7 +28,7 @@ START_TEST(test_addr_resolv_localhost) int localhost_split = 0; IP ip; - ip_init(&ip, /* ipv6? */ 0); + ip_init(&ip, 0); // ipv6enabled = 0 int res = addr_resolve(localhost, &ip, NULL); @@ -39,7 +39,7 @@ START_TEST(test_addr_resolv_localhost) ck_assert_msg(ip.ip4.uint32 == htonl(0x7F000001), "Expected 127.0.0.1, got %s.", inet_ntoa(ip.ip4.in_addr)); } - ip_init(&ip, /* ipv6? */ 1); + ip_init(&ip, 1); // ipv6enabled = 1 res = addr_resolve(localhost, &ip, NULL); if (!(res & TOX_ADDR_RESOLVE_INET6)) { @@ -55,7 +55,7 @@ START_TEST(test_addr_resolv_localhost) } if (!localhost_split) { - ip_init(&ip, /* ipv6? */ 1); + ip_init(&ip, 1); // ipv6enabled = 1 ip.family = AF_UNSPEC; IP extra; ip_reset(&extra); diff --git a/toxcore/network.c b/toxcore/network.c index 5ab480b7..c6cf6ed4 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -970,9 +970,9 @@ int addr_resolve(const char *address, IP *to, IP *extra) } IP ip4; - ip_init(&ip4, /* ipv6? */ false); + ip_init(&ip4, 0); // ipv6enabled = 0 IP ip6; - ip_init(&ip6, /* ipv6? */ true); + ip_init(&ip6, 1); // ipv6enabled = 1 for (walker = server; (walker != NULL) && !done; walker = walker->ai_next) { switch (walker->ai_family) { -- cgit v1.2.3