bug-gnulib
[Top][All Lists]
Advanced

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

Re: fix malfunction of socket functions on HP-UX in 64-bit mode


From: Bruno Haible
Subject: Re: fix malfunction of socket functions on HP-UX in 64-bit mode
Date: Tue, 24 Apr 2018 20:08:45 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-119-generic; KDE/5.18.0; x86_64; ; )

Tom G. Christensen wrote:
> This testcase uses SO_REUSEPORT which is not available everywhere.
> 
>  From Solaris 9:
> test-getsockname.c: In function 'open_server_socket':
> test-getsockname.c:43:30: error: 'SO_REUSEPORT' undeclared (first use in 
> this function)
>     setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
>                                ^
> test-getsockname.c:43:30: note: each undeclared identifier is reported 
> only once for each function it appears in

Thanks for the report. This should fix it:


2018-04-24  Bruno Haible  <address@hidden>

        sys_socket: Make SO_REUSEPORT available across platforms.
        Reported by Tom G. Christensen <address@hidden>.
        * lib/sys_socket.in.h (SO_REUSEPORT): New macro.
        * doc/posix-headers/sys_socket.texi: Mention the issue.
        * tests/test-poll.c (SO_REUSEPORT): Remove.
        * tests/test-select.h: Include <sys/socket.h>.
        (SO_REUSEPORT): Remove.
        * modules/select-tests (Depends-on): Add 'sys_socket'.

diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h
index 7102588..cbaf5cf 100644
--- a/lib/sys_socket.in.h
+++ b/lib/sys_socket.in.h
@@ -215,6 +215,15 @@ struct msghdr {
 
 #endif
 
+/* Ensure SO_REUSEPORT is defined.  */
+/* For the subtle differences between SO_REUSEPORT and SO_REUSEADDR, see
+   
https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t
+   and https://lwn.net/Articles/542629/
+ */
+#ifndef SO_REUSEPORT
+# define SO_REUSEPORT SO_REUSEADDR
+#endif
+
 /* Fix some definitions from <winsock2.h>.  */
 
 #if @HAVE_WINSOCK2_H@
diff --git a/doc/posix-headers/sys_socket.texi 
b/doc/posix-headers/sys_socket.texi
index 380a0ae..3144ae2 100644
--- a/doc/posix-headers/sys_socket.texi
+++ b/doc/posix-headers/sys_socket.texi
@@ -32,6 +32,9 @@
 The @code{CMSG_SPACE} and @code{CMSG_LEN} macros are not provided on some
 platforms:
 OpenVMS.
address@hidden
+This header file does not define the @code{SO_REUSEPORT} macro on some 
platforms:
+Minix 3.1.8, Solaris 10, Cygwin, mingw, MSVC 14.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/tests/test-poll.c b/tests/test-poll.c
index c5e0a92..ebace0f 100644
--- a/tests/test-poll.c
+++ b/tests/test-poll.c
@@ -52,10 +52,6 @@ SIGNATURE_CHECK (poll, int, (struct pollfd[], nfds_t, int));
 #include <sys/wait.h>
 #endif
 
-#ifndef SO_REUSEPORT
-#define SO_REUSEPORT    SO_REUSEADDR
-#endif
-
 #define TEST_PORT       12345
 
 
diff --git a/tests/test-select.h b/tests/test-select.h
index d751e42..364687b 100644
--- a/tests/test-select.h
+++ b/tests/test-select.h
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <unistd.h>
@@ -37,10 +38,6 @@
 # include <sys/wait.h>
 #endif
 
-#ifndef SO_REUSEPORT
-# define SO_REUSEPORT    SO_REUSEADDR
-#endif
-
 #define TEST_PORT       12345
 
 
diff --git a/modules/select-tests b/modules/select-tests
index bd7b731..899b50c 100644
--- a/modules/select-tests
+++ b/modules/select-tests
@@ -10,6 +10,7 @@ tests/test-select-stdin.c
 
 Depends-on:
 stdbool
+sys_socket
 netinet_in
 arpa_inet
 unistd




reply via email to

[Prev in Thread] Current Thread [Next in Thread]