[hackers] [quark] Only set SO_REUSEADDR on the listening fd || sin

From: <git_AT_suckless.org>
Date: Mon, 01 Dec 2014 17:36:40 +0100

commit 2a83d925d7251acf40776c5eb545a98a9313ae7c
Author: sin <sin_AT_2f30.org>
Date: Mon Dec 1 16:31:35 2014 +0000

    Only set SO_REUSEADDR on the listening fd

diff --git a/quark.c b/quark.c
index 08a8668..8ee9969 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -514,7 +514,7 @@ invalid_request:
 void
 serve(int fd)
 {
- int result, optval;
+ int result;
         struct timeval tv;
         socklen_t salen;
         struct sockaddr sa;
_AT_@ -541,11 +541,6 @@ 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 */
_AT_@ -600,7 +595,7 @@ main(int argc, char *argv[])
         struct passwd *upwd = NULL;
         struct group *gpwd = NULL;
         struct rlimit rlim;
- int i, docrootlen;
+ int i, docrootlen, optval;
 
         ARGBEGIN {
         case 'c':
_AT_@ -679,6 +674,12 @@ main(int argc, char *argv[])
                 logerrmsg("error\tsocket: %s\n", strerror(errno));
                 goto err;
         }
+
+ optval = 1;
+ if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0)
+ logerrmsg("error\tsetsockopt SO_REUSEADDR failed: %s\n",
+ strerror(errno));
+
         if (bind(listenfd, ai->ai_addr, ai->ai_addrlen) == -1) {
                 logerrmsg("error\tbind: %s\n", strerror(errno));
                 goto err;
Received on Mon Dec 01 2014 - 17:36:40 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 01 2014 - 17:48:09 CET