testbench: correctly apply socket options in minitcpsrvr

The option name in setsockopts is not a bitmask, so SO_REUSEADDR and
SO_REUSEPORT can't be ORed together. Instead apply the options via
separate calls.

Fixes: #5456

Thanks: Chris Hofstaedtler <zeha@debian.org>
This commit is contained in:
Michael Biebl 2024-09-23 21:08:06 +02:00
parent 7f79e4f249
commit 2f12b4cc9b

View File

@ -89,8 +89,11 @@ createListenSocket(void)
}
// Set SO_REUSEADDR and SO_REUSEPORT options
int opt = 1;
if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
errout("setsockopt failed");
if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
errout("setsockopt failed for SO_REUSEADDR");
}
if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
errout("setsockopt failed for SO_REUSEPORT");
}
fprintf(stderr, "listen on target port %d\n", targetPort);