From 76c7df9fceb992e3d9de2f29d9dfb508f60df0de Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 10 Dec 2013 11:46:03 +0100 Subject: tests: Add test_sendto_recvfrom_ipv6(). --- tests/test_echo_udp_sendto_recvfrom.c | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'tests') diff --git a/tests/test_echo_udp_sendto_recvfrom.c b/tests/test_echo_udp_sendto_recvfrom.c index aa6d921..7139656 100644 --- a/tests/test_echo_udp_sendto_recvfrom.c +++ b/tests/test_echo_udp_sendto_recvfrom.c @@ -19,6 +19,11 @@ static void setup_echo_srv_udp_ipv4(void **state) torture_setup_echo_srv_udp_ipv4(state); } +static void setup_echo_srv_udp_ipv6(void **state) +{ + torture_setup_echo_srv_udp_ipv6(state); +} + static void teardown(void **state) { torture_teardown_echo_srv(state); @@ -72,11 +77,64 @@ static void test_sendto_recvfrom_ipv4(void **state) } } +#ifdef HAVE_IPV6 +static void test_sendto_recvfrom_ipv6(void **state) +{ + struct sockaddr_in6 sin6; + socklen_t slen = sizeof(struct sockaddr_in6); + ssize_t ret; + int rc; + int i; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + assert_int_not_equal(s, -1); + + ZERO_STRUCT(sin6); + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(TORTURE_ECHO_SRV_PORT); + + rc = inet_pton(AF_INET6, TORTURE_ECHO_SRV_IPV6, &sin6.sin6_addr); + assert_int_equal(rc, 1); + + for (i = 0; i < 10; i++) { + char send_buf[64] = {0}; + char recv_buf[64] = {0}; + struct sockaddr_in6 cli_in6; + socklen_t clen; + + snprintf(send_buf, sizeof(send_buf), "packet.%d", i); + + ret = sendto(s, + send_buf, + sizeof(send_buf), + 0, + (struct sockaddr *)(void *)&sin6, + slen); + assert_int_not_equal(ret, -1); + + ret = recvfrom(s, + recv_buf, + sizeof(recv_buf), + 0, + (struct sockaddr *)&cli_in6, + &clen); + + assert_memory_equal(send_buf, recv_buf, sizeof(send_buf)); + } +} +#endif + int main(void) { int rc; const UnitTest tests[] = { unit_test_setup_teardown(test_sendto_recvfrom_ipv4, setup_echo_srv_udp_ipv4, teardown), +#ifdef HAVE_IPV6 + unit_test_setup_teardown(test_sendto_recvfrom_ipv6, setup_echo_srv_udp_ipv6, teardown), +#endif }; rc = run_tests(tests); -- cgit