[hackers] [quark] bind: re-use address, setsockopt SO_REUSEADDR || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sun, 30 Nov 2014 23:36:03 +0100

commit b017f90846947a2bcddc7ae2b0fbd9c8252e44a8
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sun Nov 30 14:47:26 2014 +0100

    bind: re-use address, setsockopt SO_REUSEADDR

diff --git a/quark.c b/quark.c
index 7a40d6a..08a8668 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -514,7 +514,7 @@ invalid_request:
 void
 serve(int fd)
 {
- int result;
+ int result, optval;
         struct timeval tv;
         socklen_t salen;
         struct sockaddr sa;
_AT_@ -541,6 +541,11 @@ serve(int fd)
                                           host, sizeof host);
                                 break;
                         }
+ /* bind: re-use address */
+ optval = 1;
+ if (setsockopt(req.fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0)
+ logerrmsg("error\tsetsockopt SO_REUSEADDR failed: %s\n",
+ strerror(errno));
 
                         /* If we haven't received any data within this period, close the
                          * socket to avoid spamming the process table */
Received on Sun Nov 30 2014 - 23:36:03 CET

This archive was generated by hypermail 2.3.0 : Sun Nov 30 2014 - 23:36:12 CET