From 73b3ed5a38cdd2312351ea8f19c3c89cbfc1154c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 18 Nov 2024 22:22:25 -0800 Subject: TCPv6 test suite fixes for addresses. We moved some of the tests out of the older Convey framework into the NUTS framework. --- src/sp/transport/tcp/tcp_test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src') diff --git a/src/sp/transport/tcp/tcp_test.c b/src/sp/transport/tcp/tcp_test.c index c80a259f..37321ac1 100644 --- a/src/sp/transport/tcp/tcp_test.c +++ b/src/sp/transport/tcp/tcp_test.c @@ -125,6 +125,42 @@ test_tcp_no_delay_option(void) NUTS_CLOSE(s); } +static bool +has_v6(void) +{ + nng_sockaddr sa; + nng_udp *u; + int rv; + + sa.s_in6.sa_family = NNG_AF_INET6; + sa.s_in6.sa_port = 0; + memset(sa.s_in6.sa_addr, 0, 16); + sa.s_in6.sa_addr[15] = 1; + + rv = nng_udp_open(&u, &sa); + if (rv == 0) { + nng_udp_close(u); + } + return (rv == 0 ? 1 : 0); +} + +void +test_tcp_ipv6(void) +{ + if (!has_v6()) { + NUTS_SKIP("No IPv6 support"); + return; + } + nng_socket s; + NUTS_OPEN(s); + // this should have a [::1] bracket + NUTS_FAIL(nng_dial(s, "tcp://::1", NULL, 0), NNG_EINVAL); + NUTS_FAIL(nng_dial(s, "tcp://::1:5055", NULL, 0), NNG_EINVAL); + // this requires a port, but otherwise its ok, so address is invalid + NUTS_FAIL(nng_dial(s, "tcp://[::1]", NULL, 0), NNG_EADDRINVAL); + NUTS_CLOSE(s); +} + void test_tcp_keep_alive_option(void) { @@ -206,5 +242,6 @@ NUTS_TESTS = { { "tcp no delay option", test_tcp_no_delay_option }, { "tcp keep alive option", test_tcp_keep_alive_option }, { "tcp recv max", test_tcp_recv_max }, + { "tcp ipv6", test_tcp_ipv6 }, { NULL, NULL }, }; -- cgit v1.2.3-70-g09d2