summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/sock.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/sock.c b/src/sock.c
index be50376..bf32c78 100644
--- a/src/sock.c
+++ b/src/sock.c
@@ -163,7 +163,7 @@ int socket_blocking (int sock)
* Start listening to a socket. Create a socket with the selected port.
* The size of the socket address will be returned to the caller through
* the pointer, while the socket is returned as a default return.
- * - rjkaes
+ * - rjkaes
*/
int listen_sock (uint16_t port, socklen_t * addrlen)
{
@@ -194,6 +194,9 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
if (listenfd == -1)
continue;
+ setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on,
+ sizeof (on));
+
if (bind (listenfd, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* success */
@@ -210,8 +213,6 @@ int listen_sock (uint16_t port, socklen_t * addrlen)
return -1;
}
- setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on));
-
if (listen (listenfd, MAXLISTEN) < 0) {
log_message (LOG_ERR,
"Unable to start listening socket because of %s",