modernc.org/cc@v1.0.1/v2/headers/linux_arm/usr/include/arm-linux-gnueabihf/sys/socket.h (about) 1 /* Declarations of socket constants, types, and functions. 2 Copyright (C) 1991-2016 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 The GNU C Library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, see 17 <http://www.gnu.org/licenses/>. */ 18 19 #ifndef _SYS_SOCKET_H 20 #define _SYS_SOCKET_H 1 21 22 #include <features.h> 23 24 __BEGIN_DECLS 25 #include <sys/uio.h> 26 #define __need_size_t 27 #include <stddef.h> 28 #ifdef __USE_GNU 29 /* Get the __sigset_t definition. */ 30 #include <bits/sigset.h> 31 #endif 32 /* This operating system-specific header file defines the SOCK_*, PF_*, 33 AF_*, MSG_*, SOL_*, and SO_* constants, and the `struct sockaddr', 34 `struct msghdr', and `struct linger' types. */ 35 #include <bits/socket.h> 36 #ifdef __USE_MISC 37 /* This is the 4.3 BSD `struct sockaddr' format, which is used as wire 38 format in the grotty old 4.3 `talk' protocol. */ 39 struct osockaddr { 40 unsigned short int sa_family; 41 unsigned char sa_data[14]; 42 }; 43 #endif 44 45 /* The following constants should be used for the second parameter of 46 `shutdown'. */ 47 enum { 48 SHUT_RD = 0, /* No more receptions. */ 49 #define SHUT_RD SHUT_RD 50 SHUT_WR, /* No more transmissions. */ 51 #define SHUT_WR SHUT_WR 52 SHUT_RDWR /* No more receptions or transmissions. */ 53 #define SHUT_RDWR SHUT_RDWR 54 }; 55 56 /* This is the type we use for generic socket address arguments. 57 58 With GCC 2.7 and later, the funky union causes redeclarations or 59 uses with any of the listed types to be allowed without complaint. 60 G++ 2.7 does not support transparent unions so there we want the 61 old-style declaration, too. */ 62 #if defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU 63 #define __SOCKADDR_ARG struct sockaddr *__restrict 64 #define __CONST_SOCKADDR_ARG const struct sockaddr * 65 #else 66 /* Add more `struct sockaddr_AF' types here as necessary. 67 These are all the ones I found on NetBSD and Linux. */ 68 #define __SOCKADDR_ALLTYPES \ 69 __SOCKADDR_ONETYPE (sockaddr) \ 70 __SOCKADDR_ONETYPE (sockaddr_at) \ 71 __SOCKADDR_ONETYPE (sockaddr_ax25) \ 72 __SOCKADDR_ONETYPE (sockaddr_dl) \ 73 __SOCKADDR_ONETYPE (sockaddr_eon) \ 74 __SOCKADDR_ONETYPE (sockaddr_in) \ 75 __SOCKADDR_ONETYPE (sockaddr_in6) \ 76 __SOCKADDR_ONETYPE (sockaddr_inarp) \ 77 __SOCKADDR_ONETYPE (sockaddr_ipx) \ 78 __SOCKADDR_ONETYPE (sockaddr_iso) \ 79 __SOCKADDR_ONETYPE (sockaddr_ns) \ 80 __SOCKADDR_ONETYPE (sockaddr_un) \ 81 __SOCKADDR_ONETYPE (sockaddr_x25) 82 83 #define __SOCKADDR_ONETYPE(type) struct type *__restrict __##type##__; 84 typedef union { 85 __SOCKADDR_ALLTYPES} __SOCKADDR_ARG __attribute__ ((__transparent_union__)); 86 #undef __SOCKADDR_ONETYPE 87 #define __SOCKADDR_ONETYPE(type) const struct type *__restrict __##type##__; 88 typedef union { 89 __SOCKADDR_ALLTYPES} __CONST_SOCKADDR_ARG __attribute__ ((__transparent_union__)); 90 #undef __SOCKADDR_ONETYPE 91 #endif 92 93 #ifdef __USE_GNU 94 /* For `recvmmsg' and `sendmmsg'. */ 95 struct mmsghdr { 96 struct msghdr msg_hdr; /* Actual message header. */ 97 unsigned int msg_len; /* Number of received or sent bytes for the 98 entry. */ 99 }; 100 #endif 101 102 /* Create a new socket of type TYPE in domain DOMAIN, using 103 protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically. 104 Returns a file descriptor for the new socket, or -1 for errors. */ 105 extern int socket(int __domain, int __type, int __protocol) __THROW; 106 107 /* Create two new sockets, of type TYPE in domain DOMAIN and using 108 protocol PROTOCOL, which are connected to each other, and put file 109 descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero, 110 one will be chosen automatically. Returns 0 on success, -1 for errors. */ 111 extern int socketpair(int __domain, int __type, int __protocol, int __fds[2]) __THROW; 112 113 /* Give the socket FD the local address ADDR (which is LEN bytes long). */ 114 extern int bind(int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) __THROW; 115 116 /* Put the local address of FD into *ADDR and its length in *LEN. */ 117 extern int getsockname(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len) __THROW; 118 119 /* Open a connection on socket FD to peer at ADDR (which LEN bytes long). 120 For connectionless socket types, just set the default address to send to 121 and the only address from which to accept transmissions. 122 Return 0 on success, -1 for errors. 123 124 This function is a cancellation point and therefore not marked with 125 __THROW. */ 126 extern int connect(int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len); 127 128 /* Put the address of the peer connected to socket FD into *ADDR 129 (which is *LEN bytes long), and its actual length into *LEN. */ 130 extern int getpeername(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len) __THROW; 131 132 /* Send N bytes of BUF to socket FD. Returns the number sent or -1. 133 134 This function is a cancellation point and therefore not marked with 135 __THROW. */ 136 extern ssize_t send(int __fd, const void *__buf, size_t __n, int __flags); 137 138 /* Read N bytes into BUF from socket FD. 139 Returns the number read or -1 for errors. 140 141 This function is a cancellation point and therefore not marked with 142 __THROW. */ 143 extern ssize_t recv(int __fd, void *__buf, size_t __n, int __flags); 144 145 /* Send N bytes of BUF on socket FD to peer at address ADDR (which is 146 ADDR_LEN bytes long). Returns the number sent, or -1 for errors. 147 148 This function is a cancellation point and therefore not marked with 149 __THROW. */ 150 extern ssize_t sendto(int __fd, const void *__buf, size_t __n, int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len); 151 152 /* Read N bytes into BUF through socket FD. 153 If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of 154 the sender, and store the actual size of the address in *ADDR_LEN. 155 Returns the number of bytes read or -1 for errors. 156 157 This function is a cancellation point and therefore not marked with 158 __THROW. */ 159 extern ssize_t recvfrom(int __fd, void *__restrict __buf, size_t __n, int __flags, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len); 160 161 /* Send a message described MESSAGE on socket FD. 162 Returns the number of bytes sent, or -1 for errors. 163 164 This function is a cancellation point and therefore not marked with 165 __THROW. */ 166 extern ssize_t sendmsg(int __fd, const struct msghdr *__message, int __flags); 167 168 #ifdef __USE_GNU 169 /* Send a VLEN messages as described by VMESSAGES to socket FD. 170 Returns the number of datagrams successfully written or -1 for errors. 171 172 This function is a cancellation point and therefore not marked with 173 __THROW. */ 174 extern int sendmmsg(int __fd, struct mmsghdr *__vmessages, unsigned int __vlen, int __flags); 175 #endif 176 177 /* Receive a message as described by MESSAGE from socket FD. 178 Returns the number of bytes read or -1 for errors. 179 180 This function is a cancellation point and therefore not marked with 181 __THROW. */ 182 extern ssize_t recvmsg(int __fd, struct msghdr *__message, int __flags); 183 184 #ifdef __USE_GNU 185 /* Receive up to VLEN messages as described by VMESSAGES from socket FD. 186 Returns the number of messages received or -1 for errors. 187 188 This function is a cancellation point and therefore not marked with 189 __THROW. */ 190 extern int recvmmsg(int __fd, struct mmsghdr *__vmessages, unsigned int __vlen, int __flags, struct timespec *__tmo); 191 #endif 192 193 /* Put the current value for socket FD's option OPTNAME at protocol level LEVEL 194 into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's 195 actual length. Returns 0 on success, -1 for errors. */ 196 extern int getsockopt(int __fd, int __level, int __optname, void *__restrict __optval, socklen_t * __restrict __optlen) __THROW; 197 198 /* Set socket FD's option OPTNAME at protocol level LEVEL 199 to *OPTVAL (which is OPTLEN bytes long). 200 Returns 0 on success, -1 for errors. */ 201 extern int setsockopt(int __fd, int __level, int __optname, const void *__optval, socklen_t __optlen) __THROW; 202 203 /* Prepare to accept connections on socket FD. 204 N connection requests will be queued before further requests are refused. 205 Returns 0 on success, -1 for errors. */ 206 extern int listen(int __fd, int __n) __THROW; 207 208 /* Await a connection on socket FD. 209 When a connection arrives, open a new socket to communicate with it, 210 set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting 211 peer and *ADDR_LEN to the address's actual length, and return the 212 new socket's descriptor, or -1 for errors. 213 214 This function is a cancellation point and therefore not marked with 215 __THROW. */ 216 extern int accept(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len); 217 218 #ifdef __USE_GNU 219 /* Similar to 'accept' but takes an additional parameter to specify flags. 220 221 This function is a cancellation point and therefore not marked with 222 __THROW. */ 223 extern int accept4(int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len, int __flags); 224 #endif 225 226 /* Shut down all or part of the connection open on socket FD. 227 HOW determines what to shut down: 228 SHUT_RD = No more receptions; 229 SHUT_WR = No more transmissions; 230 SHUT_RDWR = No more receptions or transmissions. 231 Returns 0 on success, -1 for errors. */ 232 extern int shutdown(int __fd, int __how) __THROW; 233 234 #ifdef __USE_XOPEN2K 235 /* Determine wheter socket is at a out-of-band mark. */ 236 extern int sockatmark(int __fd) __THROW; 237 #endif 238 239 #ifdef __USE_MISC 240 /* FDTYPE is S_IFSOCK or another S_IF* macro defined in <sys/stat.h>; 241 returns 1 if FD is open on an object of the indicated type, 0 if not, 242 or -1 for errors (setting errno). */ 243 extern int isfdtype(int __fd, int __fdtype) __THROW; 244 #endif 245 246 /* Define some macros helping to catch buffer overflows. */ 247 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function 248 #include <bits/socket2.h> 249 #endif 250 251 __END_DECLS 252 #endif /* sys/socket.h */