]> sourceware.org Git - newlib-cygwin.git/commitdiff
* fhandler.h (class fhandler_socket): Add saw_reuseaddr status flag.
authorCorinna Vinschen <corinna@vinschen.de>
Sun, 29 Jan 2006 12:23:44 +0000 (12:23 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Sun, 29 Jan 2006 12:23:44 +0000 (12:23 +0000)
* fhandler_socket.cc (fhandler_socket::bind): Set socket to
SO_EXCLUSIVEADDRUSE if application didn't explicitely set SO_REUSEADDR
socket option, on systems supporting SO_EXCLUSIVEADDRUSE.
* net.cc (cygwin_setsockopt): Set fhandler's saw_reuseaddr status flag
if SO_REUSEADDR socket option has been successsfully set.
* wincap.h (wincaps::has_exclusiveaddruse): New element.
* wincap.cc: Implement above element throughout.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.h
winsup/cygwin/fhandler_socket.cc
winsup/cygwin/net.cc
winsup/cygwin/wincap.cc
winsup/cygwin/wincap.h

index 82dcaebb7354ad82f0ee3a9b7f50ee805df74485..1886c3084a9f9691591cbc30e2f4aacd53cd1842 100644 (file)
@@ -1,3 +1,14 @@
+2006-01-29  Corinna Vinschen  <corinna@vinschen.de>
+
+       * fhandler.h (class fhandler_socket): Add saw_reuseaddr status flag.
+       * fhandler_socket.cc (fhandler_socket::bind): Set socket to
+       SO_EXCLUSIVEADDRUSE if application didn't explicitely set SO_REUSEADDR
+       socket option, on systems supporting SO_EXCLUSIVEADDRUSE.
+       * net.cc (cygwin_setsockopt): Set fhandler's saw_reuseaddr status flag
+       if SO_REUSEADDR socket option has been successsfully set.
+       * wincap.h (wincaps::has_exclusiveaddruse): New element.
+       * wincap.cc: Implement above element throughout.
+
 2006-01-28  Corinna Vinschen  <corinna@vinschen.de>
 
        * fhandler_disk_file.cc (fhandler_disk_file::mkdir): In case or error,
index 82152019ba21a06eef0607b5a388afeac64e2683..37b7699c8fca8417da812a54f22cea3ab14ca57e 100644 (file)
@@ -417,6 +417,7 @@ class fhandler_socket: public fhandler_base
     unsigned async_io              : 1; /* async I/O */
     unsigned saw_shutdown_read     : 1; /* Socket saw a SHUT_RD */
     unsigned saw_shutdown_write    : 1; /* Socket saw a SHUT_WR */
+    unsigned saw_reuseaddr         : 1; /* Socket saw SO_REUSEADDR call */
     unsigned closed               : 1;
     unsigned owner                : 1;
     unsigned connect_state         : 2;
@@ -440,6 +441,7 @@ class fhandler_socket: public fhandler_base
   IMPLEMENT_STATUS_FLAG (bool, async_io)
   IMPLEMENT_STATUS_FLAG (bool, saw_shutdown_read)
   IMPLEMENT_STATUS_FLAG (bool, saw_shutdown_write)
+  IMPLEMENT_STATUS_FLAG (bool, saw_reuseaddr)
   IMPLEMENT_STATUS_FLAG (bool, closed)
   IMPLEMENT_STATUS_FLAG (bool, owner)
   IMPLEMENT_STATUS_FLAG (conn_state, connect_state)
index 2405471fecfbb79eb6c09152cb50b38a5e40a99c..b885b97dbb84e418bfda9dadc6169829076735ec 100644 (file)
@@ -661,10 +661,33 @@ fhandler_socket::bind (const struct sockaddr *name, int namelen)
        }
 #undef un_addr
     }
-  else if (::bind (get_socket (), name, namelen))
-    set_winsock_errno ();
   else
-    res = 0;
+    {
+      /* If the application didn't explicitely call setsockopt (SO_REUSEADDR),
+         enforce exclusive local address use using the SO_EXCLUSIVEADDRUSE
+        socket option, to emulate POSIX socket behaviour more closely.
+        
+        KB 870562: Note that this option is only available since NT4 SP4.
+        Also note that a bug in Win2K SP1-3 and XP up to SP1 only enables
+        this option for users in the local administrators group. */
+      if (wincap.has_exclusiveaddruse ())
+        {
+         if (!saw_reuseaddr ())
+           {
+             int on = 1;
+             int ret = ::setsockopt (get_socket (), SOL_SOCKET,
+                                     ~(SO_REUSEADDR),
+                                     (const char *) &on, sizeof on);
+             debug_printf ("%d = setsockopt (SO_EXCLUSIVEADDRUSE), %E", ret);
+           }
+         else
+           debug_printf ("SO_REUSEADDR set");
+       }
+      if (::bind (get_socket (), name, namelen))
+       set_winsock_errno ();
+      else
+       res = 0;
+    }
 
 out:
   return res;
