sys_socket.in.h 24 KB

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