commit e5e61a193befc357b9bbb03aa9dcdf80300502b9
parent 63f8274ade6dc6a87039d1eb075c20562cff569e
Author: sin <sin@2f30.org>
Date: Tue, 5 Jun 2012 15:42:47 +0100
sscall: Set SO_REUSEADDR to avoid issues with bind()
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/sscall.c b/sscall.c
@@ -236,6 +236,7 @@ main(int argc, char *argv[])
char *prog;
int c;
char host[NI_MAXHOST];
+ int optval;
prog = *argv;
while ((c = getopt(argc, argv, "hb:c:r:d:v")) != -1) {
@@ -338,6 +339,14 @@ main(int argc, char *argv[])
p1->ai_protocol);
if (srv_sockfd < 0)
continue;
+ optval = 1;
+ ret = setsockopt(srv_sockfd, SOL_SOCKET,
+ SO_REUSEADDR, &optval, sizeof(optval));
+ if (ret < 0) {
+ close(srv_sockfd);
+ warn("setsockopt");
+ continue;
+ }
if (bind(srv_sockfd, p1->ai_addr, p1->ai_addrlen) < 0) {
close(srv_sockfd);
warn("bind");