Test for SO_REUSEADDR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I turned Jeremy's program into a Wine conformance test. It shows that unless we specify SO_REUSEADDR on the second socket, binding to an address which is already in use fails. I confirmed this behavior on Win98 and NT4. On Wine the test currently has two todo_wine.

Also note that the behavior with wsock32.dll (the 32bit winsock 1 dll) seems to be the same.


Changelog:


* dlls/winsock/tests/sock.c

   Jeremy White <jwhite@xxxxxxxxxxxxxxx>
   Francois Gouget <fgouget@xxxxxxxxxxxxxxx>

Test the behavior of bind() wrt. SO_REUSEADDR.

--
Francois Gouget
fgouget@xxxxxxxxxxxxxxx

Index: dlls/winsock/tests/sock.c
===================================================================
RCS file: /home/cvs/wine/dlls/winsock/tests/sock.c,v
retrieving revision 1.11
diff -u -r1.11 sock.c
--- dlls/winsock/tests/sock.c	7 Oct 2003 03:30:47 -0000	1.11
+++ dlls/winsock/tests/sock.c	13 Jan 2004 00:47:38 -0000
@@ -625,6 +625,47 @@
         CloseHandle ( client_ready[i] );
 }
 
+static void test_so_reuseaddr()
+{
+    struct sockaddr_in saddr;
+    SOCKET s1,s2;
+    int rc,reuse,size;
+
+    saddr.sin_family      = AF_INET;
+    saddr.sin_port        = htons(9375);
+    saddr.sin_addr.s_addr = inet_addr("127.0.0.1");
+
+    s1=socket(AF_INET, SOCK_STREAM, 0);
+    ok(s1!=INVALID_SOCKET, "socket() failed error: %d\n", WSAGetLastError());
+    rc = bind(s1, (struct sockaddr*)&saddr, sizeof(saddr));
+    ok(rc!=SOCKET_ERROR, "bind(s1) failed error: %d\n", WSAGetLastError());
+
+    s2=socket(AF_INET, SOCK_STREAM, 0);
+    ok(s2!=INVALID_SOCKET, "socket() failed error: %d\n", WSAGetLastError());
+
+    reuse=0x1234;
+    size=sizeof(reuse);
+    rc=getsockopt(s2, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, &size );
+    ok(rc==0 && reuse==0,"wrong result in getsockopt(SO_REUSEADDR): rc=%d reuse=%d\n",rc,reuse);
+
+    todo_wine {
+    rc = bind(s2, (struct sockaddr*)&saddr, sizeof(saddr));
+    ok(rc==SOCKET_ERROR, "bind() succeeded\n");
+    }
+
+    reuse = 1;
+    rc = setsockopt(s2, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse));
+    ok(rc==0, "setsockopt() failed error: %d\n", WSAGetLastError());
+
+    todo_wine {
+    rc = bind(s2, (struct sockaddr*)&saddr, sizeof(saddr));
+    ok(rc==0, "bind() failed error: %d\n", WSAGetLastError());
+    }
+
+    closesocket(s2);
+    closesocket(s1);
+}
+
 /************* Array containing the tests to run **********/
 
 #define STD_STREAM_SOCKET \
@@ -686,6 +727,8 @@
     int i;
     Init();
 
+    test_so_reuseaddr();
+
     for (i = 0; i < NUM_TESTS; i++)
     {
         trace ( " **** STARTING TEST %d **** \n", i );

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux