X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/a463e82f5f0152c3c0d7cf1ebfa56d9b099f7fee..c51bcb501fb82b27dfea7eb29be9144b7d3eb22b:/sockutils.c diff --git a/sockutils.c b/sockutils.c index 4bb97a71..11e50737 100644 --- a/sockutils.c +++ b/sockutils.c @@ -346,6 +346,18 @@ SOCKET sock_open(struct addrinfo *addrinfo, int server, int nconn, char *errbuf, /* This is a server socket */ if (server) { + /* + * Allow a new server to bind the socket after the old one exited, + * even if lingering sockets are still present. + */ + int optval = 1; + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) + { + sock_geterror("socket(): ", errbuf, errbuflen); + /* dont treat an error as a failure */ + SOCK_DEBUG_MESSAGE(errbuf); + } + #if defined(IPV6_V6ONLY) || defined(IPV6_BINDV6ONLY) /* * Force the use of IPv6-only addresses.