From ade06117babf6f0a01c866928a349d7a861c8b3d Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 16 Sep 2025 10:42:01 +0100 Subject: [PATCH] maintenance: allow reuse of address and port for the simulator. This way, the simulator can be killed and immediately restarted without encountering the "address already in use" error. --- test/simulator/simulator.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/simulator/simulator.c b/test/simulator/simulator.c index 92edaee37..739f62274 100644 --- a/test/simulator/simulator.c +++ b/test/simulator/simulator.c @@ -143,6 +143,20 @@ int main(int argc, char* argv[]) perror("ERROR opening socket"); return 1; } + + int yes = 1; + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) { + perror("setsockopt(SO_REUSEADDR) failed"); + return 1; + } + +#ifdef SO_REUSEPORT + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) < 0) { + perror("setsockopt(SO_REUSEPORT) failed"); + return 1; + } +#endif + struct sockaddr_in serv_addr; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY;