sys_socket.in.h 24 KB

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