1/* $OpenBSD: socket.h,v 1.108 2025/08/04 04:59:30 guenther Exp $ */
2/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
3
4/*
5 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)socket.h 8.4 (Berkeley) 2/21/94
33 */
34
35#ifndef _SYS_SOCKET_H_
36#define _SYS_SOCKET_H_
37
38/* get the definitions for struct iovec, size_t, ssize_t, and <sys/cdefs.h> */
39#include <sys/uio.h>
40
41#if __BSD_VISIBLE
42#include <sys/types.h> /* for off_t, uid_t, and gid_t */
43#endif
44
45#ifndef _SOCKLEN_T_DEFINED_
46#define _SOCKLEN_T_DEFINED_
47typedef __socklen_t socklen_t; /* length type for network syscalls */
48#endif
49
50#ifndef _SA_FAMILY_T_DEFINED_
51#define _SA_FAMILY_T_DEFINED_
52typedef __sa_family_t sa_family_t; /* sockaddr address family type */
53#endif
54
55
56/*
57 * Definitions related to sockets: types, address families, options.
58 */
59
60/*
61 * Types
62 */
63#define SOCK_STREAM 1 /* stream socket */
64#define SOCK_DGRAM 2 /* datagram socket */
65#define SOCK_RAW 3 /* raw-protocol interface */
66#define SOCK_RDM 4 /* reliably-delivered message */
67#define SOCK_SEQPACKET 5 /* sequenced packet stream */
68#ifdef _KERNEL
69#define SOCK_TYPE_MASK 0x000F /* mask that covers the above */
70#endif
71
72/*
73 * Socket creation flags
74 */
75#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE
76#define SOCK_CLOEXEC 0x8000 /* set FD_CLOEXEC */
77#define SOCK_NONBLOCK 0x4000 /* set O_NONBLOCK */
78#endif
79#if __BSD_VISIBLE
80#ifdef _KERNEL
81#define SOCK_NONBLOCK_INHERIT 0x2000 /* inherit O_NONBLOCK from listener */
82#endif
83#define SOCK_DNS 0x1000 /* set SS_DNS */
84#endif /* __BSD_VISIBLE */
85#if __POSIX_VISIBLE >= 202405
86#define SOCK_CLOFORK 0x0800 /* set FD_CLOFORK */
87#endif
88
89/*
90 * Option flags per-socket.
91 */
92#define SO_DEBUG 0x0001 /* turn on debugging info recording */
93#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
94#define SO_REUSEADDR 0x0004 /* allow local address reuse */
95#define SO_KEEPALIVE 0x0008 /* keep connections alive */
96#define SO_DONTROUTE 0x0010 /* just use interface addresses */
97#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
98#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
99#define SO_LINGER 0x0080 /* linger on close if data present */
100#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
101#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
102#define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */
103#define SO_BINDANY 0x1000 /* allow bind to any address */
104#define SO_ZEROIZE 0x2000 /* zero out all mbufs sent over socket */
105
106/*
107 * Additional options, not kept in so_options.
108 */
109#define SO_SNDBUF 0x1001 /* send buffer size */
110#define SO_RCVBUF 0x1002 /* receive buffer size */
111#define SO_SNDLOWAT 0x1003 /* send low-water mark */
112#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
113#define SO_SNDTIMEO 0x1005 /* send timeout */
114#define SO_RCVTIMEO 0x1006 /* receive timeout */
115#define SO_ERROR 0x1007 /* get error status and clear */
116#define SO_TYPE 0x1008 /* get socket type */
117#define SO_RTABLE 0x1021 /* routing table to be used */
118#define SO_PEERCRED 0x1022 /* get connect-time credentials */
119#define SO_SPLICE 0x1023 /* splice data to other socket */
120#define SO_DOMAIN 0x1024 /* get socket domain */
121#define SO_PROTOCOL 0x1025 /* get socket protocol */
122
123/*
124 * Structure used for manipulating linger option.
125 */
126struct linger {
127 int l_onoff; /* option on/off */
128 int l_linger; /* linger time */
129};
130
131#if __BSD_VISIBLE
132
133#ifndef _TIMEVAL_DECLARED
134#define _TIMEVAL_DECLARED
135struct timeval {
136 time_t tv_sec; /* seconds */
137 suseconds_t tv_usec; /* and microseconds */
138};
139#endif
140
141/*
142 * Structure used for manipulating splice option.
143 */
144struct splice {
145 int sp_fd; /* drain socket file descriptor */
146 off_t sp_max; /* if set, maximum bytes to splice */
147 struct timeval sp_idle; /* idle timeout */
148};
149
150/*
151 * Maximum number of alternate routing tables
152 */
153#define RT_TABLEID_MAX 255
154#define RT_TABLEID_BITS 8
155#define RT_TABLEID_MASK 0xff
156
157#endif /* __BSD_VISIBLE */
158
159/*
160 * Level number for (get/set)sockopt() to apply to socket itself.
161 */
162#define SOL_SOCKET 0xffff /* options for socket level */
163
164/*
165 * Address families.
166 */
167#define AF_UNSPEC 0 /* unspecified */
168#define AF_UNIX 1 /* local to host */
169#define AF_LOCAL AF_UNIX /* draft POSIX compatibility */
170#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
171#define AF_IMPLINK 3 /* arpanet imp addresses */
172#define AF_PUP 4 /* pup protocols: e.g. BSP */
173#define AF_CHAOS 5 /* mit CHAOS protocols */
174#define AF_NS 6 /* XEROX NS protocols */
175#define AF_ISO 7 /* ISO protocols */
176#define AF_OSI AF_ISO
177#define AF_ECMA 8 /* european computer manufacturers */
178#define AF_DATAKIT 9 /* datakit protocols */
179#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
180#define AF_SNA 11 /* IBM SNA */
181#define AF_DECnet 12 /* DECnet */
182#define AF_DLI 13 /* DEC Direct data link interface */
183#define AF_LAT 14 /* LAT */
184#define AF_HYLINK 15 /* NSC Hyperchannel */
185#define AF_APPLETALK 16 /* Apple Talk */
186#define AF_ROUTE 17 /* Internal Routing Protocol */
187#define AF_LINK 18 /* Link layer interface */
188#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
189#define AF_COIP 20 /* connection-oriented IP, aka ST II */
190#define AF_CNT 21 /* Computer Network Technology */
191#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
192#define AF_IPX 23 /* Novell Internet Protocol */
193#define AF_INET6 24 /* IPv6 */
194#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
195#define AF_ISDN 26 /* Integrated Services Digital Network*/
196#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
197#define AF_NATM 27 /* native ATM access */
198#define AF_ENCAP 28
199#define AF_SIP 29 /* Simple Internet Protocol */
200#define AF_KEY 30
201#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers
202 in interface output routine */
203#define AF_BLUETOOTH 32 /* Bluetooth */
204#define AF_MPLS 33 /* MPLS */
205#define pseudo_AF_PFLOW 34 /* pflow */
206#define pseudo_AF_PIPEX 35 /* PIPEX */
207#define AF_FRAME 36 /* frame (Ethernet) sockets */
208#define AF_MAX 37
209
210/*
211 * Structure used by kernel to store most
212 * addresses.
213 */
214struct sockaddr {
215 __uint8_t sa_len; /* total length */
216 sa_family_t sa_family; /* address family */
217 char sa_data[14]; /* actually longer; address value */
218};
219
220/*
221 * Sockaddr type which can hold any sockaddr type available
222 * in the system.
223 *
224 * Note: __ss_{len,family} is defined in RFC2553. During RFC2553 discussion
225 * the field name went back and forth between ss_len and __ss_len,
226 * and RFC2553 specifies it to be __ss_len. openbsd picked ss_len.
227 * For maximum portability, userland programmer would need to
228 * (1) make the code never touch ss_len portion (cast it into sockaddr and
229 * touch sa_len), or (2) add "-Dss_len=__ss_len" into CFLAGS to unify all
230 * occurrences (including header file) to __ss_len.
231 */
232struct sockaddr_storage {
233 __uint8_t ss_len; /* total length */
234 sa_family_t ss_family; /* address family */
235 unsigned char __ss_pad1[6]; /* align to quad */
236 __uint64_t __ss_pad2; /* force alignment for stupid compilers */
237 unsigned char __ss_pad3[240]; /* pad to a total of 256 bytes */
238};
239
240#ifdef _KERNEL
241/*
242 * Structure used by kernel to pass protocol
243 * information in raw sockets.
244 */
245struct sockproto {
246 unsigned short sp_family; /* address family */
247 unsigned short sp_protocol; /* protocol */
248};
249#endif /* _KERNEL */
250
251/*
252 * Protocol families, same as address families for now.
253 */
254#define PF_UNSPEC AF_UNSPEC
255#define PF_LOCAL AF_LOCAL
256#define PF_UNIX AF_UNIX
257#define PF_INET AF_INET
258#define PF_IMPLINK AF_IMPLINK
259#define PF_PUP AF_PUP
260#define PF_CHAOS AF_CHAOS
261#define PF_NS AF_NS
262#define PF_ISO AF_ISO
263#define PF_OSI AF_ISO
264#define PF_ECMA AF_ECMA
265#define PF_DATAKIT AF_DATAKIT
266#define PF_CCITT AF_CCITT
267#define PF_SNA AF_SNA
268#define PF_DECnet AF_DECnet
269#define PF_DLI AF_DLI
270#define PF_LAT AF_LAT
271#define PF_HYLINK AF_HYLINK
272#define PF_APPLETALK AF_APPLETALK
273#define PF_ROUTE AF_ROUTE
274#define PF_LINK AF_LINK
275#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
276#define PF_COIP AF_COIP
277#define PF_CNT AF_CNT
278#define PF_IPX AF_IPX /* same format as AF_NS */
279#define PF_INET6 AF_INET6
280#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
281#define PF_PIP pseudo_AF_PIP
282#define PF_ISDN AF_ISDN
283#define PF_NATM AF_NATM
284#define PF_ENCAP AF_ENCAP
285#define PF_SIP AF_SIP
286#define PF_KEY AF_KEY
287#define PF_BPF pseudo_AF_HDRCMPLT
288#define PF_BLUETOOTH AF_BLUETOOTH
289#define PF_MPLS AF_MPLS
290#define PF_PFLOW pseudo_AF_PFLOW
291#define PF_PIPEX pseudo_AF_PIPEX
292#define PF_FRAME AF_FRAME
293#define PF_MAX AF_MAX
294
295/*
296 * These are the valid values for the "how" field used by shutdown(2).
297 */
298#define SHUT_RD 0
299#define SHUT_WR 1
300#define SHUT_RDWR 2
301
302#if __BSD_VISIBLE
303#define SA_LEN(x) ((x)->sa_len)
304
305/* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */
306struct sockpeercred {
307 uid_t uid; /* effective user id */
308 gid_t gid; /* effective group id */
309 pid_t pid;
310};
311
312/*
313 * Definitions for network related sysctl, CTL_NET.
314 *
315 * Second level is protocol family.
316 * Third level is protocol number.
317 *
318 * Further levels are defined by the individual families below.
319 */
320#define NET_MAXID AF_MAX
321
322#define CTL_NET_NAMES { \
323 { 0, 0 }, \
324 { "unix", CTLTYPE_NODE }, \
325 { "inet", CTLTYPE_NODE }, \
326 { "implink", CTLTYPE_NODE }, \
327 { "pup", CTLTYPE_NODE }, \
328 { "chaos", CTLTYPE_NODE }, \
329 { "xerox_ns", CTLTYPE_NODE }, \
330 { "iso", CTLTYPE_NODE }, \
331 { "ecma", CTLTYPE_NODE }, \
332 { "datakit", CTLTYPE_NODE }, \
333 { "ccitt", CTLTYPE_NODE }, \
334 { "ibm_sna", CTLTYPE_NODE }, \
335 { "decnet", CTLTYPE_NODE }, \
336 { "dec_dli", CTLTYPE_NODE }, \
337 { "lat", CTLTYPE_NODE }, \
338 { "hylink", CTLTYPE_NODE }, \
339 { "appletalk", CTLTYPE_NODE }, \
340 { "route", CTLTYPE_NODE }, \
341 { "link", CTLTYPE_NODE }, \
342 { "xtp", CTLTYPE_NODE }, \
343 { "coip", CTLTYPE_NODE }, \
344 { "cnt", CTLTYPE_NODE }, \
345 { "rtip", CTLTYPE_NODE }, \
346 { "ipx", CTLTYPE_NODE }, \
347 { "inet6", CTLTYPE_NODE }, \
348 { "pip", CTLTYPE_NODE }, \
349 { "isdn", CTLTYPE_NODE }, \
350 { "natm", CTLTYPE_NODE }, \
351 { "encap", CTLTYPE_NODE }, \
352 { "sip", CTLTYPE_NODE }, \
353 { "key", CTLTYPE_NODE }, \
354 { "bpf", CTLTYPE_NODE }, \
355 { "bluetooth", CTLTYPE_NODE }, \
356 { "mpls", CTLTYPE_NODE }, \
357 { "pflow", CTLTYPE_NODE }, \
358 { "pipex", CTLTYPE_NODE }, \
359}
360
361/*
362 * PF_ROUTE - Routing table
363 *
364 * Four additional levels are defined:
365 * Fourth: address family, 0 is wildcard
366 * Fifth: type of info, defined below
367 * Sixth: flag(s) to mask with for NET_RT_FLAGS
368 * Seventh: routing table to use (facultative, defaults to 0)
369 * NET_RT_TABLE has the table id as sixth element.
370 */
371#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
372#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
373#define NET_RT_IFLIST 3 /* survey interface list */
374#define NET_RT_STATS 4 /* routing table statistics */
375#define NET_RT_TABLE 5
376#define NET_RT_IFNAMES 6
377#define NET_RT_SOURCE 7
378#define NET_RT_MAXID 8
379
380#define CTL_NET_RT_NAMES { \
381 { 0, 0 }, \
382 { "dump", CTLTYPE_STRUCT }, \
383 { "flags", CTLTYPE_STRUCT }, \
384 { "iflist", CTLTYPE_STRUCT }, \
385 { "stats", CTLTYPE_STRUCT }, \
386 { "table", CTLTYPE_STRUCT }, \
387 { "ifnames", CTLTYPE_STRUCT }, \
388 { "source", CTLTYPE_STRUCT }, \
389}
390
391/*
392 * PF_UNIX - unix socket tunables
393 */
394#define NET_UNIX_INFLIGHT 6
395#define NET_UNIX_DEFERRED 7
396#define NET_UNIX_MAXID 8
397
398#define CTL_NET_UNIX_NAMES { \
399 { 0, 0 }, \
400 { "stream", CTLTYPE_NODE }, \
401 { "dgram", CTLTYPE_NODE }, \
402 { 0, 0 }, \
403 { 0, 0 }, \
404 { "seqpacket", CTLTYPE_NODE }, \
405 { "inflight", CTLTYPE_INT }, \
406 { "deferred", CTLTYPE_INT }, \
407}
408
409#define UNPCTL_RECVSPACE 1
410#define UNPCTL_SENDSPACE 2
411#define NET_UNIX_PROTO_MAXID 3
412
413#define CTL_NET_UNIX_PROTO_NAMES { \
414 { 0, 0 }, \
415 { "recvspace", CTLTYPE_INT }, \
416 { "sendspace", CTLTYPE_INT }, \
417}
418
419/*
420 * PF_LINK - link layer or device tunables
421 */
422#define NET_LINK_IFRXQ 1 /* net.link.ifrxq */
423#define NET_LINK_MAXID 2
424
425#define CTL_NET_LINK_NAMES { \
426 { 0, 0 }, \
427 { "ifrxq", CTLTYPE_NODE }, \
428}
429
430#define NET_LINK_IFRXQ_PRESSURE_RETURN \
431 1 /* net.link.ifrxq.pressure_return */
432#define NET_LINK_IFRXQ_PRESSURE_DROP \
433 2 /* net.link.ifrxq.pressure_drop */
434#define NET_LINK_IFRXQ_MAXID 3
435
436#define CTL_NET_LINK_IFRXQ_NAMES { \
437 { 0, 0 }, \
438 { "pressure_return", CTLTYPE_INT }, \
439 { "pressure_drop", CTLTYPE_INT }, \
440}
441
442/*
443 * PF_KEY - Key Management
444 */
445#define NET_KEY_SADB_DUMP 1 /* return SADB */
446#define NET_KEY_SPD_DUMP 2 /* return SPD */
447#define NET_KEY_MAXID 3
448
449#define CTL_NET_KEY_NAMES { \
450 { 0, 0 }, \
451 { "sadb_dump", CTLTYPE_STRUCT }, \
452 { "spd_dump", CTLTYPE_STRUCT }, \
453}
454
455/*
456 * PF_BPF not really a family, but connected under CTL_NET
457 */
458#define NET_BPF_BUFSIZE 1 /* default buffer size */
459#define NET_BPF_MAXBUFSIZE 2 /* maximum buffer size */
460#define NET_BPF_MAXID 3
461
462#define CTL_NET_BPF_NAMES { \
463 { 0, 0 }, \
464 { "bufsize", CTLTYPE_INT }, \
465 { "maxbufsize", CTLTYPE_INT }, \
466}
467
468/*
469 * PF_PFLOW not really a family, but connected under CTL_NET
470 */
471#define NET_PFLOW_STATS 1 /* statistics */
472#define NET_PFLOW_MAXID 2
473
474#define CTL_NET_PFLOW_NAMES { \
475 { 0, 0 }, \
476 { "stats", CTLTYPE_STRUCT }, \
477}
478#endif /* __BSD_VISIBLE */
479
480/*
481 * Maximum queue length specifiable by listen(2).
482 */
483#define SOMAXCONN 128
484
485/*
486 * Message header for recvmsg and sendmsg calls.
487 * Used value-result for recvmsg, value only for sendmsg.
488 */
489struct msghdr {
490 void *msg_name; /* optional address */
491 socklen_t msg_namelen; /* size of address */
492 struct iovec *msg_iov; /* scatter/gather array */
493 unsigned int msg_iovlen; /* # elements in msg_iov */
494 void *msg_control; /* ancillary data, see below */
495 socklen_t msg_controllen; /* ancillary data buffer len */
496 int msg_flags; /* flags on received message */
497};
498
499struct mmsghdr {
500 struct msghdr msg_hdr;
501 unsigned int msg_len;
502};
503
504struct timespec;
505
506#define MSG_OOB 0x1 /* process out-of-band data */
507#define MSG_PEEK 0x2 /* peek at incoming message */
508#define MSG_DONTROUTE 0x4 /* send without using routing tables */
509#define MSG_EOR 0x8 /* data completes record */
510#define MSG_TRUNC 0x10 /* data discarded before delivery */
511#define MSG_CTRUNC 0x20 /* control data lost before delivery */
512#define MSG_WAITALL 0x40 /* wait for full request or error */
513#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
514#define MSG_BCAST 0x100 /* this message rec'd as broadcast */
515#define MSG_MCAST 0x200 /* this message rec'd as multicast */
516#define MSG_NOSIGNAL 0x400 /* do not send SIGPIPE */
517#define MSG_CMSG_CLOEXEC 0x800 /* set FD_CLOEXEC on received fds */
518#define MSG_WAITFORONE 0x1000 /* nonblocking but wait for one msg */
519#define MSG_CMSG_CLOFORK 0x2000 /* set FD_CLOFORK on received fds */
520
521/*
522 * Header for ancillary data objects in msg_control buffer.
523 * Used for additional information with/about a datagram
524 * not expressible by flags. The format is a sequence
525 * of message elements headed by cmsghdr structures.
526 */
527struct cmsghdr {
528 socklen_t cmsg_len; /* data byte count, including hdr */
529 int cmsg_level; /* originating protocol */
530 int cmsg_type; /* protocol-specific type */
531/* followed by u_char cmsg_data[]; */
532};
533
534/* given pointer to struct cmsghdr, return pointer to data */
535#define CMSG_DATA(cmsg) \
536 ((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr)))
537
538/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
539#define CMSG_NXTHDR(mhdr, cmsg) \
540 (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
541 _ALIGN(sizeof(struct cmsghdr)) > \
542 ((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
543 (struct cmsghdr *)NULL : \
544 (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
545
546/*
547 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
548 * an empty list for some reasons.
549 */
550#define CMSG_FIRSTHDR(mhdr) \
551 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
552 (struct cmsghdr *)(mhdr)->msg_control : \
553 (struct cmsghdr *)NULL)
554
555/* Round len up to next alignment boundary */
556#ifdef _KERNEL
557#define CMSG_ALIGN(n) _ALIGN(n)
558#endif
559
560/* Length of the contents of a control message of length len */
561#define CMSG_LEN(len) (_ALIGN(sizeof(struct cmsghdr)) + (len))
562
563/* Length of the space taken up by a padded control message of length len */
564#define CMSG_SPACE(len) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(len))
565
566/* "Socket"-level control message types: */
567#define SCM_RIGHTS 0x01 /* access rights (array of int) */
568#define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */
569
570#ifndef _KERNEL
571
572__BEGIN_DECLS
573int accept(int, struct sockaddr *, socklen_t *);
574int bind(int, const struct sockaddr *, socklen_t);
575int connect(int, const struct sockaddr *, socklen_t);
576int getpeername(int, struct sockaddr *, socklen_t *);
577int getsockname(int, struct sockaddr *, socklen_t *);
578int getsockopt(int, int, int, void *, socklen_t *);
579int listen(int, int);
580ssize_t recv(int, void *, size_t, int);
581ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
582ssize_t recvmsg(int, struct msghdr *, int);
583int recvmmsg(int, struct mmsghdr *, unsigned int, int, struct timespec *);
584ssize_t send(int, const void *, size_t, int);
585ssize_t sendto(int, const void *,
586 size_t, int, const struct sockaddr *, socklen_t);
587ssize_t sendmsg(int, const struct msghdr *, int);
588int sendmmsg(int, struct mmsghdr *, unsigned int, int);
589int setsockopt(int, int, int, const void *, socklen_t);
590int shutdown(int, int);
591int sockatmark(int);
592int socket(int, int, int);
593int socketpair(int, int, int, int *);
594
595#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE
596int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
597#endif
598
599#if __BSD_VISIBLE
600int getpeereid(int, uid_t *, gid_t *);
601int getrtable(void);
602int setrtable(int);
603#endif /* __BSD_VISIBLE */
604
605__END_DECLS
606
607#else
608
609static inline struct sockaddr *
610sstosa(struct sockaddr_storage *ss)
611{
612 return ((struct sockaddr *)(ss));
613}
614
615#endif /* !_KERNEL */
616
617#endif /* !_SYS_SOCKET_H_ */