1f0bf889imp/*-
24736ccfpfg * SPDX-License-Identifier: BSD-3-Clause
34736ccfpfg *
48fb65cergrimes * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
58fb65cergrimes *	The Regents of the University of California.  All rights reserved.
68fb65cergrimes *
78fb65cergrimes * Redistribution and use in source and binary forms, with or without
88fb65cergrimes * modification, are permitted provided that the following conditions
98fb65cergrimes * are met:
108fb65cergrimes * 1. Redistributions of source code must retain the above copyright
118fb65cergrimes *    notice, this list of conditions and the following disclaimer.
128fb65cergrimes * 2. Redistributions in binary form must reproduce the above copyright
138fb65cergrimes *    notice, this list of conditions and the following disclaimer in the
148fb65cergrimes *    documentation and/or other materials provided with the distribution.
157e6cabdimp * 3. Neither the name of the University nor the names of its contributors
168fb65cergrimes *    may be used to endorse or promote products derived from this software
178fb65cergrimes *    without specific prior written permission.
188fb65cergrimes *
198fb65cergrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208fb65cergrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218fb65cergrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228fb65cergrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238fb65cergrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248fb65cergrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258fb65cergrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268fb65cergrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278fb65cergrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288fb65cergrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298fb65cergrimes * SUCH DAMAGE.
308fb65cergrimes *
318fb65cergrimes *	@(#)socket.h	8.4 (Berkeley) 2/21/94
323b842d3peter * $FreeBSD$
338fb65cergrimes */
348fb65cergrimes
358fb65cergrimes#ifndef _SYS_SOCKET_H_
368fb65cergrimes#define	_SYS_SOCKET_H_
378fb65cergrimes
387460c4dmike#include <sys/cdefs.h>
3939f7a31mike#include <sys/_types.h>
40de21d6bphk#include <sys/_iovec.h>
41e645b49phk#include <machine/_align.h>
4297f7cecasmodai
438fb65cergrimes/*
448fb65cergrimes * Definitions related to sockets: types, address families, options.
458fb65cergrimes */
468fb65cergrimes
478fb65cergrimes/*
482431275phk * Data types.
492431275phk */
507460c4dmike#if __BSD_VISIBLE
517460c4dmike#ifndef _GID_T_DECLARED
527460c4dmiketypedef	__gid_t		gid_t;
537460c4dmike#define	_GID_T_DECLARED
547460c4dmike#endif
557460c4dmike
567460c4dmike#ifndef _OFF_T_DECLARED
577460c4dmiketypedef	__off_t		off_t;
587460c4dmike#define	_OFF_T_DECLARED
597460c4dmike#endif
607460c4dmike
617460c4dmike#ifndef _PID_T_DECLARED
627460c4dmiketypedef	__pid_t		pid_t;
637460c4dmike#define	_PID_T_DECLARED
647460c4dmike#endif
657460c4dmike#endif
667460c4dmike
679e6f796mike#ifndef _SA_FAMILY_T_DECLARED
689e6f796miketypedef	__sa_family_t	sa_family_t;
699e6f796mike#define	_SA_FAMILY_T_DECLARED
7039f7a31mike#endif
7139f7a31mike
729e6f796mike#ifndef _SOCKLEN_T_DECLARED
739e6f796miketypedef	__socklen_t	socklen_t;
749e6f796mike#define	_SOCKLEN_T_DECLARED
75bf66c2eume#endif
762431275phk
777460c4dmike#ifndef _SSIZE_T_DECLARED
787460c4dmiketypedef	__ssize_t	ssize_t;
797460c4dmike#define	_SSIZE_T_DECLARED
807460c4dmike#endif
817460c4dmike
827460c4dmike#if __BSD_VISIBLE
837460c4dmike#ifndef _UID_T_DECLARED
847460c4dmiketypedef	__uid_t		uid_t;
857460c4dmike#define	_UID_T_DECLARED
867460c4dmike#endif
877460c4dmike#endif
887460c4dmike
89103d798adrian#ifndef _UINT32_T_DECLARED
90103d798adriantypedef	__uint32_t	uint32_t;
91103d798adrian#define	_UINT32_T_DECLARED
92103d798adrian#endif
93103d798adrian
94103d798adrian#ifndef _UINTPTR_T_DECLARED
95103d798adriantypedef	__uintptr_t	uintptr_t;
96103d798adrian#define	_UINTPTR_T_DECLARED
97103d798adrian#endif
98103d798adrian
992431275phk/*
1008fb65cergrimes * Types
1018fb65cergrimes */
1028fb65cergrimes#define	SOCK_STREAM	1		/* stream socket */
1038fb65cergrimes#define	SOCK_DGRAM	2		/* datagram socket */
1048fb65cergrimes#define	SOCK_RAW	3		/* raw-protocol interface */
1057460c4dmike#if __BSD_VISIBLE
1068fb65cergrimes#define	SOCK_RDM	4		/* reliably-delivered message */
1077460c4dmike#endif
1088fb65cergrimes#define	SOCK_SEQPACKET	5		/* sequenced packet stream */
1098fb65cergrimes
110c9066bdjilles#if __BSD_VISIBLE
111c9066bdjilles/*
112c9066bdjilles * Creation flags, OR'ed into socket() and socketpair() type argument.
113c9066bdjilles */
114c9066bdjilles#define	SOCK_CLOEXEC	0x10000000
115c9066bdjilles#define	SOCK_NONBLOCK	0x20000000
116e35d543glebius#ifdef _KERNEL
117e35d543glebius/*
118e35d543glebius * Flags for accept1(), kern_accept4() and solisten_dequeue, in addition
119e35d543glebius * to SOCK_CLOEXEC and SOCK_NONBLOCK.
120e35d543glebius */
121e35d543glebius#define ACCEPT4_INHERIT 0x1
122e35d543glebius#define ACCEPT4_COMPAT  0x2
123e35d543glebius#endif	/* _KERNEL */
124e35d543glebius#endif	/* __BSD_VISIBLE */
125c9066bdjilles
1268fb65cergrimes/*
1278fb65cergrimes * Option flags per-socket.
1288fb65cergrimes */
129d0aeaa5sbruno#define	SO_DEBUG	0x00000001	/* turn on debugging info recording */
130d0aeaa5sbruno#define	SO_ACCEPTCONN	0x00000002	/* socket has had listen() */
131d0aeaa5sbruno#define	SO_REUSEADDR	0x00000004	/* allow local address reuse */
132d0aeaa5sbruno#define	SO_KEEPALIVE	0x00000008	/* keep connections alive */
133d0aeaa5sbruno#define	SO_DONTROUTE	0x00000010	/* just use interface addresses */
134d0aeaa5sbruno#define	SO_BROADCAST	0x00000020	/* permit sending of broadcast msgs */
1357460c4dmike#if __BSD_VISIBLE
136d0aeaa5sbruno#define	SO_USELOOPBACK	0x00000040	/* bypass hardware when possible */
1377460c4dmike#endif
138d0aeaa5sbruno#define	SO_LINGER	0x00000080	/* linger on close if data present */
139d0aeaa5sbruno#define	SO_OOBINLINE	0x00000100	/* leave received OOB data in line */
1407460c4dmike#if __BSD_VISIBLE
141d0aeaa5sbruno#define	SO_REUSEPORT	0x00000200	/* allow local address & port reuse */
142d0aeaa5sbruno#define	SO_TIMESTAMP	0x00000400	/* timestamp received dgram traffic */
143d0aeaa5sbruno#define	SO_NOSIGPIPE	0x00000800	/* no SIGPIPE from EPIPE */
144d0aeaa5sbruno#define	SO_ACCEPTFILTER	0x00001000	/* there is an accept filter */
145d0aeaa5sbruno#define	SO_BINTIME	0x00002000	/* timestamp received dgram traffic */
1467460c4dmike#endif
147d0aeaa5sbruno#define	SO_NO_OFFLOAD	0x00004000	/* socket cannot be offloaded */
148d0aeaa5sbruno#define	SO_NO_DDP	0x00008000	/* disable direct data placement */
149d0aeaa5sbruno#define	SO_REUSEPORT_LB	0x00010000	/* reuse with load balancing */
1508fb65cergrimes
1518fb65cergrimes/*
1528fb65cergrimes * Additional options, not kept in so_options.
1538fb65cergrimes */
1546d8d0aarwatson#define	SO_SNDBUF	0x1001		/* send buffer size */
1556d8d0aarwatson#define	SO_RCVBUF	0x1002		/* receive buffer size */
1566d8d0aarwatson#define	SO_SNDLOWAT	0x1003		/* send low-water mark */
1576d8d0aarwatson#define	SO_RCVLOWAT	0x1004		/* receive low-water mark */
1586d8d0aarwatson#define	SO_SNDTIMEO	0x1005		/* send timeout */
1596d8d0aarwatson#define	SO_RCVTIMEO	0x1006		/* receive timeout */
1608fb65cergrimes#define	SO_ERROR	0x1007		/* get error status and clear */
1618fb65cergrimes#define	SO_TYPE		0x1008		/* get socket type */
1627460c4dmike#if __BSD_VISIBLE
163d895407rwatson#define	SO_LABEL	0x1009		/* socket's MAC label */
164d895407rwatson#define	SO_PEERLABEL	0x1010		/* socket's peer's MAC label */
165bfb05b4rwatson#define	SO_LISTENQLIMIT	0x1011		/* socket's backlog limit */
166bfb05b4rwatson#define	SO_LISTENQLEN	0x1012		/* socket's complete queue length */
167bfb05b4rwatson#define	SO_LISTENINCQLEN	0x1013	/* socket's incomplete queue length */
1681dfc5c9julian#define	SO_SETFIB	0x1014		/* use this FIB to route */
169d5e8d23luigi#define	SO_USER_COOKIE	0x1015		/* user cookie (dummynet etc.) */
17079e65f6kib#define	SO_PROTOCOL	0x1016		/* get socket protocol (Linux name) */
17179e65f6kib#define	SO_PROTOTYPE	SO_PROTOCOL	/* alias for SO_PROTOCOL (SunOS name) */
1727016975sobomax#define	SO_TS_CLOCK	0x1017		/* clock type used for SO_TIMESTAMP */
173efa6326hselasky#define	SO_MAX_PACING_RATE	0x1018	/* socket's max TX pacing rate (Linux name) */
1743e0ad7dtuexen#define	SO_DOMAIN	0x1019		/* get socket domain */
1757016975sobomax#endif
1767016975sobomax
1777016975sobomax#if __BSD_VISIBLE
1787016975sobomax#define	SO_TS_REALTIME_MICRO	0	/* microsecond resolution, realtime */
1797016975sobomax#define	SO_TS_BINTIME		1	/* sub-nanosecond resolution, realtime */
1807016975sobomax#define	SO_TS_REALTIME		2	/* nanosecond resolution, realtime */
1817016975sobomax#define	SO_TS_MONOTONIC		3	/* nanosecond resolution, monotonic */
1827016975sobomax#define	SO_TS_DEFAULT		SO_TS_REALTIME_MICRO
1837016975sobomax#define	SO_TS_CLOCK_MAX		SO_TS_MONOTONIC
1847460c4dmike#endif
1858fb65cergrimes
1868fb65cergrimes/*
187b55183ajhb * Space reserved for new socket options added by third-party vendors.
188b55183ajhb * This range applies to all socket option levels.  New socket options
189b55183ajhb * in FreeBSD should always use an option value less than SO_VENDOR.
190b55183ajhb */
191b55183ajhb#if __BSD_VISIBLE
192b55183ajhb#define	SO_VENDOR	0x80000000
193b55183ajhb#endif
194b55183ajhb
195b55183ajhb/*
1968fb65cergrimes * Structure used for manipulating linger option.
1978fb65cergrimes */
19840da6b0obrienstruct linger {
1998fb65cergrimes	int	l_onoff;		/* option on/off */
2008fb65cergrimes	int	l_linger;		/* linger time */
2018fb65cergrimes};
2028fb65cergrimes
2037460c4dmike#if __BSD_VISIBLE
20440da6b0obrienstruct accept_filter_arg {
205e3e72a5alfred	char	af_name[16];
206e3e72a5alfred	char	af_arg[256-16];
207e3e72a5alfred};
2087460c4dmike#endif
209e3e72a5alfred
2108fb65cergrimes/*
2118fb65cergrimes * Level number for (get/set)sockopt() to apply to socket itself.
2128fb65cergrimes */
2138fb65cergrimes#define	SOL_SOCKET	0xffff		/* options for socket level */
2148fb65cergrimes
2158fb65cergrimes/*
2168fb65cergrimes * Address families.
2178fb65cergrimes */
2188fb65cergrimes#define	AF_UNSPEC	0		/* unspecified */
2197460c4dmike#if __BSD_VISIBLE
22002c7d00mike#define	AF_LOCAL	AF_UNIX		/* local to host (pipes, portals) */
2217460c4dmike#endif
22202c7d00mike#define	AF_UNIX		1		/* standardized name for AF_LOCAL */
2238fb65cergrimes#define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
2247460c4dmike#if __BSD_VISIBLE
2258fb65cergrimes#define	AF_IMPLINK	3		/* arpanet imp addresses */
2268fb65cergrimes#define	AF_PUP		4		/* pup protocols: e.g. BSP */
2278fb65cergrimes#define	AF_CHAOS	5		/* mit CHAOS protocols */
228fbc7526peter#define	AF_NETBIOS	6		/* SMB protocols */
2298fb65cergrimes#define	AF_ISO		7		/* ISO protocols */
2308fb65cergrimes#define	AF_OSI		AF_ISO
231f3dd75ampp#define	AF_ECMA		8		/* European computer manufacturers */
2328fb65cergrimes#define	AF_DATAKIT	9		/* datakit protocols */
2338fb65cergrimes#define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
2348fb65cergrimes#define	AF_SNA		11		/* IBM SNA */
2358fb65cergrimes#define AF_DECnet	12		/* DECnet */
2368fb65cergrimes#define AF_DLI		13		/* DEC Direct data link interface */
2378fb65cergrimes#define AF_LAT		14		/* LAT */
2388fb65cergrimes#define	AF_HYLINK	15		/* NSC Hyperchannel */
2398fb65cergrimes#define	AF_APPLETALK	16		/* Apple Talk */
2408fb65cergrimes#define	AF_ROUTE	17		/* Internal Routing Protocol */
2418fb65cergrimes#define	AF_LINK		18		/* Link layer interface */
2428fb65cergrimes#define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
2438fb65cergrimes#define	AF_COIP		20		/* connection-oriented IP, aka ST II */
2448fb65cergrimes#define	AF_CNT		21		/* Computer Network Technology */
2458fb65cergrimes#define pseudo_AF_RTIP	22		/* Help Identify RTIP packets */
2468fb65cergrimes#define	AF_IPX		23		/* Novell Internet Protocol */
2478fb65cergrimes#define	AF_SIP		24		/* Simple Internet Protocol */
2485d7722cse#define	pseudo_AF_PIP	25		/* Help Identify PIP packets */
2495d7722cse#define	AF_ISDN		26		/* Integrated Services Digital Network*/
2505d7722cse#define	AF_E164		AF_ISDN		/* CCITT E.164 recommendation */
251845782bwollman#define	pseudo_AF_KEY	27		/* Internal key-management function */
2527460c4dmike#endif
253d8c7a95peter#define	AF_INET6	28		/* IPv6 */
2547460c4dmike#if __BSD_VISIBLE
2552b17ef6kjc#define	AF_NATM		29		/* native ATM access */
256cfbddb7phk#define	AF_ATM		30		/* ATM */
257010a32dmsmith#define pseudo_AF_HDRCMPLT 31		/* Used by BPF to not rewrite headers
258010a32dmsmith					 * in interface output routine
259010a32dmsmith					 */
2608c2a435julian#define	AF_NETGRAPH	32		/* Netgraph sockets */
2619512447grog#define	AF_SLOW		33		/* 802.3ad slow protocol */
2629512447grog#define	AF_SCLUSTER	34		/* Sitara cluster protocol */
263deef4b0mdodd#define	AF_ARP		35
2647cd8d76emax#define	AF_BLUETOOTH	36		/* Bluetooth sockets */
265a245550sam#define	AF_IEEE80211	37		/* IEEE 802.11 protocol */
2665f141f7jeff#define	AF_INET_SDP	40		/* OFED Socket Direct Protocol ipv4 */
2675f141f7jeff#define	AF_INET6_SDP	42		/* OFED Socket Direct Protocol ipv6 */
2685f141f7jeff#define	AF_MAX		42
2697100da0alfred/*
2707100da0alfred * When allocating a new AF_ constant, please only allocate
2717100da0alfred * even numbered constants for FreeBSD until 134 as odd numbered AF_
2727100da0alfred * constants 39-133 are now reserved for vendors.
2737100da0alfred */
2747100da0alfred#define AF_VENDOR00 39
2757100da0alfred#define AF_VENDOR01 41
2767100da0alfred#define AF_VENDOR02 43
2777100da0alfred#define AF_VENDOR03 45
2787100da0alfred#define AF_VENDOR04 47
2797100da0alfred#define AF_VENDOR05 49
2807100da0alfred#define AF_VENDOR06 51
2817100da0alfred#define AF_VENDOR07 53
2827100da0alfred#define AF_VENDOR08 55
2837100da0alfred#define AF_VENDOR09 57
2847100da0alfred#define AF_VENDOR10 59
2857100da0alfred#define AF_VENDOR11 61
2867100da0alfred#define AF_VENDOR12 63
2877100da0alfred#define AF_VENDOR13 65
2887100da0alfred#define AF_VENDOR14 67
2897100da0alfred#define AF_VENDOR15 69
2907100da0alfred#define AF_VENDOR16 71
2917100da0alfred#define AF_VENDOR17 73
2927100da0alfred#define AF_VENDOR18 75
2937100da0alfred#define AF_VENDOR19 77
2947100da0alfred#define AF_VENDOR20 79
2957100da0alfred#define AF_VENDOR21 81
2967100da0alfred#define AF_VENDOR22 83
2977100da0alfred#define AF_VENDOR23 85
2987100da0alfred#define AF_VENDOR24 87
2997100da0alfred#define AF_VENDOR25 89
3007100da0alfred#define AF_VENDOR26 91
3017100da0alfred#define AF_VENDOR27 93
3027100da0alfred#define AF_VENDOR28 95
3037100da0alfred#define AF_VENDOR29 97
3047100da0alfred#define AF_VENDOR30 99
3057100da0alfred#define AF_VENDOR31 101
3067100da0alfred#define AF_VENDOR32 103
3077100da0alfred#define AF_VENDOR33 105
3087100da0alfred#define AF_VENDOR34 107
3097100da0alfred#define AF_VENDOR35 109
3107100da0alfred#define AF_VENDOR36 111
3117100da0alfred#define AF_VENDOR37 113
3127100da0alfred#define AF_VENDOR38 115
3137100da0alfred#define AF_VENDOR39 117
3147100da0alfred#define AF_VENDOR40 119
3157100da0alfred#define AF_VENDOR41 121
3167100da0alfred#define AF_VENDOR42 123
3177100da0alfred#define AF_VENDOR43 125
3187100da0alfred#define AF_VENDOR44 127
3197100da0alfred#define AF_VENDOR45 129
3207100da0alfred#define AF_VENDOR46 131
3217100da0alfred#define AF_VENDOR47 133
3227460c4dmike#endif
3238fb65cergrimes
3248fb65cergrimes/*
3258fb65cergrimes * Structure used by kernel to store most
3268fb65cergrimes * addresses.
3278fb65cergrimes */
3288fb65cergrimesstruct sockaddr {
3297460c4dmike	unsigned char	sa_len;		/* total length */
3302431275phk	sa_family_t	sa_family;	/* address family */
3312431275phk	char		sa_data[14];	/* actually longer; address value */
3328fb65cergrimes};
3337460c4dmike#if __BSD_VISIBLE
3344542c1cwollman#define	SOCK_MAXADDRLEN	255		/* longest possible addresses */
3358fb65cergrimes
3368fb65cergrimes/*
3378fb65cergrimes * Structure used by kernel to pass protocol
3388fb65cergrimes * information in raw sockets.
3398fb65cergrimes */
3408fb65cergrimesstruct sockproto {
3417460c4dmike	unsigned short	sp_family;		/* address family */
3427460c4dmike	unsigned short	sp_protocol;		/* protocol */
3438fb65cergrimes};
3447460c4dmike#endif
3458fb65cergrimes
346c8ab4abphk#include <sys/_sockaddr_storage.h>
3477efc91cshin
3487460c4dmike#if __BSD_VISIBLE
3497efc91cshin/*
3508fb65cergrimes * Protocol families, same as address families for now.
3518fb65cergrimes */
3528fb65cergrimes#define	PF_UNSPEC	AF_UNSPEC
3538fb65cergrimes#define	PF_LOCAL	AF_LOCAL
3548fb65cergrimes#define	PF_UNIX		PF_LOCAL	/* backward compatibility */
3558fb65cergrimes#define	PF_INET		AF_INET
3568fb65cergrimes#define	PF_IMPLINK	AF_IMPLINK
3578fb65cergrimes#define	PF_PUP		AF_PUP
3588fb65cergrimes#define	PF_CHAOS	AF_CHAOS
359fbc7526peter#define	PF_NETBIOS	AF_NETBIOS
3608fb65cergrimes#define	PF_ISO		AF_ISO
3618fb65cergrimes#define	PF_OSI		AF_ISO
3628fb65cergrimes#define	PF_ECMA		AF_ECMA
3638fb65cergrimes#define	PF_DATAKIT	AF_DATAKIT
3648fb65cergrimes#define	PF_CCITT	AF_CCITT
3658fb65cergrimes#define	PF_SNA		AF_SNA
3668fb65cergrimes#define PF_DECnet	AF_DECnet
3678fb65cergrimes#define PF_DLI		AF_DLI
3688fb65cergrimes#define PF_LAT		AF_LAT
3698fb65cergrimes#define	PF_HYLINK	AF_HYLINK
3708fb65cergrimes#define	PF_APPLETALK	AF_APPLETALK
3718fb65cergrimes#define	PF_ROUTE	AF_ROUTE
3728fb65cergrimes#define	PF_LINK		AF_LINK
3738fb65cergrimes#define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
3748fb65cergrimes#define	PF_COIP		AF_COIP
3758fb65cergrimes#define	PF_CNT		AF_CNT
3768fb65cergrimes#define	PF_SIP		AF_SIP
377fbc7526peter#define	PF_IPX		AF_IPX
378c244429jdp#define PF_RTIP		pseudo_AF_RTIP	/* same format as AF_INET */
3798fb65cergrimes#define PF_PIP		pseudo_AF_PIP
3805d7722cse#define	PF_ISDN		AF_ISDN
381358b715wollman#define	PF_KEY		pseudo_AF_KEY
382d8c7a95peter#define	PF_INET6	AF_INET6
3832b17ef6kjc#define	PF_NATM		AF_NATM
384cfbddb7phk#define	PF_ATM		AF_ATM
385c5c6397julian#define	PF_NETGRAPH	AF_NETGRAPH
3869512447grog#define	PF_SLOW		AF_SLOW
3879512447grog#define PF_SCLUSTER	AF_SCLUSTER
388deef4b0mdodd#define	PF_ARP		AF_ARP
3897cd8d76emax#define	PF_BLUETOOTH	AF_BLUETOOTH
39035a29fbkevlo#define	PF_IEEE80211	AF_IEEE80211
3915f141f7jeff#define	PF_INET_SDP	AF_INET_SDP
3925f141f7jeff#define	PF_INET6_SDP	AF_INET6_SDP
3938fb65cergrimes
3948fb65cergrimes#define	PF_MAX		AF_MAX
3958fb65cergrimes
3968fb65cergrimes/*
3978fb65cergrimes * Definitions for network related sysctl, CTL_NET.
3988fb65cergrimes *
3998fb65cergrimes * Second level is protocol family.
4008fb65cergrimes * Third level is protocol number.
4018fb65cergrimes *
402d9d6b88jhb * Further levels are defined by the individual families.
4038fb65cergrimes */
4048fb65cergrimes
4058fb65cergrimes/*
4068fb65cergrimes * PF_ROUTE - Routing table
4078fb65cergrimes *
4088fb65cergrimes * Three additional levels are defined:
4098fb65cergrimes *	Fourth: address family, 0 is wildcard
4108fb65cergrimes *	Fifth: type of info, defined below
4118fb65cergrimes *	Sixth: flag(s) to mask with for NET_RT_FLAGS
4128fb65cergrimes */
4138fb65cergrimes#define NET_RT_DUMP	1		/* dump; may limit to a.f. */
4148fb65cergrimes#define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
4158fb65cergrimes#define NET_RT_IFLIST	3		/* survey interface list */
4160cfaf20bms#define	NET_RT_IFMALIST	4		/* return multicast address list */
417d05091dbz#define	NET_RT_IFLISTL	5		/* Survey interface list, using 'l'en
418d05091dbz					 * versions of msghdr structs. */
4197460c4dmike#endif /* __BSD_VISIBLE */
4208fb65cergrimes
4218fb65cergrimes/*
4228fb65cergrimes * Maximum queue length specifiable by listen.
4238fb65cergrimes */
424d0328cbdg#define	SOMAXCONN	128
4258fb65cergrimes
4268fb65cergrimes/*
4278fb65cergrimes * Message header for recvmsg and sendmsg calls.
4288fb65cergrimes * Used value-result for recvmsg, value only for sendmsg.
4298fb65cergrimes */
4308fb65cergrimesstruct msghdr {
4312431275phk	void		*msg_name;		/* optional address */
4322431275phk	socklen_t	 msg_namelen;		/* size of address */
4332431275phk	struct iovec	*msg_iov;		/* scatter/gather array */
4342431275phk	int		 msg_iovlen;		/* # elements in msg_iov */
4352431275phk	void		*msg_control;		/* ancillary data, see below */
4362431275phk	socklen_t	 msg_controllen;	/* ancillary data buffer len */
4372431275phk	int		 msg_flags;		/* flags on received message */
4388fb65cergrimes};
4398fb65cergrimes
44057e9366glebius#define	MSG_OOB		 0x00000001	/* process out-of-band data */
44157e9366glebius#define	MSG_PEEK	 0x00000002	/* peek at incoming message */
44257e9366glebius#define	MSG_DONTROUTE	 0x00000004	/* send without using routing tables */
44357e9366glebius#define	MSG_EOR		 0x00000008	/* data completes record */
44457e9366glebius#define	MSG_TRUNC	 0x00000010	/* data discarded before delivery */
44557e9366glebius#define	MSG_CTRUNC	 0x00000020	/* control data lost before delivery */
44657e9366glebius#define	MSG_WAITALL	 0x00000040	/* wait for full request or error */
44757e9366glebius#if __BSD_VISIBLE
44857e9366glebius#define	MSG_DONTWAIT	 0x00000080	/* this message should be nonblocking */
44957e9366glebius#define	MSG_EOF		 0x00000100	/* data completes connection */
45057e9366glebius/*			 0x00000200	   unused */
45157e9366glebius/*			 0x00000400	   unused */
45257e9366glebius/*			 0x00000800	   unused */
45357e9366glebius/*			 0x00001000	   unused */
45457e9366glebius#define	MSG_NOTIFICATION 0x00002000	/* SCTP notification */
45557e9366glebius#define	MSG_NBIO	 0x00004000	/* FIONBIO mode, used by fifofs */
45657e9366glebius#define	MSG_COMPAT       0x00008000		/* used in sendit() */
45757e9366glebius#endif
45857e9366glebius#ifdef _KERNEL
45957e9366glebius#define	MSG_SOCALLBCK    0x00010000	/* for use by socket callbacks - soreceive (TCP) */
46057e9366glebius#endif
461c0fce54jilles#if __POSIX_VISIBLE >= 200809
46257e9366glebius#define	MSG_NOSIGNAL	 0x00020000	/* do not generate SIGPIPE on EOF */
463c0fce54jilles#endif
4647460c4dmike#if __BSD_VISIBLE
46557e9366glebius#define	MSG_CMSG_CLOEXEC 0x00040000	/* make received fds close-on-exec */
46657e9366glebius#define	MSG_WAITFORONE	 0x00080000	/* for recvmmsg() */
4677460c4dmike#endif
4688932ce4ps#ifdef _KERNEL
46957e9366glebius#define	MSG_MORETOCOME	 0x00100000	/* additional data pending */
47093318a5alfred#endif
4718fb65cergrimes
4728fb65cergrimes/*
4738fb65cergrimes * Header for ancillary data objects in msg_control buffer.
4748fb65cergrimes * Used for additional information with/about a datagram
4758fb65cergrimes * not expressible by flags.  The format is a sequence
4768fb65cergrimes * of message elements headed by cmsghdr structures.
4778fb65cergrimes */
4788fb65cergrimesstruct cmsghdr {
4792431275phk	socklen_t	cmsg_len;		/* data byte count, including hdr */
4802431275phk	int		cmsg_level;		/* originating protocol */
4812431275phk	int		cmsg_type;		/* protocol-specific type */
4828fb65cergrimes/* followed by	u_char  cmsg_data[]; */
4838fb65cergrimes};
4848fb65cergrimes
4857460c4dmike#if __BSD_VISIBLE
486cdd7ea4wpaul/*
487cdd7ea4wpaul * While we may have more groups than this, the cmsgcred struct must
4885d17dfcbrooks * be able to fit in an mbuf and we have historically supported a
4895d17dfcbrooks * maximum of 16 groups.
490cdd7ea4wpaul*/
491cdd7ea4wpaul#define CMGROUP_MAX 16
492cdd7ea4wpaul
493cdd7ea4wpaul/*
494cdd7ea4wpaul * Credentials structure, used to verify the identity of a peer
495cdd7ea4wpaul * process that has sent us a message. This is allocated by the
496cdd7ea4wpaul * peer process but filled in by the kernel. This prevents the
497cdd7ea4wpaul * peer from lying about its identity. (Note that cmcred_groups[0]
498cdd7ea4wpaul * is the effective GID.)
499cdd7ea4wpaul */
500cdd7ea4wpaulstruct cmsgcred {
501cdd7ea4wpaul	pid_t	cmcred_pid;		/* PID of sending process */
502cdd7ea4wpaul	uid_t	cmcred_uid;		/* real UID of sending process */
503cdd7ea4wpaul	uid_t	cmcred_euid;		/* effective UID of sending process */
504cdd7ea4wpaul	gid_t	cmcred_gid;		/* real GID of sending process */
505cdd7ea4wpaul	short	cmcred_ngroups;		/* number or groups */
506cdd7ea4wpaul	gid_t	cmcred_groups[CMGROUP_MAX];	/* groups */
507cdd7ea4wpaul};
508bdcac6amdodd
509bdcac6amdodd/*
510bdcac6amdodd * Socket credentials.
511bdcac6amdodd */
512bdcac6amdoddstruct sockcred {
513bdcac6amdodd	uid_t	sc_uid;			/* real user id */
514bdcac6amdodd	uid_t	sc_euid;		/* effective user id */
515bdcac6amdodd	gid_t	sc_gid;			/* real group id */
516bdcac6amdodd	gid_t	sc_egid;		/* effective group id */
517bdcac6amdodd	int	sc_ngroups;		/* number of supplemental groups */
518bdcac6amdodd	gid_t	sc_groups[1];		/* variable length */
519bdcac6amdodd};
520bdcac6amdodd
521bdcac6amdodd/*
522bdcac6amdodd * Compute size of a sockcred structure with groups.
523bdcac6amdodd */
524bdcac6amdodd#define	SOCKCREDSIZE(ngrps) \
525bdcac6amdodd	(sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
526bdcac6amdodd
5277460c4dmike#endif /* __BSD_VISIBLE */
528cdd7ea4wpaul
5298fb65cergrimes/* given pointer to struct cmsghdr, return pointer to data */
5307460c4dmike#define	CMSG_DATA(cmsg)		((unsigned char *)(cmsg) + \
53193040d6ume				 _ALIGN(sizeof(struct cmsghdr)))
5327efc91cshin
5338fb65cergrimes/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
5348fb65cergrimes#define	CMSG_NXTHDR(mhdr, cmsg)	\
53525d51f7ed	((char *)(cmsg) == (char *)0 ? CMSG_FIRSTHDR(mhdr) : \
536b79ecebmtm	    ((char *)(cmsg) + _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len) + \
53793040d6ume	  _ALIGN(sizeof(struct cmsghdr)) > \
5387460c4dmike	    (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
5393a09483harti	    (struct cmsghdr *)0 : \
540933648djilles	    (struct cmsghdr *)(void *)((char *)(cmsg) + \
541b79ecebmtm	    _ALIGN(((struct cmsghdr *)(cmsg))->cmsg_len)))
5428fb65cergrimes
543000bdd6andre/*
544000bdd6andre * RFC 2292 requires to check msg_controllen, in case that the kernel returns
545000bdd6andre * an empty list for some reasons.
546000bdd6andre */
547000bdd6andre#define	CMSG_FIRSTHDR(mhdr) \
548000bdd6andre	((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
549000bdd6andre	 (struct cmsghdr *)(mhdr)->msg_control : \
55025d51f7ed	 (struct cmsghdr *)0)
5518fb65cergrimes
5527460c4dmike#if __BSD_VISIBLE
553bf5d99easmodai/* RFC 2292 additions */
55493040d6ume#define	CMSG_SPACE(l)		(_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
55593040d6ume#define	CMSG_LEN(l)		(_ALIGN(sizeof(struct cmsghdr)) + (l))
5567460c4dmike#endif
557832f8d2ume
55893040d6ume#ifdef _KERNEL
55993040d6ume#define	CMSG_ALIGN(n)	_ALIGN(n)
56093040d6ume#endif
5617efc91cshin
5628fb65cergrimes/* "Socket"-level control message types: */
5638fb65cergrimes#define	SCM_RIGHTS	0x01		/* access rights (array of int) */
5647460c4dmike#if __BSD_VISIBLE
5659ea36adwollman#define	SCM_TIMESTAMP	0x02		/* timestamp (struct timeval) */
566cdd7ea4wpaul#define	SCM_CREDS	0x03		/* process creds (struct cmsgcred) */
56735592dephk#define	SCM_BINTIME	0x04		/* timestamp (struct bintime) */
5687016975sobomax#define	SCM_REALTIME	0x05		/* timestamp (struct timespec) */
5697016975sobomax#define	SCM_MONOTONIC	0x06		/* timestamp (struct timespec) */
570b5d757fkib#define	SCM_TIME_INFO	0x07		/* timestamp info */
571b5d757fkib
572b5d757fkibstruct sock_timestamp_info {
573b5d757fkib	__uint32_t	st_info_flags;
574b5d757fkib	__uint32_t	st_info_pad0;
575b5d757fkib	__uint64_t	st_info_rsv[7];
576b5d757fkib};
577b5d757fkib
578b5d757fkib#define	ST_INFO_HW		0x0001		/* SCM_TIMESTAMP was hw */
579b5d757fkib#define	ST_INFO_HW_HPREC	0x0002		/* SCM_TIMESTAMP was hw-assisted
580b5d757fkib						   on entrance */
5817460c4dmike#endif
5828fb65cergrimes
5837460c4dmike#if __BSD_VISIBLE
5848fb65cergrimes/*
5858fb65cergrimes * 4.3 compat sockaddr, move to compat file later
5868fb65cergrimes */
5878fb65cergrimesstruct osockaddr {
5887460c4dmike	unsigned short sa_family;	/* address family */
5898fb65cergrimes	char	sa_data[14];		/* up to 14 bytes of direct address */
5908fb65cergrimes};
5918fb65cergrimes
5928fb65cergrimes/*
5938fb65cergrimes * 4.3-compat message header (move to compat file later).
5948fb65cergrimes */
5958fb65cergrimesstruct omsghdr {
5967460c4dmike	char	*msg_name;		/* optional address */
5978fb65cergrimes	int	msg_namelen;		/* size of address */
5988fb65cergrimes	struct	iovec *msg_iov;		/* scatter/gather array */
5998fb65cergrimes	int	msg_iovlen;		/* # elements in msg_iov */
6007460c4dmike	char	*msg_accrights;		/* access rights sent/received */
6018fb65cergrimes	int	msg_accrightslen;
6028fb65cergrimes};
6037460c4dmike#endif
6048fb65cergrimes
605f91828fwollman/*
606f91828fwollman * howto arguments for shutdown(2), specified by Posix.1g.
607f91828fwollman */
608f91828fwollman#define	SHUT_RD		0		/* shut down the reading side */
609f91828fwollman#define	SHUT_WR		1		/* shut down the writing side */
610f91828fwollman#define	SHUT_RDWR	2		/* shut down both sides */
611f91828fwollman
612c0fce54jilles#if __BSD_VISIBLE
613c0fce54jilles/* for SCTP */
6145759bc8rrs/* we cheat and use the SHUT_XX defines for these */
6155759bc8rrs#define PRU_FLUSH_RD     SHUT_RD
6165759bc8rrs#define PRU_FLUSH_WR     SHUT_WR
6175759bc8rrs#define PRU_FLUSH_RDWR   SHUT_RDWR
618c0fce54jilles#endif
6195759bc8rrs
6205759bc8rrs
6217460c4dmike#if __BSD_VISIBLE
622b178f74dg/*
623b178f74dg * sendfile(2) header/trailer struct
624b178f74dg */
625b178f74dgstruct sf_hdtr {
626b178f74dg	struct iovec *headers;	/* pointer to an array of header struct iovec's */
627b178f74dg	int hdr_cnt;		/* number of header iovec's */
628b178f74dg	struct iovec *trailers;	/* pointer to an array of trailer struct iovec's */
629b178f74dg	int trl_cnt;		/* number of trailer iovec's */
630b178f74dg};
6319428de1silby
6329428de1silby/*
6339428de1silby * Sendfile-specific flag(s)
6349428de1silby */
63542a69dcandre#define	SF_NODISKIO     0x00000001
636aaa0977glebius#define	SF_MNOWAIT	0x00000002	/* obsolete */
6371313284phk#define	SF_SYNC		0x00000004
638b739d60glebius#define	SF_USER_READAHEAD	0x00000008
639aaa0977glebius#define	SF_NOCACHE	0x00000010
640aaa0977glebius#define	SF_FLAGS(rh, flags)	(((rh) << 16) | (flags))
641722a1a5glebius
642722a1a5glebius#ifdef _KERNEL
643aaa0977glebius#define	SF_READAHEAD(flags)	((flags) >> 16)
644722a1a5glebius#endif /* _KERNEL */
6456c0e620kib
6466c0e620kib/*
6476c0e620kib * Sendmmsg/recvmmsg specific structure(s)
6486c0e620kib */
6496c0e620kibstruct mmsghdr {
6506c0e620kib	struct msghdr	msg_hdr;		/* message header */
6516c0e620kib	ssize_t		msg_len;		/* message length */
6526c0e620kib};
653722a1a5glebius#endif /* __BSD_VISIBLE */
654b178f74dg
65515b9bcbpeter#ifndef	_KERNEL
6568fb65cergrimes
6578fb65cergrimes#include <sys/cdefs.h>
6588fb65cergrimes
6598fb65cergrimes__BEGIN_DECLS
660c4b798aalfredint	accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
6613b2d03balfredint	bind(int, const struct sockaddr *, socklen_t);
6623b2d03balfredint	connect(int, const struct sockaddr *, socklen_t);
663c0fce54jilles#if __BSD_VISIBLE
664299afd2jillesint	accept4(int, struct sockaddr * __restrict, socklen_t * __restrict, int);
665c0fce54jillesint	bindat(int, int, const struct sockaddr *, socklen_t);
666702516epjdint	connectat(int, int, const struct sockaddr *, socklen_t);
667c0fce54jilles#endif
668c4b798aalfredint	getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
669c4b798aalfredint	getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
670c4b798aalfredint	getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
6713b2d03balfredint	listen(int, int);
6723b2d03balfredssize_t	recv(int, void *, size_t, int);
673c4b798aalfredssize_t	recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
6743b2d03balfredssize_t	recvmsg(int, struct msghdr *, int);
6756c0e620kib#if __BSD_VISIBLE
6766c0e620kibstruct timespec;
6776c0e620kibssize_t	recvmmsg(int, struct mmsghdr * __restrict, size_t, int,
6786c0e620kib    const struct timespec * __restrict);
6796c0e620kib#endif
6803b2d03balfredssize_t	send(int, const void *, size_t, int);
6813b2d03balfredssize_t	sendto(int, const void *,
6823b2d03balfred	    size_t, int, const struct sockaddr *, socklen_t);
6833b2d03balfredssize_t	sendmsg(int, const struct msghdr *, int);
6847460c4dmike#if __BSD_VISIBLE
6853b2d03balfredint	sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
6866c0e620kibssize_t	sendmmsg(int, struct mmsghdr * __restrict, size_t, int);
68767cdccddelphijint	setfib(int);
6887460c4dmike#endif
6893b2d03balfredint	setsockopt(int, int, int, const void *, socklen_t);
6903b2d03balfredint	shutdown(int, int);
6910347b39fennerint	sockatmark(int);
6923b2d03balfredint	socket(int, int, int);
6933b2d03balfredint	socketpair(int, int, int, int *);
6948fb65cergrimes__END_DECLS
6958fb65cergrimes
69615b9bcbpeter#endif /* !_KERNEL */
6977fb46d4bde
698565bc00