index d56bb974c075f40584283623dfac40f11650e997..91d18fd650802ce1367048a0ec8c704e9c22b872 100644 (file)
@@ -722,6 +722,8 @@ cygwin_setsockopt (int fd, int level, int optname, const void *optval,
          else
            set_winsock_errno ();
        }
+      else if (level == SOL_SOCKET && optname == SO_REUSEADDR)
+        fh->saw_reuseaddr (*(int *) optval);
     }
 
   syscall_printf ("%d = setsockopt (%d, %d, %x, %p, %d)",
index 9ff3c92f103944ff27c2a8dacb689608a3d78bec..6b6b0e11d8e853eba0ac3b2f882b0cec6d1c5678 100644 (file)
@@ -64,7 +64,8 @@ static NO_COPY wincaps wincap_unknown = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:false,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_95 = {
@@ -120,7 +121,8 @@ static NO_COPY wincaps wincap_95 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:false,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_95osr2 = {
@@ -176,7 +178,8 @@ static NO_COPY wincaps wincap_95osr2 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:false,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_98 = {
@@ -232,7 +235,8 @@ static NO_COPY wincaps wincap_98 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:false,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_98se = {
@@ -288,7 +292,8 @@ static NO_COPY wincaps wincap_98se = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:false,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_me = {
@@ -344,7 +349,8 @@ static NO_COPY wincaps wincap_me = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:false,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_nt3 = {
@@ -400,7 +406,8 @@ static NO_COPY wincaps wincap_nt3 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_nt4 = {
@@ -456,7 +463,8 @@ static NO_COPY wincaps wincap_nt4 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:false
 };
 
 static NO_COPY wincaps wincap_nt4sp4 = {
@@ -512,7 +520,8 @@ static NO_COPY wincaps wincap_nt4sp4 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:false,
-  has_fileid_dirinfo:false
+  has_fileid_dirinfo:false,
+  has_exclusiveaddruse:true
 };
 
 static NO_COPY wincaps wincap_2000 = {
@@ -568,7 +577,8 @@ static NO_COPY wincaps wincap_2000 = {
   has_disk_ex_ioctls:false,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:true,
-  has_fileid_dirinfo:true
+  has_fileid_dirinfo:true,
+  has_exclusiveaddruse:true
 };
 
 static NO_COPY wincaps wincap_xp = {
@@ -624,7 +634,8 @@ static NO_COPY wincaps wincap_xp = {
   has_disk_ex_ioctls:true,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:true,
-  has_fileid_dirinfo:true
+  has_fileid_dirinfo:true,
+  has_exclusiveaddruse:true
 };
 
 static NO_COPY wincaps wincap_2003 = {
@@ -680,7 +691,8 @@ static NO_COPY wincaps wincap_2003 = {
   has_disk_ex_ioctls:true,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:true,
-  has_fileid_dirinfo:true
+  has_fileid_dirinfo:true,
+  has_exclusiveaddruse:true
 };
 
 static NO_COPY wincaps wincap_vista = {
@@ -736,7 +748,8 @@ static NO_COPY wincaps wincap_vista = {
   has_disk_ex_ioctls:true,
   has_working_virtual_lock:true,
   has_disabled_user_tos_setting:true,
-  has_fileid_dirinfo:true
+  has_fileid_dirinfo:true,
+  has_exclusiveaddruse:true
 };
 
 wincapc wincap __attribute__((section (".cygwin_dll_common"), shared));
index 5738850e0c81ff46e9cfe4559e204de9e49de6b4..d4edfd3daae42682edb451f2a0934a6b32d475dd 100644 (file)
@@ -66,6 +66,7 @@ struct wincaps
   unsigned has_working_virtual_lock                    : 1;
   unsigned has_disabled_user_tos_setting               : 1;
   unsigned has_fileid_dirinfo                          : 1;
+  unsigned has_exclusiveaddruse                                : 1;
 };
 
 class wincapc
@@ -138,6 +139,7 @@ public:
   bool IMPLEMENT (has_working_virtual_lock)
   bool IMPLEMENT (has_disabled_user_tos_setting)
   bool IMPLEMENT (has_fileid_dirinfo)
+  bool IMPLEMENT (has_exclusiveaddruse)
 
 #undef IMPLEMENT
 };
This page took 0.044167 seconds and 5 git commands to generate.