1 /* Provide a sys/socket header file for systems lacking it (read: MinGW)
2    and for systems where it is incomplete.
3    Copyright (C) 2005-2020 Free Software Foundation, Inc.
4    Written by Simon Josefsson.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
18 
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
21    platforms where <sys/socket.h> does not provide all necessary definitions.
22    It is intended to provide definitions and prototypes needed by an
23    application.  */
24 
25 #if __GNUC__ >= 3
26 @PRAGMA_SYSTEM_HEADER@
27 #endif
28 @PRAGMA_COLUMNS@
29 
30 #if defined _GL_ALREADY_INCLUDING_SYS_SOCKET_H
31 /* Special invocation convention:
32    - On Cygwin 1.5.x we have a sequence of nested includes
33      <sys/socket.h> -> <cygwin/socket.h> -> <asm/socket.h> -> <cygwin/if.h>,
34      and the latter includes <sys/socket.h>.  In this situation, the functions
35      are not yet declared, therefore we cannot provide the C++ aliases.  */
36 
37 #@INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
38 
39 #else
40 /* Normal invocation convention.  */
41 
42 #ifndef _@GUARD_PREFIX@_SYS_SOCKET_H
43 
44 #if @HAVE_SYS_SOCKET_H@
45 
46 # define _GL_ALREADY_INCLUDING_SYS_SOCKET_H
47 
48 /* On many platforms, <sys/socket.h> assumes prior inclusion of
49    <sys/types.h>.  */
50 # include <sys/types.h>
51 
52 /* On FreeBSD 6.4, <sys/socket.h> defines some macros that assume that NULL
53    is defined.  */
54 # include <stddef.h>
55 
56 /* The include_next requires a split double-inclusion guard.  */
57 # @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
58 
59 # undef _GL_ALREADY_INCLUDING_SYS_SOCKET_H
60 
61 #endif
62 
63 #ifndef _@GUARD_PREFIX@_SYS_SOCKET_H
64 #define _@GUARD_PREFIX@_SYS_SOCKET_H
65 
66 #ifndef _GL_INLINE_HEADER_BEGIN
67  #error "Please include config.h first."
68 #endif
69 _GL_INLINE_HEADER_BEGIN
70 #ifndef _GL_SYS_SOCKET_INLINE
71 # define _GL_SYS_SOCKET_INLINE _GL_INLINE
72 #endif
73 
74 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
75 
76 /* The definition of _GL_ARG_NONNULL is copied here.  */
77 
78 /* The definition of _GL_WARN_ON_USE is copied here.  */
79 
80 #if !@HAVE_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
84 typedef unsigned short  sa_family_t;
85 #  else
86 typedef unsigned char   sa_family_t;
87 #  endif
88 #  define GNULIB_defined_sa_family_t 1
89 # endif
90 #endif
91 
92 #if @HAVE_STRUCT_SOCKADDR_STORAGE@
93 /* Make the 'struct sockaddr_storage' field 'ss_family' visible on AIX 7.1.  */
94 # if !@HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY@
95 #  ifndef ss_family
96 #   define ss_family __ss_family
97 #  endif
98 # endif
99 #else
100 # include <stdalign.h>
101 /* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
102    2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
103 # define __ss_aligntype unsigned long int
104 # define _SS_SIZE 256
105 # define _SS_PADSIZE \
106     (_SS_SIZE - ((sizeof (sa_family_t) >= alignof (__ss_aligntype)      \
107                   ? sizeof (sa_family_t)                                \
108                   : alignof (__ss_aligntype))                           \
109                  + sizeof (__ss_aligntype)))
110 
111 # if !GNULIB_defined_struct_sockaddr_storage
112 struct sockaddr_storage
113 {
114   sa_family_t ss_family;      /* Address family, etc.  */
115   __ss_aligntype __ss_align;  /* Force desired alignment.  */
116   char __ss_padding[_SS_PADSIZE];
117 };
118 #  define GNULIB_defined_struct_sockaddr_storage 1
119 # endif
120 
121 #endif
122 
123 /* Get struct iovec.  */
124 /* But avoid namespace pollution on glibc systems.  */
125 #if ! defined __GLIBC__
126 # include <sys/uio.h>
127 #endif
128 
129 #if @HAVE_SYS_SOCKET_H@
130 
131 /* A platform that has <sys/socket.h>.  */
132 
133 /* For shutdown().  */
134 # if !defined SHUT_RD
135 #  define SHUT_RD 0
136 # endif
137 # if !defined SHUT_WR
138 #  define SHUT_WR 1
139 # endif
140 # if !defined SHUT_RDWR
141 #  define SHUT_RDWR 2
142 # endif
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 
153 #else
154 
155 # ifdef __CYGWIN__
156 #  error "Cygwin does have a sys/socket.h, doesn't it?!?"
157 # endif
158 
159 /* A platform that lacks <sys/socket.h>.
160 
161    Currently only MinGW is supported.  See the gnulib manual regarding
162    Windows sockets.  MinGW has the header files winsock2.h and
163    ws2tcpip.h that declare the sys/socket.h definitions we need.  Note
164    that you can influence which definitions you get by setting the
165    WINVER symbol before including these two files.  For example,
166    getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
167    symbol is set indirectly through WINVER).  You can set this by
168    adding AC_DEFINE(WINVER, 0x0501) to configure.ac.  Note that your
169    code may not run on older Windows releases then.  My Windows 2000
170    box was not able to run the code, for example.  The situation is
171    slightly confusing because
172    <https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
173    suggests that getaddrinfo should be available on all Windows
174    releases. */
175 
176 # if @HAVE_WINSOCK2_H@
177 #  include <winsock2.h>
178 # endif
179 # if @HAVE_WS2TCPIP_H@
180 #  include <ws2tcpip.h>
181 # endif
182 
183 /* For shutdown(). */
184 # if !defined SHUT_RD && defined SD_RECEIVE
185 #  define SHUT_RD SD_RECEIVE
186 # endif
187 # if !defined SHUT_WR && defined SD_SEND
188 #  define SHUT_WR SD_SEND
189 # endif
190 # if !defined SHUT_RDWR && defined SD_BOTH
191 #  define SHUT_RDWR SD_BOTH
192 # endif
193 
194 # if @HAVE_WINSOCK2_H@
195 /* Include headers needed by the emulation code.  */
196 #  include <sys/types.h>
197 #  include <io.h>
198 
199 #  if !GNULIB_defined_socklen_t
200 typedef int socklen_t;
201 #   define GNULIB_defined_socklen_t 1
202 #  endif
203 
204 # endif
205 
206 /* Rudimentary 'struct msghdr'; this works as long as you don't try to
207    access msg_control or msg_controllen.  */
208 struct msghdr {
209   void *msg_name;
210   socklen_t msg_namelen;
211   struct iovec *msg_iov;
212   int msg_iovlen;
213   int msg_flags;
214 };
215 
216 #endif
217 
218 /* Ensure SO_REUSEPORT is defined.  */
219 /* For the subtle differences between SO_REUSEPORT and SO_REUSEADDR, see
220    https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t
221    and https://lwn.net/Articles/542629/
222  */
223 #ifndef SO_REUSEPORT
224 # define SO_REUSEPORT SO_REUSEADDR
225 #endif
226 
227 /* Fix some definitions from <winsock2.h>.  */
228 
229 #if @HAVE_WINSOCK2_H@
230 
231 # if !GNULIB_defined_rpl_fd_isset
232 
233 /* Re-define FD_ISSET to avoid a WSA call while we are not using
234    network sockets.  */
235 _GL_SYS_SOCKET_INLINE int
236 rpl_fd_isset (SOCKET fd, fd_set * set)
237 {
238   u_int i;
239   if (set == NULL)
240     return 0;
241 
242   for (i = 0; i < set->fd_count; i++)
243     if (set->fd_array[i] == fd)
244       return 1;
245 
246   return 0;
247 }
248 
249 #  define GNULIB_defined_rpl_fd_isset 1
250 # endif
251 
252 # undef FD_ISSET
253 # define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
254 
255 #endif
256 
257 /* Hide some function declarations from <winsock2.h>.  */
258 
259 #if @HAVE_WINSOCK2_H@
260 # if !defined _@GUARD_PREFIX@_UNISTD_H
261 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
262 #   undef close
263 #   define close close_used_without_including_unistd_h
264 #  else
265     _GL_WARN_ON_USE (close,
266                      "close() used without including <unistd.h>");
267 #  endif
268 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
269 #   undef gethostname
270 #   define gethostname gethostname_used_without_including_unistd_h
271 #  else
272     _GL_WARN_ON_USE (gethostname,
273                      "gethostname() used without including <unistd.h>");
274 #  endif
275 # endif
276 # if !defined _@GUARD_PREFIX@_SYS_SELECT_H
277 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
278 #   undef select
279 #   define select select_used_without_including_sys_select_h
280 #  else
281     _GL_WARN_ON_USE (select,
282                      "select() used without including <sys/select.h>");
283 #  endif
284 # endif
285 #endif
286 
287 /* Wrap everything else to use libc file descriptors for sockets.  */
288 
289 #if @GNULIB_SOCKET@
290 # if @HAVE_WINSOCK2_H@
291 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
292 #   undef socket
293 #   define socket rpl_socket
294 #  endif
295 _GL_FUNCDECL_RPL (socket, int, (int domain, int type, int protocol));
296 _GL_CXXALIAS_RPL (socket, int, (int domain, int type, int protocol));
297 # else
298 _GL_CXXALIAS_SYS (socket, int, (int domain, int type, int protocol));
299 # endif
300 _GL_CXXALIASWARN (socket);
301 #elif @HAVE_WINSOCK2_H@
302 # undef socket
303 # define socket socket_used_without_requesting_gnulib_module_socket
304 #elif defined GNULIB_POSIXCHECK
305 # undef socket
306 # if HAVE_RAW_DECL_SOCKET
307 _GL_WARN_ON_USE (socket, "socket is not always POSIX compliant - "
308                  "use gnulib module socket for portability");
309 # endif
310 #endif
311 
312 #if @GNULIB_CONNECT@
313 # if @HAVE_WINSOCK2_H@
314 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
315 #   undef connect
316 #   define connect rpl_connect
317 #  endif
318 _GL_FUNCDECL_RPL (connect, int,
319                   (int fd, const struct sockaddr *addr, socklen_t addrlen)
320                   _GL_ARG_NONNULL ((2)));
321 _GL_CXXALIAS_RPL (connect, int,
322                   (int fd, const struct sockaddr *addr, socklen_t addrlen));
323 # else
324 /* Need to cast, because on NonStop Kernel, the third parameter is
325                                                      size_t addrlen.  */
326 _GL_CXXALIAS_SYS_CAST (connect, int,
327                        (int fd,
328                         const struct sockaddr *addr, socklen_t addrlen));
329 # endif
330 _GL_CXXALIASWARN (connect);
331 #elif @HAVE_WINSOCK2_H@
332 # undef connect
333 # define connect socket_used_without_requesting_gnulib_module_connect
334 #elif defined GNULIB_POSIXCHECK
335 # undef connect
336 # if HAVE_RAW_DECL_CONNECT
337 _GL_WARN_ON_USE (connect, "connect is not always POSIX compliant - "
338                  "use gnulib module connect for portability");
339 # endif
340 #endif
341 
342 #if @GNULIB_ACCEPT@
343 # if @HAVE_WINSOCK2_H@
344 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
345 #   undef accept
346 #   define accept rpl_accept
347 #  endif
348 _GL_FUNCDECL_RPL (accept, int,
349                   (int fd,
350                    struct sockaddr *restrict addr,
351                    socklen_t *restrict addrlen));
352 _GL_CXXALIAS_RPL (accept, int,
353                   (int fd,
354                    struct sockaddr *restrict addr,
355                    socklen_t *restrict addrlen));
356 # else
357 /* Need to cast, because on Solaris 10 systems, the third parameter is
358                         void *addrlen.  */
359 _GL_CXXALIAS_SYS_CAST (accept, int,
360                        (int fd,
361                         struct sockaddr *restrict addr,
362                         socklen_t *restrict addrlen));
363 # endif
364 _GL_CXXALIASWARN (accept);
365 #elif @HAVE_WINSOCK2_H@
366 # undef accept
367 # define accept accept_used_without_requesting_gnulib_module_accept
368 #elif defined GNULIB_POSIXCHECK
369 # undef accept
370 # if HAVE_RAW_DECL_ACCEPT
371 _GL_WARN_ON_USE (accept, "accept is not always POSIX compliant - "
372                  "use gnulib module accept for portability");
373 # endif
374 #endif
375 
376 #if @GNULIB_BIND@
377 # if @HAVE_WINSOCK2_H@
378 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
379 #   undef bind
380 #   define bind rpl_bind
381 #  endif
382 _GL_FUNCDECL_RPL (bind, int,
383                   (int fd, const struct sockaddr *addr, socklen_t addrlen)
384                   _GL_ARG_NONNULL ((2)));
385 _GL_CXXALIAS_RPL (bind, int,
386                   (int fd, const struct sockaddr *addr, socklen_t addrlen));
387 # else
388 /* Need to cast, because on NonStop Kernel, the third parameter is
389                                                      size_t addrlen.  */
390 _GL_CXXALIAS_SYS_CAST (bind, int,
391                        (int fd,
392                         const struct sockaddr *addr, socklen_t addrlen));
393 # endif
394 _GL_CXXALIASWARN (bind);
395 #elif @HAVE_WINSOCK2_H@
396 # undef bind
397 # define bind bind_used_without_requesting_gnulib_module_bind
398 #elif defined GNULIB_POSIXCHECK
399 # undef bind
400 # if HAVE_RAW_DECL_BIND
401 _GL_WARN_ON_USE (bind, "bind is not always POSIX compliant - "
402                  "use gnulib module bind for portability");
403 # endif
404 #endif
405 
406 #if @GNULIB_GETPEERNAME@
407 # if @HAVE_WINSOCK2_H@
408 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
409 #   undef getpeername
410 #   define getpeername rpl_getpeername
411 #  endif
412 _GL_FUNCDECL_RPL (getpeername, int,
413                   (int fd, struct sockaddr *restrict addr,
414                    socklen_t *restrict addrlen)
415                   _GL_ARG_NONNULL ((2, 3)));
416 _GL_CXXALIAS_RPL (getpeername, int,
417                   (int fd, struct sockaddr *restrict addr,
418                    socklen_t *restrict addrlen));
419 # else
420 /* Need to cast, because on Solaris 10 systems, the third parameter is
421                         void *addrlen.  */
422 _GL_CXXALIAS_SYS_CAST (getpeername, int,
423                        (int fd, struct sockaddr *restrict addr,
424                         socklen_t *restrict addrlen));
425 # endif
426 _GL_CXXALIASWARN (getpeername);
427 #elif @HAVE_WINSOCK2_H@
428 # undef getpeername
429 # define getpeername getpeername_used_without_requesting_gnulib_module_getpeername
430 #elif defined GNULIB_POSIXCHECK
431 # undef getpeername
432 # if HAVE_RAW_DECL_GETPEERNAME
433 _GL_WARN_ON_USE (getpeername, "getpeername is not always POSIX compliant - "
434                  "use gnulib module getpeername for portability");
435 # endif
436 #endif
437 
438 #if @GNULIB_GETSOCKNAME@
439 # if @HAVE_WINSOCK2_H@
440 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
441 #   undef getsockname
442 #   define getsockname rpl_getsockname
443 #  endif
444 _GL_FUNCDECL_RPL (getsockname, int,
445                   (int fd, struct sockaddr *restrict addr,
446                    socklen_t *restrict addrlen)
447                   _GL_ARG_NONNULL ((2, 3)));
448 _GL_CXXALIAS_RPL (getsockname, int,
449                   (int fd, struct sockaddr *restrict addr,
450                    socklen_t *restrict addrlen));
451 # else
452 /* Need to cast, because on Solaris 10 systems, the third parameter is
453                         void *addrlen.  */
454 _GL_CXXALIAS_SYS_CAST (getsockname, int,
455                        (int fd, struct sockaddr *restrict addr,
456                         socklen_t *restrict addrlen));
457 # endif
458 _GL_CXXALIASWARN (getsockname);
459 #elif @HAVE_WINSOCK2_H@
460 # undef getsockname
461 # define getsockname getsockname_used_without_requesting_gnulib_module_getsockname
462 #elif defined GNULIB_POSIXCHECK
463 # undef getsockname
464 # if HAVE_RAW_DECL_GETSOCKNAME
465 _GL_WARN_ON_USE (getsockname, "getsockname is not always POSIX compliant - "
466                  "use gnulib module getsockname for portability");
467 # endif
468 #endif
469 
470 #if @GNULIB_GETSOCKOPT@
471 # if @HAVE_WINSOCK2_H@
472 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
473 #   undef getsockopt
474 #   define getsockopt rpl_getsockopt
475 #  endif
476 _GL_FUNCDECL_RPL (getsockopt, int,
477                   (int fd, int level, int optname,
478                    void *restrict optval, socklen_t *restrict optlen)
479                   _GL_ARG_NONNULL ((4, 5)));
480 _GL_CXXALIAS_RPL (getsockopt, int,
481                   (int fd, int level, int optname,
482                    void *restrict optval, socklen_t *restrict optlen));
483 # else
484 /* Need to cast, because on Solaris 10 systems, the fifth parameter is
485                                                        void *optlen.  */
486 _GL_CXXALIAS_SYS_CAST (getsockopt, int,
487                        (int fd, int level, int optname,
488                         void *restrict optval, socklen_t *restrict optlen));
489 # endif
490 _GL_CXXALIASWARN (getsockopt);
491 #elif @HAVE_WINSOCK2_H@
492 # undef getsockopt
493 # define getsockopt getsockopt_used_without_requesting_gnulib_module_getsockopt
494 #elif defined GNULIB_POSIXCHECK
495 # undef getsockopt
496 # if HAVE_RAW_DECL_GETSOCKOPT
497 _GL_WARN_ON_USE (getsockopt, "getsockopt is not always POSIX compliant - "
498                  "use gnulib module getsockopt for portability");
499 # endif
500 #endif
501 
502 #if @GNULIB_LISTEN@
503 # if @HAVE_WINSOCK2_H@
504 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
505 #   undef listen
506 #   define listen rpl_listen
507 #  endif
508 _GL_FUNCDECL_RPL (listen, int, (int fd, int backlog));
509 _GL_CXXALIAS_RPL (listen, int, (int fd, int backlog));
510 # else
511 _GL_CXXALIAS_SYS (listen, int, (int fd, int backlog));
512 # endif
513 _GL_CXXALIASWARN (listen);
514 #elif @HAVE_WINSOCK2_H@
515 # undef listen
516 # define listen listen_used_without_requesting_gnulib_module_listen
517 #elif defined GNULIB_POSIXCHECK
518 # undef listen
519 # if HAVE_RAW_DECL_LISTEN
520 _GL_WARN_ON_USE (listen, "listen is not always POSIX compliant - "
521                  "use gnulib module listen for portability");
522 # endif
523 #endif
524 
525 #if @GNULIB_RECV@
526 # if @HAVE_WINSOCK2_H@
527 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
528 #   undef recv
529 #   define recv rpl_recv
530 #  endif
531 _GL_FUNCDECL_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)
532                                  _GL_ARG_NONNULL ((2)));
533 _GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
534 # else
535 /* Need to cast, because on HP-UX 11.31 the return type may be
536                              int,
537    depending on compiler options.  */
538 _GL_CXXALIAS_SYS_CAST (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
539 # endif
540 _GL_CXXALIASWARN (recv);
541 #elif @HAVE_WINSOCK2_H@
542 # undef recv
543 # define recv recv_used_without_requesting_gnulib_module_recv
544 #elif defined GNULIB_POSIXCHECK
545 # undef recv
546 # if HAVE_RAW_DECL_RECV
547 _GL_WARN_ON_USE (recv, "recv is not always POSIX compliant - "
548                  "use gnulib module recv for portability");
549 # endif
550 #endif
551 
552 #if @GNULIB_SEND@
553 # if @HAVE_WINSOCK2_H@
554 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
555 #   undef send
556 #   define send rpl_send
557 #  endif
558 _GL_FUNCDECL_RPL (send, ssize_t,
559                   (int fd, const void *buf, size_t len, int flags)
560                   _GL_ARG_NONNULL ((2)));
561 _GL_CXXALIAS_RPL (send, ssize_t,
562                   (int fd, const void *buf, size_t len, int flags));
563 # else
564 /* Need to cast, because on HP-UX 11.31 the return type may be
565                              int,
566    depending on compiler options.  */
567 _GL_CXXALIAS_SYS_CAST (send, ssize_t,
568                        (int fd, const void *buf, size_t len, int flags));
569 # endif
570 _GL_CXXALIASWARN (send);
571 #elif @HAVE_WINSOCK2_H@
572 # undef send
573 # define send send_used_without_requesting_gnulib_module_send
574 #elif defined GNULIB_POSIXCHECK
575 # undef send
576 # if HAVE_RAW_DECL_SEND
577 _GL_WARN_ON_USE (send, "send is not always POSIX compliant - "
578                  "use gnulib module send for portability");
579 # endif
580 #endif
581 
582 #if @GNULIB_RECVFROM@
583 # if @HAVE_WINSOCK2_H@
584 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
585 #   undef recvfrom
586 #   define recvfrom rpl_recvfrom
587 #  endif
588 _GL_FUNCDECL_RPL (recvfrom, ssize_t,
589                   (int fd, void *restrict buf, size_t len, int flags,
590                    struct sockaddr *restrict from,
591                    socklen_t *restrict fromlen)
592                   _GL_ARG_NONNULL ((2)));
593 _GL_CXXALIAS_RPL (recvfrom, ssize_t,
594                   (int fd, void *restrict buf, size_t len, int flags,
595                    struct sockaddr *restrict from,
596                    socklen_t *restrict fromlen));
597 # else
598 /* Need to cast, because on Solaris 10 systems, the sixth parameter is
599                                                void *fromlen.  */
600 _GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t,
601                        (int fd, void *restrict buf, size_t len, int flags,
602                         struct sockaddr *restrict from,
603                         socklen_t *restrict fromlen));
604 # endif
605 _GL_CXXALIASWARN (recvfrom);
606 #elif @HAVE_WINSOCK2_H@
607 # undef recvfrom
608 # define recvfrom recvfrom_used_without_requesting_gnulib_module_recvfrom
609 #elif defined GNULIB_POSIXCHECK
610 # undef recvfrom
611 # if HAVE_RAW_DECL_RECVFROM
612 _GL_WARN_ON_USE (recvfrom, "recvfrom is not always POSIX compliant - "
613                  "use gnulib module recvfrom for portability");
614 # endif
615 #endif
616 
617 #if @GNULIB_SENDTO@
618 # if @HAVE_WINSOCK2_H@
619 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
620 #   undef sendto
621 #   define sendto rpl_sendto
622 #  endif
623 _GL_FUNCDECL_RPL (sendto, ssize_t,
624                   (int fd, const void *buf, size_t len, int flags,
625                    const struct sockaddr *to, socklen_t tolen)
626                   _GL_ARG_NONNULL ((2)));
627 _GL_CXXALIAS_RPL (sendto, ssize_t,
628                   (int fd, const void *buf, size_t len, int flags,
629                    const struct sockaddr *to, socklen_t tolen));
630 # else
631 /* Need to cast, because on NonStop Kernel, the sixth parameter is
632                                                    size_t tolen.  */
633 _GL_CXXALIAS_SYS_CAST (sendto, ssize_t,
634                        (int fd, const void *buf, size_t len, int flags,
635                         const struct sockaddr *to, socklen_t tolen));
636 # endif
637 _GL_CXXALIASWARN (sendto);
638 #elif @HAVE_WINSOCK2_H@
639 # undef sendto
640 # define sendto sendto_used_without_requesting_gnulib_module_sendto
641 #elif defined GNULIB_POSIXCHECK
642 # undef sendto
643 # if HAVE_RAW_DECL_SENDTO
644 _GL_WARN_ON_USE (sendto, "sendto is not always POSIX compliant - "
645                  "use gnulib module sendto for portability");
646 # endif
647 #endif
648 
649 #if @GNULIB_SETSOCKOPT@
650 # if @HAVE_WINSOCK2_H@
651 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
652 #   undef setsockopt
653 #   define setsockopt rpl_setsockopt
654 #  endif
655 _GL_FUNCDECL_RPL (setsockopt, int, (int fd, int level, int optname,
656                                     const void * optval, socklen_t optlen)
657                                    _GL_ARG_NONNULL ((4)));
658 _GL_CXXALIAS_RPL (setsockopt, int, (int fd, int level, int optname,
659                                     const void * optval, socklen_t optlen));
660 # else
661 /* Need to cast, because on NonStop Kernel, the fifth parameter is
662                                              size_t optlen.  */
663 _GL_CXXALIAS_SYS_CAST (setsockopt, int,
664                        (int fd, int level, int optname,
665                         const void * optval, socklen_t optlen));
666 # endif
667 _GL_CXXALIASWARN (setsockopt);
668 #elif @HAVE_WINSOCK2_H@
669 # undef setsockopt
670 # define setsockopt setsockopt_used_without_requesting_gnulib_module_setsockopt
671 #elif defined GNULIB_POSIXCHECK
672 # undef setsockopt
673 # if HAVE_RAW_DECL_SETSOCKOPT
674 _GL_WARN_ON_USE (setsockopt, "setsockopt is not always POSIX compliant - "
675                  "use gnulib module setsockopt for portability");
676 # endif
677 #endif
678 
679 #if @GNULIB_SHUTDOWN@
680 # if @HAVE_WINSOCK2_H@
681 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
682 #   undef shutdown
683 #   define shutdown rpl_shutdown
684 #  endif
685 _GL_FUNCDECL_RPL (shutdown, int, (int fd, int how));
686 _GL_CXXALIAS_RPL (shutdown, int, (int fd, int how));
687 # else
688 _GL_CXXALIAS_SYS (shutdown, int, (int fd, int how));
689 # endif
690 _GL_CXXALIASWARN (shutdown);
691 #elif @HAVE_WINSOCK2_H@
692 # undef shutdown
693 # define shutdown shutdown_used_without_requesting_gnulib_module_shutdown
694 #elif defined GNULIB_POSIXCHECK
695 # undef shutdown
696 # if HAVE_RAW_DECL_SHUTDOWN
697 _GL_WARN_ON_USE (shutdown, "shutdown is not always POSIX compliant - "
698                  "use gnulib module shutdown for portability");
699 # endif
700 #endif
701 
702 #if @GNULIB_ACCEPT4@
703 /* Accept a connection on a socket, with specific opening flags.
704    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
705    and O_TEXT, O_BINARY (defined in "binary-io.h").
706    See also the Linux man page at
707    <https://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>.  */
708 # if @HAVE_ACCEPT4@
709 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
710 #   define accept4 rpl_accept4
711 #  endif
712 _GL_FUNCDECL_RPL (accept4, int,
713                   (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
714                    int flags));
715 _GL_CXXALIAS_RPL (accept4, int,
716                   (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
717                    int flags));
718 # else
719 _GL_FUNCDECL_SYS (accept4, int,
720                   (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
721                    int flags));
722 _GL_CXXALIAS_SYS (accept4, int,
723                   (int sockfd, struct sockaddr *addr, socklen_t *addrlen,
724                    int flags));
725 # endif
726 _GL_CXXALIASWARN (accept4);
727 #elif defined GNULIB_POSIXCHECK
728 # undef accept4
729 # if HAVE_RAW_DECL_ACCEPT4
730 _GL_WARN_ON_USE (accept4, "accept4 is unportable - "
731                  "use gnulib module accept4 for portability");
732 # endif
733 #endif
734 
735 _GL_INLINE_HEADER_END
736 
737 #endif /* _@GUARD_PREFIX@_SYS_SOCKET_H */
738 #endif /* _@GUARD_PREFIX@_SYS_SOCKET_H */
739 #endif
740