summaryrefslogtreecommitdiffstats
path: root/gl/sys_socket.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/sys_socket.in.h')
-rw-r--r--gl/sys_socket.in.h137
1 files changed, 91 insertions, 46 deletions
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index b4cf0c3..acdf7ee 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -1,20 +1,20 @@
1/* Provide a sys/socket header file for systems lacking it (read: MinGW) 1/* Provide a sys/socket header file for systems lacking it (read: MinGW)
2 and for systems where it is incomplete. 2 and for systems where it is incomplete.
3 Copyright (C) 2005-2013 Free Software Foundation, Inc. 3 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 Written by Simon Josefsson. 4 Written by Simon Josefsson.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU Lesser General Public License as
8 the Free Software Foundation; either version 3, or (at your option) 8 published by the Free Software Foundation; either version 2.1 of the
9 any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19/* This file is supposed to be used on platforms that lack <sys/socket.h>, 19/* This file is supposed to be used on platforms that lack <sys/socket.h>,
20 on platforms where <sys/socket.h> cannot be included standalone, and on 20 on platforms where <sys/socket.h> cannot be included standalone, and on
@@ -63,6 +63,9 @@
63#ifndef _@GUARD_PREFIX@_SYS_SOCKET_H 63#ifndef _@GUARD_PREFIX@_SYS_SOCKET_H
64#define _@GUARD_PREFIX@_SYS_SOCKET_H 64#define _@GUARD_PREFIX@_SYS_SOCKET_H
65 65
66#ifndef _GL_INLINE_HEADER_BEGIN
67 #error "Please include config.h first."
68#endif
66_GL_INLINE_HEADER_BEGIN 69_GL_INLINE_HEADER_BEGIN
67#ifndef _GL_SYS_SOCKET_INLINE 70#ifndef _GL_SYS_SOCKET_INLINE
68# define _GL_SYS_SOCKET_INLINE _GL_INLINE 71# define _GL_SYS_SOCKET_INLINE _GL_INLINE
@@ -76,7 +79,12 @@ _GL_INLINE_HEADER_BEGIN
76 79
77#if !@HAVE_SA_FAMILY_T@ 80#if !@HAVE_SA_FAMILY_T@
78# if !GNULIB_defined_sa_family_t 81# if !GNULIB_defined_sa_family_t
82/* On OS/2 kLIBC, sa_family_t is unsigned char unless TCPV40HDRS is defined. */
83# if !defined __KLIBC__ || defined TCPV40HDRS
79typedef unsigned short sa_family_t; 84typedef unsigned short sa_family_t;
85# else
86typedef unsigned char sa_family_t;
87# endif
80# define GNULIB_defined_sa_family_t 1 88# define GNULIB_defined_sa_family_t 1
81# endif 89# endif
82#endif 90#endif
@@ -133,6 +141,15 @@ struct sockaddr_storage
133# define SHUT_RDWR 2 141# define SHUT_RDWR 2
134# endif 142# endif
135 143
144# ifdef __VMS /* OpenVMS */
145# ifndef CMSG_SPACE
146# define CMSG_SPACE(length) _CMSG_SPACE(length)
147# endif
148# ifndef CMSG_LEN
149# define CMSG_LEN(length) _CMSG_LEN(length)
150# endif
151# endif
152
136#else 153#else
137 154
138# ifdef __CYGWIN__ 155# ifdef __CYGWIN__
@@ -152,7 +169,7 @@ struct sockaddr_storage
152 code may not run on older Windows releases then. My Windows 2000 169 code may not run on older Windows releases then. My Windows 2000
153 box was not able to run the code, for example. The situation is 170 box was not able to run the code, for example. The situation is
154 slightly confusing because 171 slightly confusing because
155 <http://msdn.microsoft.com/en-us/library/ms738520> 172 <https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
156 suggests that getaddrinfo should be available on all Windows 173 suggests that getaddrinfo should be available on all Windows
157 releases. */ 174 releases. */
158 175
@@ -178,12 +195,7 @@ struct sockaddr_storage
178/* Include headers needed by the emulation code. */ 195/* Include headers needed by the emulation code. */
179# include <sys/types.h> 196# include <sys/types.h>
180# include <io.h> 197# include <io.h>
181 198/* If these headers don't define socklen_t, <config.h> does. */
182# if !GNULIB_defined_socklen_t
183typedef int socklen_t;
184# define GNULIB_defined_socklen_t 1
185# endif
186
187# endif 199# endif
188 200
189/* Rudimentary 'struct msghdr'; this works as long as you don't try to 201/* Rudimentary 'struct msghdr'; this works as long as you don't try to
@@ -198,6 +210,15 @@ struct msghdr {
198 210
199#endif 211#endif
200 212
213/* Ensure SO_REUSEPORT is defined. */
214/* For the subtle differences between SO_REUSEPORT and SO_REUSEADDR, see
215 https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t
216 and https://lwn.net/Articles/542629/
217 */
218#ifndef SO_REUSEPORT
219# define SO_REUSEPORT SO_REUSEADDR
220#endif
221
201/* Fix some definitions from <winsock2.h>. */ 222/* Fix some definitions from <winsock2.h>. */
202 223
203#if @HAVE_WINSOCK2_H@ 224#if @HAVE_WINSOCK2_H@
@@ -235,7 +256,7 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
235# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 256# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
236# undef close 257# undef close
237# define close close_used_without_including_unistd_h 258# define close close_used_without_including_unistd_h
238# else 259# elif !defined __clang__
239 _GL_WARN_ON_USE (close, 260 _GL_WARN_ON_USE (close,
240 "close() used without including <unistd.h>"); 261 "close() used without including <unistd.h>");
241# endif 262# endif
@@ -320,14 +341,20 @@ _GL_WARN_ON_USE (connect, "connect is not always POSIX compliant - "
320# define accept rpl_accept 341# define accept rpl_accept
321# endif 342# endif
322_GL_FUNCDECL_RPL (accept, int, 343_GL_FUNCDECL_RPL (accept, int,
323 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 344 (int fd,
345 struct sockaddr *restrict addr,
346 socklen_t *restrict addrlen));
324_GL_CXXALIAS_RPL (accept, int, 347_GL_CXXALIAS_RPL (accept, int,
325 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 348 (int fd,
349 struct sockaddr *restrict addr,
350 socklen_t *restrict addrlen));
326# else 351# else
327/* Need to cast, because on Solaris 10 systems, the third parameter is 352/* Need to cast, because on Solaris 10 systems, the third parameter is
328 void *addrlen. */ 353 void *addrlen. */
329_GL_CXXALIAS_SYS_CAST (accept, int, 354_GL_CXXALIAS_SYS_CAST (accept, int,
330 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 355 (int fd,
356 struct sockaddr *restrict addr,
357 socklen_t *restrict addrlen));
331# endif 358# endif
332_GL_CXXALIASWARN (accept); 359_GL_CXXALIASWARN (accept);
333#elif @HAVE_WINSOCK2_H@ 360#elif @HAVE_WINSOCK2_H@
@@ -378,15 +405,18 @@ _GL_WARN_ON_USE (bind, "bind is not always POSIX compliant - "
378# define getpeername rpl_getpeername 405# define getpeername rpl_getpeername
379# endif 406# endif
380_GL_FUNCDECL_RPL (getpeername, int, 407_GL_FUNCDECL_RPL (getpeername, int,
381 (int fd, struct sockaddr *addr, socklen_t *addrlen) 408 (int fd, struct sockaddr *restrict addr,
409 socklen_t *restrict addrlen)
382 _GL_ARG_NONNULL ((2, 3))); 410 _GL_ARG_NONNULL ((2, 3)));
383_GL_CXXALIAS_RPL (getpeername, int, 411_GL_CXXALIAS_RPL (getpeername, int,
384 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 412 (int fd, struct sockaddr *restrict addr,
413 socklen_t *restrict addrlen));
385# else 414# else
386/* Need to cast, because on Solaris 10 systems, the third parameter is 415/* Need to cast, because on Solaris 10 systems, the third parameter is
387 void *addrlen. */ 416 void *addrlen. */
388_GL_CXXALIAS_SYS_CAST (getpeername, int, 417_GL_CXXALIAS_SYS_CAST (getpeername, int,
389 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 418 (int fd, struct sockaddr *restrict addr,
419 socklen_t *restrict addrlen));
390# endif 420# endif
391_GL_CXXALIASWARN (getpeername); 421_GL_CXXALIASWARN (getpeername);
392#elif @HAVE_WINSOCK2_H@ 422#elif @HAVE_WINSOCK2_H@
@@ -407,15 +437,18 @@ _GL_WARN_ON_USE (getpeername, "getpeername is not always POSIX compliant - "
407# define getsockname rpl_getsockname 437# define getsockname rpl_getsockname
408# endif 438# endif
409_GL_FUNCDECL_RPL (getsockname, int, 439_GL_FUNCDECL_RPL (getsockname, int,
410 (int fd, struct sockaddr *addr, socklen_t *addrlen) 440 (int fd, struct sockaddr *restrict addr,
441 socklen_t *restrict addrlen)
411 _GL_ARG_NONNULL ((2, 3))); 442 _GL_ARG_NONNULL ((2, 3)));
412_GL_CXXALIAS_RPL (getsockname, int, 443_GL_CXXALIAS_RPL (getsockname, int,
413 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 444 (int fd, struct sockaddr *restrict addr,
445 socklen_t *restrict addrlen));
414# else 446# else
415/* Need to cast, because on Solaris 10 systems, the third parameter is 447/* Need to cast, because on Solaris 10 systems, the third parameter is
416 void *addrlen. */ 448 void *addrlen. */
417_GL_CXXALIAS_SYS_CAST (getsockname, int, 449_GL_CXXALIAS_SYS_CAST (getsockname, int,
418 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 450 (int fd, struct sockaddr *restrict addr,
451 socklen_t *restrict addrlen));
419# endif 452# endif
420_GL_CXXALIASWARN (getsockname); 453_GL_CXXALIASWARN (getsockname);
421#elif @HAVE_WINSOCK2_H@ 454#elif @HAVE_WINSOCK2_H@
@@ -435,16 +468,19 @@ _GL_WARN_ON_USE (getsockname, "getsockname is not always POSIX compliant - "
435# undef getsockopt 468# undef getsockopt
436# define getsockopt rpl_getsockopt 469# define getsockopt rpl_getsockopt
437# endif 470# endif
438_GL_FUNCDECL_RPL (getsockopt, int, (int fd, int level, int optname, 471_GL_FUNCDECL_RPL (getsockopt, int,
439 void *optval, socklen_t *optlen) 472 (int fd, int level, int optname,
440 _GL_ARG_NONNULL ((4, 5))); 473 void *restrict optval, socklen_t *restrict optlen)
441_GL_CXXALIAS_RPL (getsockopt, int, (int fd, int level, int optname, 474 _GL_ARG_NONNULL ((4, 5)));
442 void *optval, socklen_t *optlen)); 475_GL_CXXALIAS_RPL (getsockopt, int,
476 (int fd, int level, int optname,
477 void *restrict optval, socklen_t *restrict optlen));
443# else 478# else
444/* Need to cast, because on Solaris 10 systems, the fifth parameter is 479/* Need to cast, because on Solaris 10 systems, the fifth parameter is
445 void *optlen. */ 480 void *optlen. */
446_GL_CXXALIAS_SYS_CAST (getsockopt, int, (int fd, int level, int optname, 481_GL_CXXALIAS_SYS_CAST (getsockopt, int,
447 void *optval, socklen_t *optlen)); 482 (int fd, int level, int optname,
483 void *restrict optval, socklen_t *restrict optlen));
448# endif 484# endif
449_GL_CXXALIASWARN (getsockopt); 485_GL_CXXALIASWARN (getsockopt);
450#elif @HAVE_WINSOCK2_H@ 486#elif @HAVE_WINSOCK2_H@
@@ -491,7 +527,10 @@ _GL_FUNCDECL_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)
491 _GL_ARG_NONNULL ((2))); 527 _GL_ARG_NONNULL ((2)));
492_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)); 528_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
493# else 529# else
494_GL_CXXALIAS_SYS (recv, ssize_t, (int fd, void *buf, size_t len, int flags)); 530/* Need to cast, because on HP-UX 11.31 the return type may be
531 int,
532 depending on compiler options. */
533_GL_CXXALIAS_SYS_CAST (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
495# endif 534# endif
496_GL_CXXALIASWARN (recv); 535_GL_CXXALIASWARN (recv);
497#elif @HAVE_WINSOCK2_H@ 536#elif @HAVE_WINSOCK2_H@
@@ -517,8 +556,11 @@ _GL_FUNCDECL_RPL (send, ssize_t,
517_GL_CXXALIAS_RPL (send, ssize_t, 556_GL_CXXALIAS_RPL (send, ssize_t,
518 (int fd, const void *buf, size_t len, int flags)); 557 (int fd, const void *buf, size_t len, int flags));
519# else 558# else
520_GL_CXXALIAS_SYS (send, ssize_t, 559/* Need to cast, because on HP-UX 11.31 the return type may be
521 (int fd, const void *buf, size_t len, int flags)); 560 int,
561 depending on compiler options. */
562_GL_CXXALIAS_SYS_CAST (send, ssize_t,
563 (int fd, const void *buf, size_t len, int flags));
522# endif 564# endif
523_GL_CXXALIASWARN (send); 565_GL_CXXALIASWARN (send);
524#elif @HAVE_WINSOCK2_H@ 566#elif @HAVE_WINSOCK2_H@
@@ -539,18 +581,21 @@ _GL_WARN_ON_USE (send, "send is not always POSIX compliant - "
539# define recvfrom rpl_recvfrom 581# define recvfrom rpl_recvfrom
540# endif 582# endif
541_GL_FUNCDECL_RPL (recvfrom, ssize_t, 583_GL_FUNCDECL_RPL (recvfrom, ssize_t,
542 (int fd, void *buf, size_t len, int flags, 584 (int fd, void *restrict buf, size_t len, int flags,
543 struct sockaddr *from, socklen_t *fromlen) 585 struct sockaddr *restrict from,
586 socklen_t *restrict fromlen)
544 _GL_ARG_NONNULL ((2))); 587 _GL_ARG_NONNULL ((2)));
545_GL_CXXALIAS_RPL (recvfrom, ssize_t, 588_GL_CXXALIAS_RPL (recvfrom, ssize_t,
546 (int fd, void *buf, size_t len, int flags, 589 (int fd, void *restrict buf, size_t len, int flags,
547 struct sockaddr *from, socklen_t *fromlen)); 590 struct sockaddr *restrict from,
591 socklen_t *restrict fromlen));
548# else 592# else
549/* Need to cast, because on Solaris 10 systems, the sixth parameter is 593/* Need to cast, because on Solaris 10 systems, the sixth parameter is
550 void *fromlen. */ 594 void *fromlen. */
551_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t, 595_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t,
552 (int fd, void *buf, size_t len, int flags, 596 (int fd, void *restrict buf, size_t len, int flags,
553 struct sockaddr *from, socklen_t *fromlen)); 597 struct sockaddr *restrict from,
598 socklen_t *restrict fromlen));
554# endif 599# endif
555_GL_CXXALIASWARN (recvfrom); 600_GL_CXXALIASWARN (recvfrom);
556#elif @HAVE_WINSOCK2_H@ 601#elif @HAVE_WINSOCK2_H@
@@ -654,7 +699,7 @@ _GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX compliant - "
654 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) 699 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
655 and O_TEXT, O_BINARY (defined in "binary-io.h"). 700 and O_TEXT, O_BINARY (defined in "binary-io.h").
656 See also the Linux man page at 701 See also the Linux man page at
657 <http://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */ 702 <https://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */
658# if @HAVE_ACCEPT4@ 703# if @HAVE_ACCEPT4@
659# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 704# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
660# define accept4 rpl_accept4 705# define accept4 rpl_accept4