Skip to content

Commit fddbd52

Browse files
authored
Merge pull request the-tcpdump-group#771 from ether42/reuseaddr
Allow rpcapd to rebind more rapidly
2 parents c821ea0 + c51bcb5 commit fddbd52

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sockutils.c

+12
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf,
340340
/* This is a server socket */
341341
if (server)
342342
{
343+
/*
344+
* Allow a new server to bind the socket after the old one exited,
345+
* even if lingering sockets are still present.
346+
*/
347+
int optval = 1;
348+
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0)
349+
{
350+
sock_geterror("socket(): ", errbuf, errbuflen);
351+
/* dont treat an error as a failure */
352+
SOCK_DEBUG_MESSAGE(errbuf);
353+
}
354+
343355
#if defined(IPV6_V6ONLY) || defined(IPV6_BINDV6ONLY)
344356
/*
345357
* Force the use of IPv6-only addresses.

0 commit comments

Comments
 (0)