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