diff options
| -rw-r--r-- | src/sp/transport/tcp/tcp_test.c | 37 | ||||
| -rw-r--r-- | tests/tcp6.c | 10 |
2 files changed, 37 insertions, 10 deletions
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 }, }; diff --git a/tests/tcp6.c b/tests/tcp6.c index f6fd5a7c..a3ce919b 100644 --- a/tests/tcp6.c +++ b/tests/tcp6.c @@ -75,14 +75,4 @@ TestMain("TCP (IPv6) Transport", { } else { SkipSo("IPv6 not available"); } - - Convey("Malformed TCPv6 addresses do not panic", { - nng_socket s1; - - So(nng_pair_open(&s1) == 0); - Reset({ nng_close(s1); }); - So(nng_dial(s1, "tcp://::1", NULL, 0) == NNG_EADDRINVAL); - So(nng_dial(s1, "tcp://::1:5055", NULL, 0) == NNG_EADDRINVAL); - So(nng_dial(s1, "tcp://[::1]", NULL, 0) == NNG_EADDRINVAL); - }); }) |
