From 952da5949f677e932f2a48a5474210df571472fb Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 29 Nov 2026 00:34:40 +0100 Subject: Warn about udp addresses already taken by other tracker instances --- tests/t_socket.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/t_socket.c') diff --git a/tests/t_socket.c b/tests/t_socket.c index 8e917a3..6f07f95 100644 --- a/tests/t_socket.c +++ b/tests/t_socket.c @@ -342,6 +342,24 @@ static void case_bind_failure(void) { CHECK_INT(next_descriptor(), before); } +/* The holder binds the way the tracker does, which lets a second socket in + beside it, and that is what the probe is there to see through. */ +static void case_a_taken_udp_address_is_noticed(void) { + char ip[16]; + uint16_t port; + int holder; + + test_case("a udp address somebody holds is reported as taken"); + holder = socket_udp_bind(ip_loopback, 0, SOCKET_SHARED); + CHECK(holder != -1); + bound_address(holder, ip, &port); + CHECK_INT(socket_udp_is_taken(ip_loopback, port), 1); + + test_case("and as free again once it is let go"); + close(holder); + CHECK_INT(socket_udp_is_taken(ip_loopback, port), 0); +} + #ifdef WANT_SYNC_LIVE /* Reading an IPv4 multicast option back: Linux answers with an int, the BSDs with a single byte, so ask how much was written. */ @@ -391,6 +409,7 @@ void test_socket(void) { case_deferred_accept(); case_connect_refused(); case_bind_failure(); + case_a_taken_udp_address_is_noticed(); #ifdef WANT_SYNC_LIVE case_mcast_sender(); #endif -- cgit v1.3