To self: reuseaddr before bind. - geomyidae - A small C-based gopherd.
HTML git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
DIR LICENSE
---
DIR commit 94382cb7360ec1e712df59e883381cee1344dd9a
DIR parent d81d0fda6b372f9bd057b5c17e50079509875d94
HTML Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 24 Apr 2011 15:14:25 +0200
To self: reuseaddr before bind.
Diffstat:
M main.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
---
DIR 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);