Allow server to reuse bound address.
[cascardo/rnetproxy.git] / tcp_server.c
index 35ad630..fd18201 100644 (file)
@@ -28,9 +28,11 @@ static int
 tcp_server (struct addrinfo *ai)
 {
   int fd;
+  int optval = 1;
   fd = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol);
   if (fd < 0)
     return -1;
+  setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (int));
   if (bind (fd, ai->ai_addr, ai->ai_addrlen) < 0)
     {
       close (fd);