1570af302Sopenharmony_ci#ifndef	_SYS_SOCKET_H
2570af302Sopenharmony_ci#define	_SYS_SOCKET_H
3570af302Sopenharmony_ci#ifdef __cplusplus
4570af302Sopenharmony_ciextern "C" {
5570af302Sopenharmony_ci#endif
6570af302Sopenharmony_ci
7570af302Sopenharmony_ci#include <features.h>
8570af302Sopenharmony_ci
9570af302Sopenharmony_ci#define __NEED_socklen_t
10570af302Sopenharmony_ci#define __NEED_sa_family_t
11570af302Sopenharmony_ci#define __NEED_size_t
12570af302Sopenharmony_ci#define __NEED_ssize_t
13570af302Sopenharmony_ci#define __NEED_uid_t
14570af302Sopenharmony_ci#define __NEED_pid_t
15570af302Sopenharmony_ci#define __NEED_gid_t
16570af302Sopenharmony_ci#define __NEED_struct_iovec
17570af302Sopenharmony_ci
18570af302Sopenharmony_ci#include <bits/alltypes.h>
19570af302Sopenharmony_ci
20570af302Sopenharmony_ci#include <bits/socket.h>
21570af302Sopenharmony_ci
22570af302Sopenharmony_ci#ifdef __MUSL__
23570af302Sopenharmony_ci#include <linux/socket.h>
24570af302Sopenharmony_ci#endif
25570af302Sopenharmony_ci
26570af302Sopenharmony_cistruct msghdr {
27570af302Sopenharmony_ci	void *msg_name;
28570af302Sopenharmony_ci	socklen_t msg_namelen;
29570af302Sopenharmony_ci	struct iovec *msg_iov;
30570af302Sopenharmony_ci#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
31570af302Sopenharmony_ci	int __pad1;
32570af302Sopenharmony_ci#endif
33570af302Sopenharmony_ci	int msg_iovlen;
34570af302Sopenharmony_ci#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
35570af302Sopenharmony_ci	int __pad1;
36570af302Sopenharmony_ci#endif
37570af302Sopenharmony_ci	void *msg_control;
38570af302Sopenharmony_ci#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
39570af302Sopenharmony_ci	int __pad2;
40570af302Sopenharmony_ci#endif
41570af302Sopenharmony_ci	socklen_t msg_controllen;
42570af302Sopenharmony_ci#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
43570af302Sopenharmony_ci	int __pad2;
44570af302Sopenharmony_ci#endif
45570af302Sopenharmony_ci	int msg_flags;
46570af302Sopenharmony_ci};
47570af302Sopenharmony_ci
48570af302Sopenharmony_cistruct cmsghdr {
49570af302Sopenharmony_ci#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
50570af302Sopenharmony_ci	int __pad1;
51570af302Sopenharmony_ci#endif
52570af302Sopenharmony_ci	socklen_t cmsg_len;
53570af302Sopenharmony_ci#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
54570af302Sopenharmony_ci	int __pad1;
55570af302Sopenharmony_ci#endif
56570af302Sopenharmony_ci	int cmsg_level;
57570af302Sopenharmony_ci	int cmsg_type;
58570af302Sopenharmony_ci};
59570af302Sopenharmony_ci
60570af302Sopenharmony_ci#ifdef _GNU_SOURCE
61570af302Sopenharmony_cistruct ucred {
62570af302Sopenharmony_ci	pid_t pid;
63570af302Sopenharmony_ci	uid_t uid;
64570af302Sopenharmony_ci	gid_t gid;
65570af302Sopenharmony_ci};
66570af302Sopenharmony_ci
67570af302Sopenharmony_cistruct mmsghdr {
68570af302Sopenharmony_ci	struct msghdr msg_hdr;
69570af302Sopenharmony_ci	unsigned int  msg_len;
70570af302Sopenharmony_ci};
71570af302Sopenharmony_ci
72570af302Sopenharmony_cistruct timespec;
73570af302Sopenharmony_ci
74570af302Sopenharmony_ciint sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int);
75570af302Sopenharmony_ciint recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
76570af302Sopenharmony_ci#endif
77570af302Sopenharmony_ci
78570af302Sopenharmony_cistruct linger {
79570af302Sopenharmony_ci	int l_onoff;
80570af302Sopenharmony_ci	int l_linger;
81570af302Sopenharmony_ci};
82570af302Sopenharmony_ci
83570af302Sopenharmony_ci#define SHUT_RD 0
84570af302Sopenharmony_ci#define SHUT_WR 1
85570af302Sopenharmony_ci#define SHUT_RDWR 2
86570af302Sopenharmony_ci
87570af302Sopenharmony_ci#ifndef SOCK_STREAM
88570af302Sopenharmony_ci#define SOCK_STREAM    1
89570af302Sopenharmony_ci#define SOCK_DGRAM     2
90570af302Sopenharmony_ci#endif
91570af302Sopenharmony_ci
92570af302Sopenharmony_ci#define SOCK_RAW       3
93570af302Sopenharmony_ci#define SOCK_RDM       4
94570af302Sopenharmony_ci#define SOCK_SEQPACKET 5
95570af302Sopenharmony_ci#define SOCK_DCCP      6
96570af302Sopenharmony_ci#define SOCK_PACKET    10
97570af302Sopenharmony_ci
98570af302Sopenharmony_ci#ifndef SOCK_CLOEXEC
99570af302Sopenharmony_ci#define SOCK_CLOEXEC   02000000
100570af302Sopenharmony_ci#define SOCK_NONBLOCK  04000
101570af302Sopenharmony_ci#endif
102570af302Sopenharmony_ci
103570af302Sopenharmony_ci#define PF_UNSPEC       0
104570af302Sopenharmony_ci#define PF_LOCAL        1
105570af302Sopenharmony_ci#define PF_UNIX         PF_LOCAL
106570af302Sopenharmony_ci#define PF_FILE         PF_LOCAL
107570af302Sopenharmony_ci#define PF_INET         2
108570af302Sopenharmony_ci#define PF_AX25         3
109570af302Sopenharmony_ci#define PF_IPX          4
110570af302Sopenharmony_ci#define PF_APPLETALK    5
111570af302Sopenharmony_ci#define PF_NETROM       6
112570af302Sopenharmony_ci#define PF_BRIDGE       7
113570af302Sopenharmony_ci#define PF_ATMPVC       8
114570af302Sopenharmony_ci#define PF_X25          9
115570af302Sopenharmony_ci#define PF_INET6        10
116570af302Sopenharmony_ci#define PF_ROSE         11
117570af302Sopenharmony_ci#define PF_DECnet       12
118570af302Sopenharmony_ci#define PF_NETBEUI      13
119570af302Sopenharmony_ci#define PF_SECURITY     14
120570af302Sopenharmony_ci#define PF_KEY          15
121570af302Sopenharmony_ci#define PF_NETLINK      16
122570af302Sopenharmony_ci#define PF_ROUTE        PF_NETLINK
123570af302Sopenharmony_ci#define PF_PACKET       17
124570af302Sopenharmony_ci#define PF_ASH          18
125570af302Sopenharmony_ci#define PF_ECONET       19
126570af302Sopenharmony_ci#define PF_ATMSVC       20
127570af302Sopenharmony_ci#define PF_RDS          21
128570af302Sopenharmony_ci#define PF_SNA          22
129570af302Sopenharmony_ci#define PF_IRDA         23
130570af302Sopenharmony_ci#define PF_PPPOX        24
131570af302Sopenharmony_ci#define PF_WANPIPE      25
132570af302Sopenharmony_ci#define PF_LLC          26
133570af302Sopenharmony_ci#define PF_IB           27
134570af302Sopenharmony_ci#define PF_MPLS         28
135570af302Sopenharmony_ci#define PF_CAN          29
136570af302Sopenharmony_ci#define PF_TIPC         30
137570af302Sopenharmony_ci#define PF_BLUETOOTH    31
138570af302Sopenharmony_ci#define PF_IUCV         32
139570af302Sopenharmony_ci#define PF_RXRPC        33
140570af302Sopenharmony_ci#define PF_ISDN         34
141570af302Sopenharmony_ci#define PF_PHONET       35
142570af302Sopenharmony_ci#define PF_IEEE802154   36
143570af302Sopenharmony_ci#define PF_CAIF         37
144570af302Sopenharmony_ci#define PF_ALG          38
145570af302Sopenharmony_ci#define PF_NFC          39
146570af302Sopenharmony_ci#define PF_VSOCK        40
147570af302Sopenharmony_ci#define PF_KCM          41
148570af302Sopenharmony_ci#define PF_QIPCRTR      42
149570af302Sopenharmony_ci#define PF_SMC          43
150570af302Sopenharmony_ci#define PF_XDP          44
151570af302Sopenharmony_ci#define PF_MAX          45
152570af302Sopenharmony_ci
153570af302Sopenharmony_ci#define AF_UNSPEC       PF_UNSPEC
154570af302Sopenharmony_ci#define AF_LOCAL        PF_LOCAL
155570af302Sopenharmony_ci#define AF_UNIX         AF_LOCAL
156570af302Sopenharmony_ci#define AF_FILE         AF_LOCAL
157570af302Sopenharmony_ci#define AF_INET         PF_INET
158570af302Sopenharmony_ci#define AF_AX25         PF_AX25
159570af302Sopenharmony_ci#define AF_IPX          PF_IPX
160570af302Sopenharmony_ci#define AF_APPLETALK    PF_APPLETALK
161570af302Sopenharmony_ci#define AF_NETROM       PF_NETROM
162570af302Sopenharmony_ci#define AF_BRIDGE       PF_BRIDGE
163570af302Sopenharmony_ci#define AF_ATMPVC       PF_ATMPVC
164570af302Sopenharmony_ci#define AF_X25          PF_X25
165570af302Sopenharmony_ci#define AF_INET6        PF_INET6
166570af302Sopenharmony_ci#define AF_ROSE         PF_ROSE
167570af302Sopenharmony_ci#define AF_DECnet       PF_DECnet
168570af302Sopenharmony_ci#define AF_NETBEUI      PF_NETBEUI
169570af302Sopenharmony_ci#define AF_SECURITY     PF_SECURITY
170570af302Sopenharmony_ci#define AF_KEY          PF_KEY
171570af302Sopenharmony_ci#define AF_NETLINK      PF_NETLINK
172570af302Sopenharmony_ci#define AF_ROUTE        PF_ROUTE
173570af302Sopenharmony_ci#define AF_PACKET       PF_PACKET
174570af302Sopenharmony_ci#define AF_ASH          PF_ASH
175570af302Sopenharmony_ci#define AF_ECONET       PF_ECONET
176570af302Sopenharmony_ci#define AF_ATMSVC       PF_ATMSVC
177570af302Sopenharmony_ci#define AF_RDS          PF_RDS
178570af302Sopenharmony_ci#define AF_SNA          PF_SNA
179570af302Sopenharmony_ci#define AF_IRDA         PF_IRDA
180570af302Sopenharmony_ci#define AF_PPPOX        PF_PPPOX
181570af302Sopenharmony_ci#define AF_WANPIPE      PF_WANPIPE
182570af302Sopenharmony_ci#define AF_LLC          PF_LLC
183570af302Sopenharmony_ci#define AF_IB           PF_IB
184570af302Sopenharmony_ci#define AF_MPLS         PF_MPLS
185570af302Sopenharmony_ci#define AF_CAN          PF_CAN
186570af302Sopenharmony_ci#define AF_TIPC         PF_TIPC
187570af302Sopenharmony_ci#define AF_BLUETOOTH    PF_BLUETOOTH
188570af302Sopenharmony_ci#define AF_IUCV         PF_IUCV
189570af302Sopenharmony_ci#define AF_RXRPC        PF_RXRPC
190570af302Sopenharmony_ci#define AF_ISDN         PF_ISDN
191570af302Sopenharmony_ci#define AF_PHONET       PF_PHONET
192570af302Sopenharmony_ci#define AF_IEEE802154   PF_IEEE802154
193570af302Sopenharmony_ci#define AF_CAIF         PF_CAIF
194570af302Sopenharmony_ci#define AF_ALG          PF_ALG
195570af302Sopenharmony_ci#define AF_NFC          PF_NFC
196570af302Sopenharmony_ci#define AF_VSOCK        PF_VSOCK
197570af302Sopenharmony_ci#define AF_KCM          PF_KCM
198570af302Sopenharmony_ci#define AF_QIPCRTR      PF_QIPCRTR
199570af302Sopenharmony_ci#define AF_SMC          PF_SMC
200570af302Sopenharmony_ci#define AF_XDP          PF_XDP
201570af302Sopenharmony_ci#define AF_MAX          PF_MAX
202570af302Sopenharmony_ci
203570af302Sopenharmony_ci#ifndef SO_DEBUG
204570af302Sopenharmony_ci#define SO_DEBUG        1
205570af302Sopenharmony_ci#define SO_REUSEADDR    2
206570af302Sopenharmony_ci#define SO_TYPE         3
207570af302Sopenharmony_ci#define SO_ERROR        4
208570af302Sopenharmony_ci#define SO_DONTROUTE    5
209570af302Sopenharmony_ci#define SO_BROADCAST    6
210570af302Sopenharmony_ci#define SO_SNDBUF       7
211570af302Sopenharmony_ci#define SO_RCVBUF       8
212570af302Sopenharmony_ci#define SO_KEEPALIVE    9
213570af302Sopenharmony_ci#define SO_OOBINLINE    10
214570af302Sopenharmony_ci#define SO_NO_CHECK     11
215570af302Sopenharmony_ci#define SO_PRIORITY     12
216570af302Sopenharmony_ci#define SO_LINGER       13
217570af302Sopenharmony_ci#define SO_BSDCOMPAT    14
218570af302Sopenharmony_ci#define SO_REUSEPORT    15
219570af302Sopenharmony_ci#define SO_PASSCRED     16
220570af302Sopenharmony_ci#define SO_PEERCRED     17
221570af302Sopenharmony_ci#define SO_RCVLOWAT     18
222570af302Sopenharmony_ci#define SO_SNDLOWAT     19
223570af302Sopenharmony_ci#define SO_ACCEPTCONN   30
224570af302Sopenharmony_ci#define SO_PEERSEC      31
225570af302Sopenharmony_ci#define SO_SNDBUFFORCE  32
226570af302Sopenharmony_ci#define SO_RCVBUFFORCE  33
227570af302Sopenharmony_ci#define SO_PROTOCOL     38
228570af302Sopenharmony_ci#define SO_DOMAIN       39
229570af302Sopenharmony_ci#endif
230570af302Sopenharmony_ci
231570af302Sopenharmony_ci#ifndef SO_RCVTIMEO
232570af302Sopenharmony_ci#if __LONG_MAX == 0x7fffffff
233570af302Sopenharmony_ci#define SO_RCVTIMEO     66
234570af302Sopenharmony_ci#define SO_SNDTIMEO     67
235570af302Sopenharmony_ci#else
236570af302Sopenharmony_ci#define SO_RCVTIMEO     20
237570af302Sopenharmony_ci#define SO_SNDTIMEO     21
238570af302Sopenharmony_ci#endif
239570af302Sopenharmony_ci#endif
240570af302Sopenharmony_ci
241570af302Sopenharmony_ci#ifndef SO_TIMESTAMP
242570af302Sopenharmony_ci#if __LONG_MAX == 0x7fffffff
243570af302Sopenharmony_ci#define SO_TIMESTAMP    63
244570af302Sopenharmony_ci#define SO_TIMESTAMPNS  64
245570af302Sopenharmony_ci#define SO_TIMESTAMPING 65
246570af302Sopenharmony_ci#else
247570af302Sopenharmony_ci#define SO_TIMESTAMP    29
248570af302Sopenharmony_ci#define SO_TIMESTAMPNS  35
249570af302Sopenharmony_ci#define SO_TIMESTAMPING 37
250570af302Sopenharmony_ci#endif
251570af302Sopenharmony_ci#endif
252570af302Sopenharmony_ci
253570af302Sopenharmony_ci#define SO_SECURITY_AUTHENTICATION              22
254570af302Sopenharmony_ci#define SO_SECURITY_ENCRYPTION_TRANSPORT        23
255570af302Sopenharmony_ci#define SO_SECURITY_ENCRYPTION_NETWORK          24
256570af302Sopenharmony_ci
257570af302Sopenharmony_ci#define SO_BINDTODEVICE 25
258570af302Sopenharmony_ci
259570af302Sopenharmony_ci#define SO_ATTACH_FILTER        26
260570af302Sopenharmony_ci#define SO_DETACH_FILTER        27
261570af302Sopenharmony_ci#define SO_GET_FILTER           SO_ATTACH_FILTER
262570af302Sopenharmony_ci
263570af302Sopenharmony_ci#define SO_PEERNAME             28
264570af302Sopenharmony_ci#define SCM_TIMESTAMP           SO_TIMESTAMP
265570af302Sopenharmony_ci#define SO_PASSSEC              34
266570af302Sopenharmony_ci#define SCM_TIMESTAMPNS         SO_TIMESTAMPNS
267570af302Sopenharmony_ci#define SO_MARK                 36
268570af302Sopenharmony_ci#define SCM_TIMESTAMPING        SO_TIMESTAMPING
269570af302Sopenharmony_ci#define SO_RXQ_OVFL             40
270570af302Sopenharmony_ci#define SO_WIFI_STATUS          41
271570af302Sopenharmony_ci#define SCM_WIFI_STATUS         SO_WIFI_STATUS
272570af302Sopenharmony_ci#define SO_PEEK_OFF             42
273570af302Sopenharmony_ci#define SO_NOFCS                43
274570af302Sopenharmony_ci#define SO_LOCK_FILTER          44
275570af302Sopenharmony_ci#define SO_SELECT_ERR_QUEUE     45
276570af302Sopenharmony_ci#define SO_BUSY_POLL            46
277570af302Sopenharmony_ci#define SO_MAX_PACING_RATE      47
278570af302Sopenharmony_ci#define SO_BPF_EXTENSIONS       48
279570af302Sopenharmony_ci#define SO_INCOMING_CPU         49
280570af302Sopenharmony_ci#define SO_ATTACH_BPF           50
281570af302Sopenharmony_ci#define SO_DETACH_BPF           SO_DETACH_FILTER
282570af302Sopenharmony_ci#define SO_ATTACH_REUSEPORT_CBPF 51
283570af302Sopenharmony_ci#define SO_ATTACH_REUSEPORT_EBPF 52
284570af302Sopenharmony_ci#define SO_CNX_ADVICE           53
285570af302Sopenharmony_ci#define SCM_TIMESTAMPING_OPT_STATS 54
286570af302Sopenharmony_ci#define SO_MEMINFO              55
287570af302Sopenharmony_ci#define SO_INCOMING_NAPI_ID     56
288570af302Sopenharmony_ci#define SO_COOKIE               57
289570af302Sopenharmony_ci#define SCM_TIMESTAMPING_PKTINFO 58
290570af302Sopenharmony_ci#define SO_PEERGROUPS           59
291570af302Sopenharmony_ci#define SO_ZEROCOPY             60
292570af302Sopenharmony_ci#define SO_TXTIME               61
293570af302Sopenharmony_ci#define SCM_TXTIME              SO_TXTIME
294570af302Sopenharmony_ci#define SO_BINDTOIFINDEX        62
295570af302Sopenharmony_ci#define SO_DETACH_REUSEPORT_BPF 68
296570af302Sopenharmony_ci#define SO_PREFER_BUSY_POLL     69
297570af302Sopenharmony_ci#define SO_BUSY_POLL_BUDGET     70
298570af302Sopenharmony_ci
299570af302Sopenharmony_ci#ifndef SOL_SOCKET
300570af302Sopenharmony_ci#define SOL_SOCKET      1
301570af302Sopenharmony_ci#endif
302570af302Sopenharmony_ci
303570af302Sopenharmony_ci#define SOL_IP          0
304570af302Sopenharmony_ci#define SOL_IPV6        41
305570af302Sopenharmony_ci#define SOL_ICMPV6      58
306570af302Sopenharmony_ci
307570af302Sopenharmony_ci#define SOL_RAW         255
308570af302Sopenharmony_ci#define SOL_DECNET      261
309570af302Sopenharmony_ci#define SOL_X25         262
310570af302Sopenharmony_ci#define SOL_PACKET      263
311570af302Sopenharmony_ci#define SOL_ATM         264
312570af302Sopenharmony_ci#define SOL_AAL         265
313570af302Sopenharmony_ci#define SOL_IRDA        266
314570af302Sopenharmony_ci#define SOL_NETBEUI     267
315570af302Sopenharmony_ci#define SOL_LLC         268
316570af302Sopenharmony_ci#define SOL_DCCP        269
317570af302Sopenharmony_ci#define SOL_NETLINK     270
318570af302Sopenharmony_ci#define SOL_TIPC        271
319570af302Sopenharmony_ci#define SOL_RXRPC       272
320570af302Sopenharmony_ci#define SOL_PPPOL2TP    273
321570af302Sopenharmony_ci#define SOL_BLUETOOTH   274
322570af302Sopenharmony_ci#define SOL_PNPIPE      275
323570af302Sopenharmony_ci#define SOL_RDS         276
324570af302Sopenharmony_ci#define SOL_IUCV        277
325570af302Sopenharmony_ci#define SOL_CAIF        278
326570af302Sopenharmony_ci#define SOL_ALG         279
327570af302Sopenharmony_ci#define SOL_NFC         280
328570af302Sopenharmony_ci#define SOL_KCM         281
329570af302Sopenharmony_ci#define SOL_TLS         282
330570af302Sopenharmony_ci#define SOL_XDP         283
331570af302Sopenharmony_ci
332570af302Sopenharmony_ci#define SOMAXCONN       128
333570af302Sopenharmony_ci
334570af302Sopenharmony_ci#define MSG_OOB       0x0001
335570af302Sopenharmony_ci#define MSG_PEEK      0x0002
336570af302Sopenharmony_ci#define MSG_DONTROUTE 0x0004
337570af302Sopenharmony_ci#define MSG_CTRUNC    0x0008
338570af302Sopenharmony_ci#define MSG_PROXY     0x0010
339570af302Sopenharmony_ci#define MSG_TRUNC     0x0020
340570af302Sopenharmony_ci#define MSG_DONTWAIT  0x0040
341570af302Sopenharmony_ci#define MSG_EOR       0x0080
342570af302Sopenharmony_ci#define MSG_WAITALL   0x0100
343570af302Sopenharmony_ci#define MSG_FIN       0x0200
344570af302Sopenharmony_ci#define MSG_SYN       0x0400
345570af302Sopenharmony_ci#define MSG_CONFIRM   0x0800
346570af302Sopenharmony_ci#define MSG_RST       0x1000
347570af302Sopenharmony_ci#define MSG_ERRQUEUE  0x2000
348570af302Sopenharmony_ci#define MSG_NOSIGNAL  0x4000
349570af302Sopenharmony_ci#define MSG_MORE      0x8000
350570af302Sopenharmony_ci#define MSG_WAITFORONE 0x10000
351570af302Sopenharmony_ci#define MSG_BATCH     0x40000
352570af302Sopenharmony_ci#define MSG_ZEROCOPY  0x4000000
353570af302Sopenharmony_ci#define MSG_FASTOPEN  0x20000000
354570af302Sopenharmony_ci#define MSG_CMSG_CLOEXEC 0x40000000
355570af302Sopenharmony_ci
356570af302Sopenharmony_ci#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
357570af302Sopenharmony_ci#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
358570af302Sopenharmony_ci#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)
359570af302Sopenharmony_ci
360570af302Sopenharmony_ci#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1))
361570af302Sopenharmony_ci#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \
362570af302Sopenharmony_ci	__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
363570af302Sopenharmony_ci	? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg))
364570af302Sopenharmony_ci#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0)
365570af302Sopenharmony_ci
366570af302Sopenharmony_ci#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
367570af302Sopenharmony_ci#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
368570af302Sopenharmony_ci#define CMSG_LEN(len)   (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
369570af302Sopenharmony_ci
370570af302Sopenharmony_ci#define SCM_RIGHTS      0x01
371570af302Sopenharmony_ci#define SCM_CREDENTIALS 0x02
372570af302Sopenharmony_ci
373570af302Sopenharmony_cistruct sockaddr {
374570af302Sopenharmony_ci	sa_family_t sa_family;
375570af302Sopenharmony_ci	char sa_data[14];
376570af302Sopenharmony_ci};
377570af302Sopenharmony_ci
378570af302Sopenharmony_ci#ifndef __MUSL__
379570af302Sopenharmony_cistruct sockaddr_storage {
380570af302Sopenharmony_ci	sa_family_t ss_family;
381570af302Sopenharmony_ci	char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)];
382570af302Sopenharmony_ci	unsigned long __ss_align;
383570af302Sopenharmony_ci};
384570af302Sopenharmony_ci#endif
385570af302Sopenharmony_ci
386570af302Sopenharmony_ciint socket (int, int, int);
387570af302Sopenharmony_ciint socketpair (int, int, int, int [2]);
388570af302Sopenharmony_ci
389570af302Sopenharmony_ciint shutdown (int, int);
390570af302Sopenharmony_ci
391570af302Sopenharmony_ciint bind (int, const struct sockaddr *, socklen_t);
392570af302Sopenharmony_ciint connect (int, const struct sockaddr *, socklen_t);
393570af302Sopenharmony_ciint listen (int, int);
394570af302Sopenharmony_ciint accept (int, struct sockaddr *__restrict, socklen_t *__restrict);
395570af302Sopenharmony_ciint accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
396570af302Sopenharmony_ci
397570af302Sopenharmony_ciint getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
398570af302Sopenharmony_ciint getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict);
399570af302Sopenharmony_ci
400570af302Sopenharmony_cissize_t send (int, const void *, size_t, int);
401570af302Sopenharmony_cissize_t recv (int, void *, size_t, int);
402570af302Sopenharmony_cissize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
403570af302Sopenharmony_cissize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
404570af302Sopenharmony_cissize_t sendmsg (int, const struct msghdr *, int);
405570af302Sopenharmony_cissize_t recvmsg (int, struct msghdr *, int);
406570af302Sopenharmony_ci
407570af302Sopenharmony_ciint getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);
408570af302Sopenharmony_ciint setsockopt (int, int, int, const void *, socklen_t);
409570af302Sopenharmony_ci
410570af302Sopenharmony_ciint sockatmark (int);
411570af302Sopenharmony_ci
412570af302Sopenharmony_ci#if _REDIR_TIME64
413570af302Sopenharmony_ci#ifdef _GNU_SOURCE
414570af302Sopenharmony_ci__REDIR(recvmmsg, __recvmmsg_time64);
415570af302Sopenharmony_ci#endif
416570af302Sopenharmony_ci#endif
417570af302Sopenharmony_ci
418570af302Sopenharmony_ci#include <fortify/socket.h>
419570af302Sopenharmony_ci
420570af302Sopenharmony_ci#ifdef __cplusplus
421570af302Sopenharmony_ci}
422570af302Sopenharmony_ci#endif
423570af302Sopenharmony_ci#endif
424