From: Pavel Shramov Date: Thu, 29 Nov 2007 10:37:22 +0000 (+0300) Subject: network plugin: Set SO_REUSEADDR on socket so multiple listeners can share port X-Git-Tag: collectd-4.3.0beta0~70^2~2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b538a4fc80d63b881382e33f517f4e38e559478a;p=collectd.git network plugin: Set SO_REUSEADDR on socket so multiple listeners can share port This patch allows other programs to bind same port and process data from clients not interfering with master collectd server. Signed-off-by: Florian Forster --- diff --git a/src/network.c b/src/network.c index 21b96940..ab04f4c1 100644 --- a/src/network.c +++ b/src/network.c @@ -683,6 +683,15 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai) { int loop = 0; + /* allow multiple sockets to use the same PORT number */ + if (setsockopt(se->fd, SOL_SOCKET, SO_REUSEADDR, + &loop, sizeof(loop)) == -1) { + char errbuf[1024]; + ERROR ("setsockopt: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + DEBUG ("fd = %i; calling `bind'", se->fd); if (bind (se->fd, ai->ai_addr, ai->ai_addrlen) == -1)