Commit Diff


commit - 2040c43f171d5e4aaad310589de246ccc6f310fe
commit + 4a797971a5f97f3963da28a0f0c7c92c67583481
blob - 9e06a0e252c65c5a267e989ff02417fd5638535c
blob + 47275b4db415a9c8b0926d30f268cd30653f6dda
--- lstun.c
+++ lstun.c
@@ -319,7 +319,7 @@ static void
 bind_socket(void)
 {
 	struct addrinfo hints, *res, *res0;
-	int r, saved_errno;
+	int v, r, saved_errno;
 	char host[64];
 	const char *c, *h, *port, *cause;
 
@@ -358,7 +358,17 @@ bind_socket(void)
 			errno = saved_errno;
 			continue;
 		}
+
+		v = 1;
+		if (setsockopt(socks[nsock], SOL_SOCKET, SO_REUSEADDR, &v,
+		    sizeof(v)) == -1)
+			fatal("setsockopt(SO_REUSEADDR)");
 
+		v = 1;
+		if (setsockopt(socks[nsock], SOL_SOCKET, SO_REUSEPORT, &v,
+		    sizeof(v)) == -1)
+			fatal("setsockopt(SO_REUSEPORT)");
+
 		listen(socks[nsock], 5);
 
 		nsock++;