commit 94382cb7360ec1e712df59e883381cee1344dd9a
parent d81d0fda6b372f9bd057b5c17e50079509875d94
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 24 Apr 2011 15:14:25 +0200
To self: reuseaddr before bind.
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/main.c b/main.c
@@ -254,7 +254,7 @@ main(int argc, char *argv[])
struct addrinfo hints, *ai, *rp;
struct sockaddr_storage clt;
socklen_t cltlen;
- int sock, dofork;
+ int sock, dofork, on;
char *port, *base, clienth[NI_MAXHOST], clientp[NI_MAXSERV];
char *user, *group, *bindip, *ohost, *sport;
struct passwd *us;
@@ -355,11 +355,16 @@ main(int argc, char *argv[])
return 1;
}
+ on = 1;
for(rp = ai; rp != nil; rp = rp->ai_next) {
listfd = socket(rp->ai_family, rp->ai_socktype,
rp->ai_protocol);
if(listfd < 0)
continue;
+ if(setsockopt(listfd, SOL_SOCKET, SO_REUSEADDR, &on,
+ sizeof(on)) < 0) {
+ break;
+ }
if(bind(listfd, rp->ai_addr, rp->ai_addrlen) == 0)
break;
close(listfd);