]> hackdaworld.org Git - my-code/ivac.git/commitdiff
only set reuseaddr socket opt if regular bind call fails
authorhackbard <hackbard>
Tue, 11 May 2004 07:06:19 +0000 (07:06 +0000)
committerhackbard <hackbard>
Tue, 11 May 2004 07:06:19 +0000 (07:06 +0000)
src/network.c

index 449dacf7a43a75db3b8b4930a2207011cee173b7..3579f5ab8aff8a945492a917d7dba6caf7a21d04 100644 (file)
@@ -27,17 +27,15 @@ int network_init(t_net *net) {
   addr.sin_port=htons(net->l_port);
   addr.sin_addr.s_addr=INADDR_ANY;
 
-  /* prevent addres in use error message */
-  true=1;
-  if(setsockopt(net->l_fd,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(true))==-1) {
-    perror("[network] setsockopt call");
-    return N_ERROR;
-  }
-
   if(bind(net->l_fd,(struct sockaddr *)&addr,
           sizeof(struct sockaddr))==-1) {
-    perror("[network] bind call");
-    return N_ERROR;
+    /* try harder ... */
+    true=1;
+    if(setsockopt(net->l_fd,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(true))==-1) {
+      perror("[network] setsockopt call");
+      return N_ERROR;
+    }
+    puts("[network] reused address");
   }
 
   if(listen(net->l_fd,MAX_LISTEN_QUEUE)==-1) {