• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @defgroup socket Socket
3  * @ingroup libc
4  */
5 
6 #ifndef	_SYS_SOCKET_H
7 #define	_SYS_SOCKET_H
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <features.h>
13 
14 #define __NEED_socklen_t
15 #define __NEED_sa_family_t
16 #define __NEED_size_t
17 #define __NEED_ssize_t
18 #define __NEED_uid_t
19 #define __NEED_pid_t
20 #define __NEED_gid_t
21 #define __NEED_struct_iovec
22 
23 #include <bits/alltypes.h>
24 
25 #include <bits/socket.h>
26 
27 struct msghdr {
28 	void *msg_name;
29 	socklen_t msg_namelen;
30 	struct iovec *msg_iov;
31 #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
32 	int __pad1;
33 #endif
34 	int msg_iovlen;
35 #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
36 	int __pad1;
37 #endif
38 	void *msg_control;
39 #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
40 	int __pad2;
41 #endif
42 	socklen_t msg_controllen;
43 #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
44 	int __pad2;
45 #endif
46 	int msg_flags;
47 };
48 
49 struct cmsghdr {
50 #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
51 	int __pad1;
52 #endif
53 	socklen_t cmsg_len;
54 #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
55 	int __pad1;
56 #endif
57 	int cmsg_level;
58 	int cmsg_type;
59 };
60 
61 #ifdef _GNU_SOURCE
62 struct ucred {
63 	pid_t pid;
64 	uid_t uid;
65 	gid_t gid;
66 };
67 
68 struct mmsghdr {
69 	struct msghdr msg_hdr;
70 	unsigned int  msg_len;
71 };
72 
73 struct timespec;
74 
75 int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int);
76 int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
77 #endif
78 
79 struct linger {
80 	int l_onoff;
81 	int l_linger;
82 };
83 
84 #define SHUT_RD 0
85 #define SHUT_WR 1
86 #define SHUT_RDWR 2
87 
88 #ifndef SOCK_STREAM
89 #define SOCK_STREAM    1
90 #define SOCK_DGRAM     2
91 #endif
92 
93 #define SOCK_RAW       3
94 #define SOCK_RDM       4
95 #define SOCK_SEQPACKET 5
96 #define SOCK_DCCP      6
97 #define SOCK_PACKET    10
98 
99 #ifndef SOCK_CLOEXEC
100 #define SOCK_CLOEXEC   02000000
101 #define SOCK_NONBLOCK  04000
102 #endif
103 
104 #define PF_UNSPEC       0
105 #define PF_LOCAL        1
106 #define PF_UNIX         PF_LOCAL
107 #define PF_FILE         PF_LOCAL
108 #define PF_INET         2
109 #define PF_AX25         3
110 #define PF_IPX          4
111 #define PF_APPLETALK    5
112 #define PF_NETROM       6
113 #define PF_BRIDGE       7
114 #define PF_ATMPVC       8
115 #define PF_X25          9
116 #define PF_INET6        10
117 #define PF_ROSE         11
118 #define PF_DECnet       12
119 #define PF_NETBEUI      13
120 #define PF_SECURITY     14
121 #define PF_KEY          15
122 #define PF_NETLINK      16
123 #define PF_ROUTE        PF_NETLINK
124 #define PF_PACKET       17
125 #define PF_ASH          18
126 #define PF_ECONET       19
127 #define PF_ATMSVC       20
128 #define PF_RDS          21
129 #define PF_SNA          22
130 #define PF_IRDA         23
131 #define PF_PPPOX        24
132 #define PF_WANPIPE      25
133 #define PF_LLC          26
134 #define PF_IB           27
135 #define PF_MPLS         28
136 #define PF_CAN          29
137 #define PF_TIPC         30
138 #define PF_BLUETOOTH    31
139 #define PF_IUCV         32
140 #define PF_RXRPC        33
141 #define PF_ISDN         34
142 #define PF_PHONET       35
143 #define PF_IEEE802154   36
144 #define PF_CAIF         37
145 #define PF_ALG          38
146 #define PF_NFC          39
147 #define PF_VSOCK        40
148 #define PF_KCM          41
149 #define PF_QIPCRTR      42
150 #define PF_SMC          43
151 #define PF_XDP          44
152 #define PF_MAX          45
153 
154 #define AF_UNSPEC       PF_UNSPEC
155 #define AF_LOCAL        PF_LOCAL
156 #define AF_UNIX         AF_LOCAL
157 #define AF_FILE         AF_LOCAL
158 #define AF_INET         PF_INET
159 #define AF_AX25         PF_AX25
160 #define AF_IPX          PF_IPX
161 #define AF_APPLETALK    PF_APPLETALK
162 #define AF_NETROM       PF_NETROM
163 #define AF_BRIDGE       PF_BRIDGE
164 #define AF_ATMPVC       PF_ATMPVC
165 #define AF_X25          PF_X25
166 #define AF_INET6        PF_INET6
167 #define AF_ROSE         PF_ROSE
168 #define AF_DECnet       PF_DECnet
169 #define AF_NETBEUI      PF_NETBEUI
170 #define AF_SECURITY     PF_SECURITY
171 #define AF_KEY          PF_KEY
172 #define AF_NETLINK      PF_NETLINK
173 #define AF_ROUTE        PF_ROUTE
174 #define AF_PACKET       PF_PACKET
175 #define AF_ASH          PF_ASH
176 #define AF_ECONET       PF_ECONET
177 #define AF_ATMSVC       PF_ATMSVC
178 #define AF_RDS          PF_RDS
179 #define AF_SNA          PF_SNA
180 #define AF_IRDA         PF_IRDA
181 #define AF_PPPOX        PF_PPPOX
182 #define AF_WANPIPE      PF_WANPIPE
183 #define AF_LLC          PF_LLC
184 #define AF_IB           PF_IB
185 #define AF_MPLS         PF_MPLS
186 #define AF_CAN          PF_CAN
187 #define AF_TIPC         PF_TIPC
188 #define AF_BLUETOOTH    PF_BLUETOOTH
189 #define AF_IUCV         PF_IUCV
190 #define AF_RXRPC        PF_RXRPC
191 #define AF_ISDN         PF_ISDN
192 #define AF_PHONET       PF_PHONET
193 #define AF_IEEE802154   PF_IEEE802154
194 #define AF_CAIF         PF_CAIF
195 #define AF_ALG          PF_ALG
196 #define AF_NFC          PF_NFC
197 #define AF_VSOCK        PF_VSOCK
198 #define AF_KCM          PF_KCM
199 #define AF_QIPCRTR      PF_QIPCRTR
200 #define AF_SMC          PF_SMC
201 #define AF_XDP          PF_XDP
202 #define AF_MAX          PF_MAX
203 
204 #ifndef SO_DEBUG
205 #define SO_DEBUG        1
206 #define SO_REUSEADDR    2
207 #define SO_TYPE         3
208 #define SO_ERROR        4
209 #define SO_DONTROUTE    5
210 #define SO_BROADCAST    6
211 #define SO_SNDBUF       7
212 #define SO_RCVBUF       8
213 #define SO_KEEPALIVE    9
214 #define SO_OOBINLINE    10
215 #define SO_NO_CHECK     11
216 #define SO_PRIORITY     12
217 #define SO_LINGER       13
218 #define SO_BSDCOMPAT    14
219 #define SO_REUSEPORT    15
220 #define SO_PASSCRED     16
221 #define SO_PEERCRED     17
222 #define SO_RCVLOWAT     18
223 #define SO_SNDLOWAT     19
224 #define SO_ACCEPTCONN   30
225 #define SO_PEERSEC      31
226 #define SO_SNDBUFFORCE  32
227 #define SO_RCVBUFFORCE  33
228 #define SO_PROTOCOL     38
229 #define SO_DOMAIN       39
230 #endif
231 
232 #ifndef SO_RCVTIMEO
233 #if __LONG_MAX == 0x7fffffff
234 #define SO_RCVTIMEO     66
235 #define SO_SNDTIMEO     67
236 #else
237 #define SO_RCVTIMEO     20
238 #define SO_SNDTIMEO     21
239 #endif
240 #endif
241 
242 #ifndef SO_TIMESTAMP
243 #if __LONG_MAX == 0x7fffffff
244 #define SO_TIMESTAMP    63
245 #define SO_TIMESTAMPNS  64
246 #define SO_TIMESTAMPING 65
247 #else
248 #define SO_TIMESTAMP    29
249 #define SO_TIMESTAMPNS  35
250 #define SO_TIMESTAMPING 37
251 #endif
252 #endif
253 
254 #define SO_SECURITY_AUTHENTICATION              22
255 #define SO_SECURITY_ENCRYPTION_TRANSPORT        23
256 #define SO_SECURITY_ENCRYPTION_NETWORK          24
257 
258 #define SO_BINDTODEVICE 25
259 
260 #define SO_ATTACH_FILTER        26
261 #define SO_DETACH_FILTER        27
262 #define SO_GET_FILTER           SO_ATTACH_FILTER
263 
264 #define SO_PEERNAME             28
265 #define SCM_TIMESTAMP           SO_TIMESTAMP
266 #define SO_PASSSEC              34
267 #define SCM_TIMESTAMPNS         SO_TIMESTAMPNS
268 #define SO_MARK                 36
269 #define SCM_TIMESTAMPING        SO_TIMESTAMPING
270 #define SO_RXQ_OVFL             40
271 #define SO_WIFI_STATUS          41
272 #define SCM_WIFI_STATUS         SO_WIFI_STATUS
273 #define SO_PEEK_OFF             42
274 #define SO_NOFCS                43
275 #define SO_LOCK_FILTER          44
276 #define SO_SELECT_ERR_QUEUE     45
277 #define SO_BUSY_POLL            46
278 #define SO_MAX_PACING_RATE      47
279 #define SO_BPF_EXTENSIONS       48
280 #define SO_INCOMING_CPU         49
281 #define SO_ATTACH_BPF           50
282 #define SO_DETACH_BPF           SO_DETACH_FILTER
283 #define SO_ATTACH_REUSEPORT_CBPF 51
284 #define SO_ATTACH_REUSEPORT_EBPF 52
285 #define SO_CNX_ADVICE           53
286 #define SCM_TIMESTAMPING_OPT_STATS 54
287 #define SO_MEMINFO              55
288 #define SO_INCOMING_NAPI_ID     56
289 #define SO_COOKIE               57
290 #define SCM_TIMESTAMPING_PKTINFO 58
291 #define SO_PEERGROUPS           59
292 #define SO_ZEROCOPY             60
293 #define SO_TXTIME               61
294 #define SCM_TXTIME              SO_TXTIME
295 #define SO_BINDTOIFINDEX        62
296 #define SO_DETACH_REUSEPORT_BPF 68
297 
298 #ifndef SOL_SOCKET
299 #define SOL_SOCKET      1
300 #endif
301 
302 #define SOL_IP          0
303 #define SOL_IPV6        41
304 #define SOL_ICMPV6      58
305 
306 #define SOL_RAW         255
307 #define SOL_DECNET      261
308 #define SOL_X25         262
309 #define SOL_PACKET      263
310 #define SOL_ATM         264
311 #define SOL_AAL         265
312 #define SOL_IRDA        266
313 #define SOL_NETBEUI     267
314 #define SOL_LLC         268
315 #define SOL_DCCP        269
316 #define SOL_NETLINK     270
317 #define SOL_TIPC        271
318 #define SOL_RXRPC       272
319 #define SOL_PPPOL2TP    273
320 #define SOL_BLUETOOTH   274
321 #define SOL_PNPIPE      275
322 #define SOL_RDS         276
323 #define SOL_IUCV        277
324 #define SOL_CAIF        278
325 #define SOL_ALG         279
326 #define SOL_NFC         280
327 #define SOL_KCM         281
328 #define SOL_TLS         282
329 #define SOL_XDP         283
330 
331 #define SOMAXCONN       128
332 
333 #define MSG_OOB       0x0001
334 #define MSG_PEEK      0x0002
335 #define MSG_DONTROUTE 0x0004
336 #define MSG_CTRUNC    0x0008
337 #define MSG_PROXY     0x0010
338 #define MSG_TRUNC     0x0020
339 #define MSG_DONTWAIT  0x0040
340 #define MSG_EOR       0x0080
341 #define MSG_WAITALL   0x0100
342 #define MSG_FIN       0x0200
343 #define MSG_SYN       0x0400
344 #define MSG_CONFIRM   0x0800
345 #define MSG_RST       0x1000
346 #define MSG_ERRQUEUE  0x2000
347 #define MSG_NOSIGNAL  0x4000
348 #define MSG_MORE      0x8000
349 #define MSG_WAITFORONE 0x10000
350 #define MSG_BATCH     0x40000
351 #define MSG_ZEROCOPY  0x4000000
352 #define MSG_FASTOPEN  0x20000000
353 #define MSG_CMSG_CLOEXEC 0x40000000
354 
355 #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
356 #define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
357 #define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)
358 
359 #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1))
360 #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \
361 	__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
362 	? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg))
363 #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0)
364 
365 #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
366 #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
367 #define CMSG_LEN(len)   (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
368 
369 #define SCM_RIGHTS      0x01
370 #define SCM_CREDENTIALS 0x02
371 
372 struct sockaddr {
373 	sa_family_t sa_family;
374 	char sa_data[14];
375 };
376 
377 struct sockaddr_storage {
378 	sa_family_t ss_family;
379 	char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)];
380 	unsigned long __ss_align;
381 };
382 
383 /**
384  * @ingroup  socket
385  *
386  * @par Description:
387  * This API is used to create an endpoint for communication and returns a file descriptor.
388  *
389  * @param    domain    [IN]  Specifies a protocol family.
390  * @param    type      [IN]  Specifies the socket type.  [SOCK_RAW|SOCK_DGRAM|SOCK_STREAM]
391  * @param    protocol  [IN]  Specifies the protocol to be used with the socket.
392  *
393  * @attention
394  * <ul>
395  * <li>Only domain AF_INET and AF_PACKET are supported. For AF_INET, type SOCK_RAW|SOCK_DGRAM|SOCK_STREAM is supported.
396  * For AF_PACKET, only type SOCK_RAW is supported.</li>
397  * <li>The type argument can only be used to specify the socket type, no flags is supported, such as SOCK_NONBLOCK and SOCK_CLOEXEC.</li>
398  * </ul>
399  *
400  * @retval    #int    On success, socket() shall return a non-negative integer, the socket file descriptor. On failure, -1 shall be returned.
401  *
402  * @par Errors
403  * <ul>
404  * <li><b>EAFNOSUPPORT</b>: The implementation does not support the specified address family.</li>
405  * <li><b>EINVAL</b>: Invalid type or invalid flags in type.</li>
406  * <li><b>ENFILE</b>: The maximum number of sockets in the system are already open.</li>
407  * <li><b>ENOBUFS</b>: Insufficient resources were available in the system to perform the operation.</li>
408  * <li><b>EPROTONOSUPPORT</b>: The specified protocol is not supported within this domain & type.</li>
409  * <li><b>ESOCKTNOSUPPORT</b>: The socket type is not supported within this domain.</li>
410  * </ul>
411  *
412  * @par Dependency:
413  * <ul><li>socket.h</li></ul>
414  *
415  * @see  None
416  *
417  */
418 int socket (int, int, int);
419 int socketpair (int, int, int, int [2]);
420 
421 /**
422  * @ingroup  socket
423  *
424  * @par Description:
425  * This API is used to shut down socket send and receive operations.
426  *
427  * @param  s    [IN]  Specifies a file descriptor referring to the socket.
428  * @param  how  [IN]  Specifies the type of shutdown. The values are as follows: \n SHUT_RD Disables further receive operations. SHUT_WR: Disables further send operations. SHUT_RDWR: Disables further send and receive operations.
429  *
430  * @attention
431  * <ul>
432  * <li>Only "SHUT_RDWR" is supported for the "how" parameter in this API. lwIP does not support closing one end of the full-duplex connection.</li>
433  * <li>This API does not support the PF_PACKET option.</li>
434  * <li>The listen socket does not support half shutdown.</li>
435  * </ul>
436  *
437  * @retval    #0    On success.
438  * @retval    #-1   On failure.
439  *
440  * @par Errors
441  * <ul>
442  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
443  * <li><b>EINVAL</b>: The how argument is invalid.</li>
444  * <li><b>ENOTCONN</b>: lwIP does not support half close, ENOTCONN is returned.</li>
445  * <li><b>EINPROGRESS</b>: If WRITE/CONNECTING/CLOSE is in progress, lwip may fail.</li>
446  * <li><b>EINVAL</b>: If socket is not connected, lwIP shall fail with EINVAL.</li>
447  * <li><b>ENOMEM</b>: There was insufficient memory available to complete the operation.</li>
448  * <li><b>EOPNOTSUPP</b>: Socket is not TCP, lwIP shall fail.</li>
449  * </ul>
450  *
451  * @par Dependency:
452  * <ul><li>socket.h</li></ul>
453  *
454  * @see  None
455  *
456  */
457 int shutdown (int, int);
458 
459 /**
460  * @ingroup  socket
461  *
462  * @par Description:
463  * This API assigns the address specified by name to the socket referred to
464  * by the file descriptor 's'. namelen specifies the size, in bytes, of the address
465  * structure pointed to by name.
466  *
467  * @param  s        [IN]  Specifies the file descriptor of the socket to be bound.
468  * @param  name     [IN]  Points to a sockaddr structure containing the address to be bound to the socket. The length and format of the address depend on the address family of the socket.
469  * @param  namelen  [IN]  Specifies the length of the sockaddr structure pointed to by the address argument.
470  *
471  * @attention
472  * <ul>
473  * <li>Bind must not be called multiple times.</li>
474  * </ul>
475  *
476  * @retval     #0    On success.
477  * @retval     #-1   On failure.
478  *
479  * @par Errors
480  * <ul>
481  * <li><b>EADDRINUSE</b>: The specified address is already in use.</li>
482  * <li><b>EADDRINUSE</b>: For AF_INET socket, the port number was specified as zero in the socket address structure, but, upon attempting to bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use.</li>
483  * <li><b>EADDRNOTAVAIL</b>: The specified address is not available from the local machine.</li>
484  * <li><b>EAFNOSUPPORT</b>: The specified address is not a valid address for the address family of the specified socket.</li>
485  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
486  * <li><b>EINVAL</b>: The socket is already bound to an address, and the protocol does not support binding to a new address.</li>
487  * <li><b>EINVAL</b>: The namelen argument is not a valid length for the address family.</li>
488  * <li><b>EINVAL</b>: For AF_PACKET socket, the ifindex is out of system netif index range.</li>
489  * <li><b>EISCONN</b>: The specified socket is already connected.</li>
490  * <li><b>ENOBUFS</b>: Insufficient resources were available to complete the call.</li>
491  * <li><b>ENODEV</b>: For AF_PACKET socket, the netif can not be determined by the ifindex.</li>
492  * <li><b>ENETDOWN</b>: For AF_PACKET socket, the netif determined by the ifindex was down.</li>
493  * <li><b>EOPNOTSUPP</b>: The socket type of the specified socket does not support binding to an address.</li>
494  * </ul>
495  *
496  * @par Dependency:
497  * <ul><li>socket.h</li></ul>
498  *
499  * @see  connect | listen | socket
500  *
501  */
502 int bind (int, const struct sockaddr *, socklen_t);
503 
504 /**
505  * @ingroup  socket
506  *
507  * @par Description:
508  * This API connects the socket referred to by the file descriptor 's' to the address specified by name.
509  *
510  * @param  s          [IN]  Specifies a socket file descriptor.
511  * @param  name       [IN]  Specifies a pointer to the sockaddr structure which identifies the connection.
512  * @param  namelen    [IN]  Specifies size of name.
513  *
514  * @attention
515  * <ul>
516  * <li>None.</li>
517  * </ul>
518  *
519  * @retval    #0    On success.
520  * @retval    #-1   On failure.
521  *
522  * @par Errors
523  * <ul>
524  * <li><b>EACCES</b>: The user tried to connect to a broadcast address without having the socket broadcast flag enabled.</li>
525  * <li><b>EADDRNOTAVAIL</b>: For AF_IENT socket, the socket had not previously been bound to an address and, upon attempting to bind it to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use.</li>
526  * <li><b>EAFNOSUPPORT</b>: The specified address is not a valid address for the address family of the specified socket.</li>
527  * <li><b>EALREADY</b>: The socket is nonblocking and a previous connection attempt has not yet been completed.</li>
528  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
529  * <li><b>ECONNREFUSED</b>: The target address was not listening for connections or refused the connection request.</li>
530  * <li><b>ECONNRESET</b>: Remote host reset the connection request.</li>
531  * <li><b>EINPROGRESS</b>: O_NONBLOCK is set for the file descriptor for the socket and the connection cannot be immediately established; the connection shall be established asynchronously.</li>
532  * <li><b>EINVAL</b>: The address_len argument is not a valid length for the address family.</li>
533  * <li><b>EISCONN</b>: The specified socket is connection-mode and is already connected.</li>
534  * <li><b>ENETUNREACH</b>: No route to the network is present.</li>
535  * <li><b>ENOBUFS</b>: No buffer space is available.</li>
536  * <li><b>EOPNOTSUPP</b>: The referenced socket is not of domain AF_INET.</li>
537  * <li><b>EOPNOTSUPP</b>: The socket is listening and cannot be connected.</li>
538  * <li><b>ETIMEDOUT</b>: The attempt to connect timed out before a connection was made.</li>
539  * </ul>
540  *
541  * @par Dependency:
542  * <ul><li>socket.h</li></ul>
543  *
544  * @see  bind | listen | socket
545  *
546  */
547 int connect (int, const struct sockaddr *, socklen_t);
548 
549 /**
550  * @ingroup  socket
551  *
552  * @par Description:
553  * This API marks the socket referred to by 's' as a passive socket, that is, as a socket that will be used
554  * to accept incoming connection requests using accept().
555  *
556  * @param  s          [IN]  Specifies a file descriptor that refers to a socket of type SOCK_STREAM.
557  * @param  backlog    [IN]  Defines the maximum length to which the queue of pending connections for 's' may grow. If a connection request arrives when the queue is full, the client may receive an error with
558  *      an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.
559  *
560  * @attention
561  * <ul>
562  * <li>Max value of backlog is 0xFF, and min value of backlog is 0.</li>
563  * <li>If backlog value is 0 or less than zero, backlog value of 1 is used.</li>
564  * <li>This API does not support the PF_PACKET socket.</li>
565  * <li>lwIP do not support auto binding in listen operation, so bind must be called before listen.</li>
566  * <li>Listen can only be called once, and the backlog value can not be changed by later calling.</li>
567  * </ul>
568  *
569  * @retval    #0    On success.
570  * @retval    #-1   On failure.
571  *
572  * @par Errors
573  * <ul>
574  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
575  * <li><b>EDESTADDRREQ</b>: The socket is not bound to a local address, and the protocol does not support listening on an unbound socket.</li>
576  * <li><b>EINVAL</b>: The socket is in state which is not acceptable for listen.</li>
577  * <li><b>ENOBUFS</b>: Insufficient resources are available in the system to complete the call.</li>
578  * <li><b>EOPNOTSUPP</b>: The socket protocol does not support listen().</li>
579  * </ul>
580  *
581  * @par Dependency:
582  * <ul><li>socket.h</li></ul>
583  *
584  * @see  bind | connect | socket
585  *
586  */
587 int listen (int, int);
588 
589 /**
590  * @ingroup  socket
591  *
592  * @par Description:
593  * This API extracts the first connection request on the queue of pending connections
594  * for the listening socket 's', creates a new connected socket, and returns a new
595  * file descriptor  referring to that  socket. The newly created socket is not in the
596  * the listening state. The original socket 's' is unaffected by this call.
597  *
598  * @param  s          [IN]     Specifies a socket that was created with socket(), has been bound to an address with bind(), and has issued a successful call to listen().
599  * @param  addr       [OUT]    Either a null pointer, or a pointer to a sockaddr structure where the address of the connecting socket shall be returned.
600  * @param  addrlen    [IN/OUT] Either a null pointer, if address is a null pointer, or a pointer to a socklen_t object which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address.
601  *
602  * @attention
603  * <ul>
604  * <li>This API does not support the PF_PACKET option.</li>
605  * </ul>
606  *
607  * @retval    #int     On success, accept() shall return the non-negative file descriptor of the accepted socket. On failure, -1 shall be returned.
608  *
609  * @par Errors
610  * <ul>
611  * <li><b>EWOULDBLOCK</b>: O_NONBLOCK is set for the socket file descriptor and no connections are present to be accepted.</li>
612  * <li><b>EWOULDBLOCK</b>: O_NONBLOCK is not set but SO_RCVTIMEO is set, and no connections are present within acception timeout.</li>
613  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
614  * <li><b>ECONNABORTED</b>: A connection has been aborted.</li>
615  * <li><b>EINVAL</b>: The socket is not accepting connections.</li>
616  * <li><b>ENFILE</b>: The maximum number of sockets in the system are already open.</li>
617  * <li><b>ENOBUFS</b>: No buffer space is available.</li>
618  * <li><b>ENOMEM</b>: There was insufficient memory available to complete the operation.</li>
619  * <li><b>EOPNOTSUPP</b>: The referenced socket is not of type SOCK_STREAM.</li>
620  * <li><b>EIO</b>: Internal errors.</li>
621  * </ul>
622  *
623  * @par Dependency:
624  * <ul><li>socket.h</li></ul>
625  *
626  * @see  bind | connect | listen | socket
627  *
628  */
629 int accept (int, struct sockaddr *__restrict, socklen_t *__restrict);
630 int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
631 
632 /**
633  * @ingroup  socket
634  *
635  * @par Description:
636  * This API returns the current address to which the socket 's'  is bound, in the buffer pointed to by name.
637  * The namelen argument should be initialized to indicate the amount of space(in bytes) pointed to by
638  * name.The returned address is truncated if the buffer provided is too small; in this case, namelen will
639  * return a value greater than was supplied to the call.
640  *
641  * @param  s       [IN]      Specifies the file descriptor referring to connected socket.
642  * @param  name    [OUT]     Pointer to sockaddr structure of local peer.
643  * @param  namelen [IN/OUT]  Size of name structure.
644  *
645  * @attention
646  * <ul>
647  * <li>None.</li>
648  * </ul>
649  *
650  * @retval    #0    On success.
651  * @retval    #-1   On failure.
652  *
653  * @par Errors
654  * <ul>
655  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
656  * <li><b>EOPNOTSUPP</b>: The operation is not supported for this socket's protocol.For PF_RAW sockets, this error is returned.</li>
657  * <li><b>EINVAL</b>: The Name or Namelen are NULL, then EINVAL is returned.</li>
658  * </ul>
659  *
660  * @par Dependency:
661  * <ul><li>socket.h</li></ul>
662  *
663  * @see  getpeername
664  *
665  */
666 int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
667 
668 /**
669  * @ingroup  socket
670  *
671  * @par Description:
672  * This API returns the address of the peer connected to the socket 's', in the buffer pointed to by name.
673  * The namelen argument should be initialized  to  indicate the amount of space pointed to by name.
674  * On return it contains the actual size of the name returned (in bytes). The name is truncated if the
675  * buffer provided is too small.
676  *
677  * @param  s        [IN]      Specifies the file descriptor referring to the connected socket.
678  * @param  name     [OUT]     Pointer to sockaddr structure of remote peer
679  * @param  namelen  [IN/OUT]  Size of name structure.
680  *
681  * @attention
682  * <ul>
683  * <li>This API does not support the PF_PACKET option.</li>
684  * </ul>
685  *
686  * @retval     #0    On success.
687  * @retval     #-1   On failure.
688  *
689  * @par Errors
690  * <ul>
691  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
692  * <li><b>ENOTCONN</b>: The socket is not connected or otherwise has not had the peer pre-specified.</li>
693  * <li><b>EOPNOTSUPP</b>: The operation is not supported for the socket protocol.</li>
694  * <li><b>EINVAL</b>: The Name or Namelen are NULL, then EINVAL is returned.</li>
695  * </ul>
696  *
697  * @par Dependency:
698  * <ul><li>socket.h</li></ul>
699  *
700  * @see  getsockname
701  *
702  */
703 int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict);
704 
705 /**
706  * @ingroup  socket
707  *
708  * @par Description:
709  * This API initiate transmission of a message from the specified socket to its peer.
710  * This API will send a message only when the socket is connected.
711  *
712  * @param    s       [IN]   Specifies the socket file descriptor.
713  * @param    dataptr [IN]   Specifies a buffer containing message to send.
714  * @param    size    [IN]   Specifies the length of the message to send.
715  * @param    flags   [IN]   Indicates the flags of message transmission.
716  *
717  * @attention
718  * <ul>
719  * <li>UDP & RAW connection can send only a maximum data of length 65000. Sending more data would
720  * return -1 and errno set to EMSGSIZE.</li>
721  * <li>Only flag MSG_MORE, MSG_DONTWAIT and MSG_NOSIGNAL are supported, other flags, such as MSG_OOB/MSG_EOR is not supported.</li>
722  * </ul>
723  *
724  * @retval    #ssize_t      On success, send() shall return the number of bytes sent. On failure, -1 shall be returned.
725  *
726  * @par Errors
727  * <ul>
728  * <li><b>EWOULDBLOCK</b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONWAIT flag is set and the requested operation would block.</li>
729  * <li><b>EWOULDBLOCK</b>: The socket was not marked with O_NONBLOCK, but set with option SO_SNDTIMEO, and elapsed time is more than timeout value.</li>
730  * <li><b>EADDINUSE</b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use.</li>
731  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
732  * <li><b>ECONNRESET</b>: A connection was forcibly closed by a peer.</li>
733  * <li><b>EDESTADDRREQ</b>: The socket is not connection-mode and does not have its peer address set.</li>
734  * <li><b>EINPROGRESS</b>: For PF_INET/SOCK_STREAM, there was one send operation in progress, and concurrent sending was not supported.</li>
735  * <li><b>EINVAL</b>: Invalid argument passed, e.g. dataptr is NULL, size is zero.</li>
736  * <li><b>EMSGSIZE</b>: The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger than the MTU of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger than 65000 bytes.</li>
737  * <li><b>ENETDOWN</b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down.</li>
738  * <li><b>ENOBUFS</b>: Insufficient resources were available in the system to perform the operation.</li>
739  * <li><b>ENOMEM</b>: Insufficient memory was available to fulfill the request.</li>
740  * <li><b>ENODEVADDR</b>: For PF_PACKET/SOCK_RAW socket, the binding network interface does not exist.</li>
741  * <li><b>ENOTCONN</b>: The socket is not connected.</li>
742  * <li><b>EOPNOTSUPP</b>: Some bit in the flags argument is unsupported for the socket type.</li>
743  * <li><b>EIO</b>: Internal errors.</li>
744  * </ul>
745  *
746  * @par Dependency:
747  * <ul><li>socket.h</li></ul>
748  *
749  * @see  sendto
750  *
751  */
752 ssize_t send (int, const void *, size_t, int);
753 
754 /**
755  * @ingroup  socket
756  *
757  * @par Description:
758  * This API can be used to receive messages from a connection-oriented sockets only
759  * because it doesnot permits the application to retrieve the source address of received data.
760  *
761  * @param  s          [IN]  Specifies the socket file descriptor.
762  * @param  mem        [IN]  Points to a buffer where the message should be stored.
763  * @param  len        [IN]  Specifies the length in bytes of the buffer pointed to by the 'mem' argument.
764  * @param  flags      [IN]  Specifies the type of message reception. Values of this argument are formed by logically OR'ing zero or more of the following values: MSG_PEEK
765  *                          Peeks at an incoming message. The data is treated as unread and the next recv() or similar function shall still return this data.
766  *
767  * @attention
768  * <ul>
769  * <li>LwIP updates this receive buffer list, once it gets the next expected segment.
770  * If there is any out of order segment which is next to the received segment, means
771  * it merges and puts that as one segemnt into receive buffer list.</li>
772  * <li>If the apps don't read the packet from the socket and the recv buffered
773  * packets up to MAX_MBOX_SIZE, the incoming packet may be discard by lwIP and cause
774  * retransmission for tcp connection.</li>
775  * <li>Only flag MSG_PEEK and MSG_DONTWAIT are supported, other flags, such as MSG_TRUNC/MSG_WAITALL/MSG_OOB is not supported.</li>
776  * <li>When RST is received after FIN, this API will return 0 to indicate FIN, then
777  * return -1 and set errno to ECONNRESET for RST if called again.</li>
778  * <li>This API is not thread-safe.</li>
779  * </ul>
780  *
781  * @retval    #ssize_t    On success, recv() shall return the length of the message in bytes. On failure, -1 shall be returned.
782  *
783  * @par Errors
784  * <ul>
785  * <li><b>EWOULDBLOCK</b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set and no data is waiting to be received.</li>
786  * <li><b>EWOULDBLOCK</b>: The socket was not marked with O_NONBLOCK, but set with option SO_RCVTIMEO, and elapsed time is more than timeout value.</li>
787  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
788  * <li><b>ECONNRESET</b>: A connection was forcibly closed by a peer.</li>
789  * <li><b>EINVAL</b>: Invalid input parameters. If mem, len is null or flags is less than zero, lwip return failure.</li>
790  * <li><b>ENOBUFS</b>: Insufficient resources were available in the system to perform the operation.</li>
791  * <li><b>ENOMEM</b>: Insufficient memory was available to fulfill the request.</li>
792  * <li><b>ENOTCONN</b>: A receive is attempted on a connection-mode socket that is not connected.</li>
793  * <li><b>EOPNOTSUPP</b>: Some bit in the flags argument is unsupported for the socket type.</li>
794  * <li><b>EIO</b>: Internal errors.</li>
795  * </ul>
796  *
797  * @par Dependency:
798  * <ul><li>socket.h</li></ul>
799  *
800  * @see  recvfrom
801  *
802  */
803 ssize_t recv (int, void *, size_t, int);
804 
805 /**
806  * @ingroup  socket
807  *
808  * @par Description:
809  * This API can be used to send messages to a connection-oriented or connectionless socket.
810  * If the socket is connectionless-mode, the message shall be sent to the address specified by 'to'.
811  * If the socket is connection-mode, destination address in 'to' shall be ignored.
812  *
813  * @param    s        [IN]  Specifies a socket file descriptor.
814  * @param    dataptr  [IN]  Specifies a buffer containing the message to send.
815  * @param    size     [IN]  Specifies the length of the message to send.
816  * @param    flags    [IN]  Indicates the flags of message transmission.
817  * @param    to       [IN]  Specifies a pointer to the sockaddr structure that contains the destination address.
818  * @param    tolen    [IN]  Specifies the size of the 'to' structure.
819  *
820  * @attention
821  * <ul>
822  * <li>UDP & RAW connection can send only a maximum data of length 65000. Sending more data would
823  * return -1 and errno set to EMSGSIZE.</li>
824  * <li>Only flag MSG_MORE, MSG_DONTWAIT and MSG_NOSIGNAL are supported, other flags, such as MSG_OOB/MSG_EOR is not supported.</li>
825  * </ul>
826  *
827  * @retval    #ssize_t       On success, sendto() shall return the number of bytes sent. On failure, -1 shall be returned.
828  *
829  * @par Errors
830  * <ul>
831  * <li><b>EWOULDBLOCK</b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set and the requested operation would block.</li>
832  * <li><b>EWOULDBLOCK</b>: The socket was not marked with O_NONBLOCK, but set with option SO_SNDTIMEO, and elapsed time is more than timeout value.</li>
833  * <li><b>EACCES</b>: For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, the destination address is broadcast but SO_BROADCAST option was not enabled.</li>
834  * <li><b>EADDINUSE</b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use.</li>
835  * <li><b>EAFNOSUPPORT</b>: Addresses in the specified address family cannot be used with this socket.</li>
836  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
837  * <li><b>ECONNRESET</b>: A connection was forcibly closed by a peer.</li>
838  * <li><b>EDESTADDRREQ</b>: The socket is not connection-mode and does not have its peer address set, and no destination address was specified.</li>
839  * <li><b>EINPROGRESS</b>: For PF_INET/SOCK_STREAM, there was one send operation in progress, and concurrent sending was not supported.</li>
840  * <li><b>EINVAL</b>: Invalid argument passed, e.g. dataptr is NULL, size is zero.</li>
841  * <li><b>EMSGSIZE</b>: The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger than the MTU of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger than 65000 bytes.</li>
842  * <li><b>ENETDOWN</b>: For PF_PACKET/SOCK_RAW socket, the out network interface was down.</li>
843  * <li><b>ENETUNREACH</b>: No route to the destination is present.</li>
844  * <li><b>ENOBUFS</b>: Insufficient resources were available in the system to perform the operation.</li>
845  * <li><b>ENXIO</b>: For PF_PACKET/SOCK_RAW socket, the given network interface does not exist.</li>
846  * <li><b>ENOMEM</b>: Insufficient memory was available to fulfill the request.</li>
847  * <li><b>ENOTCONN</b>: The socket is not connected.</li>
848  * <li><b>EOPNOTSUPP</b>: Some bit in the flags argument is unsupported for the socket type.</li>
849  * <li><b>EIO</b>: Internal error.</li>
850  * </ul>
851  *
852  * @par Dependency:
853  * <ul><li>socket.h</li></ul>
854  *
855  * @see  send
856  *
857  */
858 ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
859 
860 /**
861  * @ingroup  socket
862  *
863  * @par Description:
864  * This API can be used to receive messages from a connection-oriented and connectionless sockets
865  * because it permits the application to retrieve the source address of received data.
866  *
867  * @param    s         [IN]   Specifies the socket file descriptor.
868  * @param    mem       [IN]   Points to the buffer where the message should be stored.
869  * @param    len       [IN]   Specifies the length in bytes of the buffer pointed to by the buffer argument.
870  * @param    flags     [IN]   Specifies the type of message reception. Values of this argument are formed by logically OR'ing zero or more of the following values: MSG_PEEK Peeks at an incoming message. The data is treated as unread and the next recvfrom() or similar function shall still return this data.
871  * @param    from      [OUT]  A null pointer, or points to a sockaddr structure in which the sending address is to be stored. The length and format of the address depend on the address family of the socket.
872  * @param    fromlen   [OUT]  Either a null pointer, if address is a null pointer, or a pointer to a socklen_t object which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address.
873  *
874  * @attention
875  * <ul>
876  * <li>If the apps don't read the packet from the socket and the recv buffered
877  * packets up to MAX_MBOX_SIZE, the incoming packet may be discard by lwIP.</li>
878  * <li>For TCP connection, when RST is received after FIN, this API will return
879  * 0 to indicate FIN, then return -1 and set errno to ECONNRESET for RST if
880  * called again.</li>
881  * <li>Only flag MSG_PEEK and MSG_DONTWAIT are supported, other flags, such as MSG_TRUNC/MSG_WAITALL/MSG_OOB is not supported.</li>
882  * <li>This API is not thread-safe.</li>
883  * </ul>
884  *
885  * @retval     #ssize_t      On success, recvfrom() shall return the length of the message in bytes. On failure, the function shall return -1.
886  *
887  * @par Errors
888  * <ul>
889  * <li><b>EWOULDBLOCK</b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONTWAIT flag is set and no data is waiting to be received.</li>
890  * <li><b>EWOULDBLOCK</b>: The socket was not marked with O_NONBLOCK, but set with option SO_RCVTIMEO, and elapsed time is more than timeout value.</li>
891  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
892  * <li><b>ECONNRESET</b>: A connection was forcibly closed by a peer.</li>
893  * <li><b>EINVAL</b>: Invalid input parameters. If mem, len is null or flags is less than zero, lwip return failure.</li>
894  * <li><b>ENOBUFS</b>: Insufficient resources were available in the system to perform the operation.</li>
895  * <li><b>ENOMEM</b>: Insufficient memory was available to fulfill the request.</li>
896  * <li><b>ENOTCONN</b>: A receive is attempted on a connection-mode socket that is not connected.</li>
897  * <li><b>EOPNOTSUPP</b>: Some bit in the flags argument is unsupported for the socket type.</li>
898  * <li><b>EIO</b>: Internal errors.</li>
899  * </ul>
900  *
901  * @par Dependency:
902  * <ul><li>socket.h</li></ul>
903  *
904  * @see  recv
905  *
906  */
907 ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
908 
909 /**
910  * @ingroup  socket
911  *
912  * @par Description:
913  *  This API initiates transmission of a message from the specified socket to its peer.
914  *  It sends a message only when the socket is connected.  The sendmsg() call also allows
915  * sending ancillary data (also known as control information).
916  *
917  * @param    s       [IN]   Specifies the socket file descriptor.
918  * @param    message [IN]   Specifies a buffer containing message to send.
919  * @param    flags   [IN]   Indicates the flags of message transmission.
920  *
921  * @attention
922  * <ul>
923  * <li>This API is only supported since lwip 2.0.</li>
924  * <li>UDP and RAW connection can send only data of maximum length 65332. Sending more than data
925  * will return -1 and errno set to EMSGSIZE</li>
926  * <li>Only flag MSG_MORE and MSG_DONTWAIT is supported. Other flags, such as
927  * MSG_OOB/MSG_NOSIGNAL/MSG_EOR are not supported.</li>
928  * </ul>
929  *
930  * @retval    #ssize_t      On success, sendmsg() shall return the number of bytes sent. On failure, -1 shall be returned.
931  *
932  * @par Errors
933  * <ul>
934  * <li><b>EADDINUSE</b>: For PF_INET/SOCK_DGRAM socket without local port bond, when attempting to
935  * bind to an ephemeral port, it was determined that all port numbers in the ephemeral port range are currently in use.</li>
936  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
937  * <li><b>ECONNRESET</b>: A connection was forcibly closed by a peer.</li>
938  * <li><b>EDESTADDRREQ</b>: The socket is not connection-mode and does not have its peer address set.</li>
939  * <li><b>EINPROGRESS</b>: For PF_INET/SOCK_STREAM, there was one send operation in progress,
940  * and concurrent sending was not supported.</li>
941  * <li><b>EINVAL</b>: Invalid argument passed, e.g. dataptr is NULL, size is zero.</li>
942  * <li><b>EMSGSIZE</b>: The socket type requires that message be sent atomically, and the size of the message
943  * to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger than the MTU of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger than 65000 bytes.</li>
944  * <li><b>ENETDOWN</b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down.</li>
945  * <li><b>ENOBUFS</b>: The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible. For PF_PACKET/SOCK_RAW socket, it means the packet is larger than the MTU of out network interface. For PF_INET/(SOCK_RAW,SOCK_DGRAM) socket, it means the packet is larger than 65000 bytes.</li>
946  * <li><b>ENETDOWN</b>: For PF_PACKET/SOCK_RAW socket, the binding network interface was down.</li>
947  * <li><b>ENOBUFS</b>: Insufficient resources were available in the system to perform the operation.</li>
948  * <li><b>ENODEVADDR</b>: For PF_PACKET/SOCK_RAW socket, the binding network interface does not exist.</li>
949  * <li><b>ENOMEM</b>: Insufficient memory was available to fulfill the request.</li>
950  * <li><b>ENOTCONN</b>: The socket is not connected.</li>
951  * <li><b>EOPNOTSUPP</b>: Some bit in the flags argument is unsupported for the socket type.</li>
952  * <li><b>EPIPE</b>: The socket is shut down for writing, or the socket is connection-mode
953  * and is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM.</li>
954  * <li><b>EWOULDBLOCK</b>: The socket's file descriptor is marked O_NONBLOCK or MSG_DONWAIT flag is set and the requested operation would block.</li>
955  * <li><b>EWOULDBLOCK</b>: The socket was not marked with O_NONBLOCK, but set with option SO_SNDTIMEO, and elapsed time is more than timeout value.</li>
956  * <li><b>EIO</b>: Internal errors.</li>
957  * </ul>
958  *
959  * @par Dependency:
960  * <ul><li>socket.h</li></ul>
961  *
962  * @see  sendto
963  *
964  */
965 ssize_t sendmsg (int, const struct msghdr *, int);
966 ssize_t recvmsg (int, struct msghdr *, int);
967 
968 /**
969  * @ingroup  socket
970  *
971  * @par Description:
972  * This API retrieves the value for the option specified by the optname argument for the socket
973  * specified by 's'. If the size of the optval is greater than optlen, the value stored in the object
974  * pointed to by the optval argument shall be silently truncated.
975  *
976  * @param  s        [IN]      Specifies a socket file descriptor.
977  * @param  level    [IN]      Specifies the protocol level at which the option resides.
978  * @param  optname  [IN]      Specifies a single option to be retrieved.
979  * @param  optval   [OUT]     Indicates an address to store option value.
980  * @param  optlen   [IN/OUT]  Specifies the size of the option value.
981  *
982  * @attention
983  * <ul>
984  * <li>Supported protocol levels are: SOL_SOCKET, IPPROTO_IP, IPPROTO_TCP,IPPROTO_UDPLITE.</li>
985  * <li>Under SOL_SOCKET the options supported are:
986  * SO_ACCEPTCONN
987  * SO_BROADCAST
988  * SO_ERROR
989  * SO_KEEPALIVE
990  * SO_SNDTIMEO
991  * SO_RCVTIMEO
992  * SO_RCVBUF
993  * SO_SNDBUF
994  * SO_REUSEADDR
995  * SO_TYPE
996  * SO_NO_CHECK
997  * SO_DONTROUTE
998  * SO_BINDTODEVICE
999  * For SO_SNDTIMEO, SO_RCVTIMEO, SO_RCVBUF, the macros LWIP_SO_SNDTIMEO, LWIP_SO_RCVTIMEO and LWIP_SO_RCVBUF should have been defined at compile time.
1000  * For SO_REUSEADDR, the macro SO_REUSE should have been defined at compile time.
1001  * For SO_BINDTODEVICE, the macro LWIP_SO_BINDTODEVICE should have been defined at compile time.
1002  * For SO_SNDBUF, the macro LWIP_SO_SNDBUF should have been defined at compile time.
1003  * </li>
1004  * <li>Under IPPROTO_IP the options supported are:
1005  * IP_MULTICAST_TTL
1006  * IP_MULTICAST_LOOP
1007  * IP_MULTICAST_IF
1008  * IP_HDRINCL
1009  * IP_TTL
1010  * IP_TOS
1011  * Only UDP socket supports IP_MULTICAST_TTL, IP_MULTICAST_LOOP, IP_MULTICAST_IF.
1012  * </li>
1013  * <li>Under IPPROTO_TCP the options supported are:
1014  * TCP_NODELAY
1015  * TCP_KEEPIDLE
1016  * TCP_KEEPINTVL
1017  * TCP_KEEPCNT
1018  * TCP_INFO
1019  * TCP_QUEUE_SEQ.
1020  * For TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT, the macro LWIP_TCP_KEEPALIVE should have been defined at compile time.\n
1021  * For TCP_INFO, Only tcpi_state, tcpi_retransmits, tcpi_probes, tcpi_backoff, tcpi_options, tcpi_rto, tcpi_snd_mss, tcpi_rcv_mss, tcpi_unacked,
1022  * tcpi_rtt, tcpi_rttvar, tcpi_snd_ssthresh, tcpi_snd_cwnd, tcpi_reordering in
1023  * struct tcp_info are supported, other fields are keep 0.
1024  * </li>
1025  * <li>Under IPPROTO_UDPLITE the options supported are:
1026  * UDPLITE_SEND_CSCOV
1027  * UDPLITE_RECV_CSCOV
1028  * </li>
1029  * </ul>
1030  *
1031  * @retval    #0    On success.
1032  * @retval    #-1   On failure.
1033  *
1034  * @par Errors
1035  * <ul>
1036  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
1037  * <li><b>EINVAL</b>: The specified option is invalid at the specified socket level.</li>
1038  * <li><b>EINVAL</b>: If opt or optlen are NULL,option or option length is incorrect.</li>
1039  * <li><b>ENOPROTOOPT</b>: The option is not supported by the protocol.</li>
1040  * <li><b>ENOMEM</b>: There was insufficient memory available to complete the operation.</li>
1041  * </ul>
1042  *
1043  * @par Dependency:
1044  * <ul><li>socket.h</li></ul>
1045  *
1046  * @see  setsockopt
1047  *
1048  */
1049 int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);
1050 
1051 /**
1052  * @ingroup  socket
1053  *
1054  * @par Description:
1055  * This API sets the option specified by the optname, at the protocol level specified by the level,
1056  * to the value pointed to by the optval for the socket associated with the file descriptor specified by 's'.
1057  *
1058  * @param  s        [IN]      Specifies a socket file descriptor.
1059  * @param  level    [IN]      Specifies the protocol level at which the option resides.
1060  * @param  optname  [IN]      Specifies a single option to set.
1061  * @param  optval   [IN]      Indicates the address to store the option value.
1062  * @param  optlen   [IN]      Specifies the size of option value.
1063  *
1064  * @attention
1065  * <ul>
1066  * <li>Supported protocol levels are: SOL_SOCKET, IPPROTO_IP, IPPROTO_TCP,IPPROTO_UDPLITE.</li>
1067  * <li>Under SOL_SOCKET the options supported are:
1068  * SO_BROADCAST
1069  * SO_KEEPALIVE
1070  * SO_SNDTIMEO
1071  * SO_RCVTIMEO
1072  * SO_RCVBUF
1073  * SO_SNDBUF
1074  * SO_REUSEADDR
1075  * SO_REUSEPORT
1076  * SO_NO_CHECK.
1077  * SO_ATTACH_FILTER
1078  * SO_DETACH_FILTER
1079  * SO_DONTROUTE
1080  * SO_BINDTODEVICE
1081  * For SO_SNDTIMEO, SO_RCVTIMEO, SO_RCVBUF, the macros LWIP_SO_SNDTIMEO, LWIP_SO_RCVTIMEO and LWIP_SO_RCVBUF should have been defined at compile time.
1082  * For SO_REUSEADDR, the macro SO_REUSE should have been defined at compile time.
1083  * For SO_BINDTODEVICE, the macro LWIP_SO_BINDTODEVICE should have been defined at compile time.
1084  * For SO_ATTACH_FILTER, SO_DETACH_FILTER, the macro LWIP_SOCKET_FILTER should have been defined at compile time.
1085  * Only PF_PACKET RAW socket supports SO_ATTACH_FILTER and SO_DETACH_FILTER now.
1086  * For SO_SNDBUF, the macro LWIP_SO_SNDBUF should have been defined at compile time.
1087  * Only TCP socket in listen or closed stated supports SO_SNDBUF.
1088  * </li>
1089  * <li>Under IPPROTO_IP the options supported are:
1090  * IP_ADD_MEMBERSHIP
1091  * IP_DROP_MEMBERSHIP
1092  * IP_MULTICAST_TTL
1093  * IP_MULTICAST_LOOP
1094  * IP_MULTICAST_IF
1095  * IP_HDRINCL
1096  * IP_TTL
1097  * IP_TOS
1098  * Only UDP socket supports IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_TTL, IP_MULTICAST_LOOP, IP_MULTICAST_IF.
1099  * </li>
1100  * <li>Under IPPROTO_TCP the options supported are:
1101  * TCP_NODELAY
1102  * TCP_KEEPIDLE
1103  * TCP_KEEPINTVL
1104  * TCP_KEEPCNT.
1105  * For TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT, the macro LWIP_TCP_KEEPALIVE should have been defined at compile time.
1106  * </li>
1107  * <li>Under IPPROTO_UDPLITE the options supported are:
1108  * UDPLITE_SEND_CSCOV
1109  * UDPLITE_RECV_CSCOV
1110  * </li>
1111  * </ul>
1112  *
1113  * @retval    #0    On success.
1114  * @retval    #-1   On failure.
1115  *
1116  * @par Errors
1117  * <ul>
1118  * <li><b>EBADF</b>: The socket argument is not a valid file descriptor.</li>
1119  * <li><b>EDOM</b>: The send and receive timeout values are too big to fit into the timeout fields in the socket structure.</li>
1120  * <li><b>ENOENT</b>: the option is SO_DETACH_FILTER while no previous socket filter was attached.</li>
1121  * <li><b>ENOMEM</b>: There was insufficient memory available for the operation to complete.</li>
1122  * <li><b>ENOPROTOOPT</b>: The option is not supported by the protocol.</li>
1123  * <li><b>EINVAL</b>: If optval is NULL pointer, lwIP shall fail.</li>
1124  * <li><b>EINVAL</b>: If for PF_PACKET socket type, level is neither SOL_PACKET nor SOL_SOCKET, lwIP shall fail.</li>
1125  * <li><b>EINVAL</b>: If optlen does not match optval for corresponding optname, lwIP shall fail.</li>
1126  * <li><b>EINVAL</b>: If the send and receive timeout values are smaller than 10000 microseconds, lwIP shall fail.</li>
1127  * </ul>
1128  *
1129  * @par Dependency:
1130  * <ul><li>socket.h</li></ul>
1131  *
1132  * @see  getsockopt
1133  *
1134  */
1135 int setsockopt (int, int, int, const void *, socklen_t);
1136 
1137 int sockatmark (int);
1138 
1139 #if _REDIR_TIME64
1140 #ifdef _GNU_SOURCE
1141 __REDIR(recvmmsg, __recvmmsg_time64);
1142 #endif
1143 #endif
1144 
1145 #ifdef __cplusplus
1146 }
1147 #endif
1148 #endif
1149