aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2019-01-24 17:32:35 -0800
committerRob Landley <rob@landley.net>2019-01-25 08:27:17 -0600
commit0430bb09837ed5664ea781e54519f965c966992a (patch)
tree8708df121f737dfa0111ec14e14bfc17dc6aa71e
parenta60d0bd0bfddc49238d33424f4848a3c8bc3dc3e (diff)
downloadtoybox-0430bb09837ed5664ea781e54519f965c966992a.tar.gz
nc: allow immediate reuse of ports.
Set SO_REUSEADDR when listening so that we can immediately reuse ports that are no longer being listened upon, instead of having to wait 60 seconds for the socket to be shutdown after being closed (even on localhost!).
-rw-r--r--toys/net/netcat.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/toys/net/netcat.c b/toys/net/netcat.c
index cd05dcf3..3f08b5f7 100644
--- a/toys/net/netcat.c
+++ b/toys/net/netcat.c
@@ -140,6 +140,12 @@ void netcat_main(void)
}
sockfd = xsocket(family, type, 0);
+
+ {
+ int val = 1;
+ xsetsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
+ }
+
if (bind(sockfd, address, bind_addrlen))
perror_exit("bind");
}