socket.h revision 163913
1139825Simp/*-
21541Srgrimes * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)socket.h	8.4 (Berkeley) 2/21/94
3050477Speter * $FreeBSD: head/sys/sys/socket.h 163913 2006-11-02 16:53:26Z andre $
311541Srgrimes */
321541Srgrimes
331541Srgrimes#ifndef _SYS_SOCKET_H_
341541Srgrimes#define	_SYS_SOCKET_H_
351541Srgrimes
36104983Smike#include <sys/cdefs.h>
3795099Smike#include <sys/_types.h>
38108366Sphk#include <sys/_iovec.h>
3968498Sasmodai#define _NO_NAMESPACE_POLLUTION
4068498Sasmodai#include <machine/param.h>
4168498Sasmodai#undef _NO_NAMESPACE_POLLUTION
4268498Sasmodai
431541Srgrimes/*
441541Srgrimes * Definitions related to sockets: types, address families, options.
451541Srgrimes */
461541Srgrimes
471541Srgrimes/*
4853678Sphk * Data types.
4953678Sphk */
50104983Smike#if __BSD_VISIBLE
51104983Smike#ifndef _GID_T_DECLARED
52104983Smiketypedef	__gid_t		gid_t;
53104983Smike#define	_GID_T_DECLARED
54104983Smike#endif
55104983Smike
56104983Smike#ifndef _OFF_T_DECLARED
57104983Smiketypedef	__off_t		off_t;
58104983Smike#define	_OFF_T_DECLARED
59104983Smike#endif
60104983Smike
61104983Smike#ifndef _PID_T_DECLARED
62104983Smiketypedef	__pid_t		pid_t;
63104983Smike#define	_PID_T_DECLARED
64104983Smike#endif
65104983Smike#endif
66104983Smike
67102227Smike#ifndef _SA_FAMILY_T_DECLARED
68102227Smiketypedef	__sa_family_t	sa_family_t;
69102227Smike#define	_SA_FAMILY_T_DECLARED
7095099Smike#endif
7195099Smike
72102227Smike#ifndef _SOCKLEN_T_DECLARED
73102227Smiketypedef	__socklen_t	socklen_t;
74102227Smike#define	_SOCKLEN_T_DECLARED
7572510Sume#endif
7653678Sphk
77104983Smike#ifndef _SSIZE_T_DECLARED
78104983Smiketypedef	__ssize_t	ssize_t;
79104983Smike#define	_SSIZE_T_DECLARED
80104983Smike#endif
81104983Smike
82104983Smike#if __BSD_VISIBLE
83104983Smike#ifndef _UID_T_DECLARED
84104983Smiketypedef	__uid_t		uid_t;
85104983Smike#define	_UID_T_DECLARED
86104983Smike#endif
87104983Smike#endif
88104983Smike
8953678Sphk/*
901541Srgrimes * Types
911541Srgrimes */
921541Srgrimes#define	SOCK_STREAM	1		/* stream socket */
931541Srgrimes#define	SOCK_DGRAM	2		/* datagram socket */
941541Srgrimes#define	SOCK_RAW	3		/* raw-protocol interface */
95104983Smike#if __BSD_VISIBLE
961541Srgrimes#define	SOCK_RDM	4		/* reliably-delivered message */
97104983Smike#endif
981541Srgrimes#define	SOCK_SEQPACKET	5		/* sequenced packet stream */
991541Srgrimes
1001541Srgrimes/*
1011541Srgrimes * Option flags per-socket.
1021541Srgrimes */
1031541Srgrimes#define	SO_DEBUG	0x0001		/* turn on debugging info recording */
1041541Srgrimes#define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
1051541Srgrimes#define	SO_REUSEADDR	0x0004		/* allow local address reuse */
1061541Srgrimes#define	SO_KEEPALIVE	0x0008		/* keep connections alive */
1071541Srgrimes#define	SO_DONTROUTE	0x0010		/* just use interface addresses */
1081541Srgrimes#define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
109104983Smike#if __BSD_VISIBLE
1101541Srgrimes#define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
111104983Smike#endif
1121541Srgrimes#define	SO_LINGER	0x0080		/* linger on close if data present */
1131541Srgrimes#define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
114104983Smike#if __BSD_VISIBLE
1151541Srgrimes#define	SO_REUSEPORT	0x0200		/* allow local address & port reuse */
11615701Swollman#define	SO_TIMESTAMP	0x0400		/* timestamp received dgram traffic */
11798499Salfred#define	SO_NOSIGPIPE	0x0800		/* no SIGPIPE from EPIPE */
11861837Salfred#define	SO_ACCEPTFILTER	0x1000		/* there is an accept filter */
119125264Sphk#define	SO_BINTIME	0x2000		/* timestamp received dgram traffic */
120104983Smike#endif
1211541Srgrimes
1221541Srgrimes/*
1231541Srgrimes * Additional options, not kept in so_options.
1241541Srgrimes */
12598212Srwatson#define	SO_SNDBUF	0x1001		/* send buffer size */
12698212Srwatson#define	SO_RCVBUF	0x1002		/* receive buffer size */
12798212Srwatson#define	SO_SNDLOWAT	0x1003		/* send low-water mark */
12898212Srwatson#define	SO_RCVLOWAT	0x1004		/* receive low-water mark */
12998212Srwatson#define	SO_SNDTIMEO	0x1005		/* send timeout */
13098212Srwatson#define	SO_RCVTIMEO	0x1006		/* receive timeout */
1311541Srgrimes#define	SO_ERROR	0x1007		/* get error status and clear */
1321541Srgrimes#define	SO_TYPE		0x1008		/* get socket type */
133104983Smike#if __BSD_VISIBLE
13498213Srwatson#define	SO_LABEL	0x1009		/* socket's MAC label */
13598213Srwatson#define	SO_PEERLABEL	0x1010		/* socket's peer's MAC label */
136150302Srwatson#define	SO_LISTENQLIMIT	0x1011		/* socket's backlog limit */
137150302Srwatson#define	SO_LISTENQLEN	0x1012		/* socket's complete queue length */
138150302Srwatson#define	SO_LISTENINCQLEN	0x1013	/* socket's incomplete queue length */
139104983Smike#endif
1401541Srgrimes
1411541Srgrimes/*
1421541Srgrimes * Structure used for manipulating linger option.
1431541Srgrimes */
14483045Sobrienstruct linger {
1451541Srgrimes	int	l_onoff;		/* option on/off */
1461541Srgrimes	int	l_linger;		/* linger time */
1471541Srgrimes};
1481541Srgrimes
149104983Smike#if __BSD_VISIBLE
15083045Sobrienstruct accept_filter_arg {
15161837Salfred	char	af_name[16];
15261837Salfred	char	af_arg[256-16];
15361837Salfred};
154104983Smike#endif
15561837Salfred
1561541Srgrimes/*
1571541Srgrimes * Level number for (get/set)sockopt() to apply to socket itself.
1581541Srgrimes */
1591541Srgrimes#define	SOL_SOCKET	0xffff		/* options for socket level */
1601541Srgrimes
1611541Srgrimes/*
1621541Srgrimes * Address families.
1631541Srgrimes */
1641541Srgrimes#define	AF_UNSPEC	0		/* unspecified */
165104983Smike#if __BSD_VISIBLE
166106847Smike#define	AF_LOCAL	AF_UNIX		/* local to host (pipes, portals) */
167104983Smike#endif
168106847Smike#define	AF_UNIX		1		/* standardized name for AF_LOCAL */
1691541Srgrimes#define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
170104983Smike#if __BSD_VISIBLE
1711541Srgrimes#define	AF_IMPLINK	3		/* arpanet imp addresses */
1721541Srgrimes#define	AF_PUP		4		/* pup protocols: e.g. BSP */
1731541Srgrimes#define	AF_CHAOS	5		/* mit CHAOS protocols */
174111926Speter#define	AF_NETBIOS	6		/* SMB protocols */
1751541Srgrimes#define	AF_ISO		7		/* ISO protocols */
1761541Srgrimes#define	AF_OSI		AF_ISO
17713765Smpp#define	AF_ECMA		8		/* European computer manufacturers */
1781541Srgrimes#define	AF_DATAKIT	9		/* datakit protocols */
1791541Srgrimes#define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
1801541Srgrimes#define	AF_SNA		11		/* IBM SNA */
1811541Srgrimes#define AF_DECnet	12		/* DECnet */
1821541Srgrimes#define AF_DLI		13		/* DEC Direct data link interface */
1831541Srgrimes#define AF_LAT		14		/* LAT */
1841541Srgrimes#define	AF_HYLINK	15		/* NSC Hyperchannel */
1851541Srgrimes#define	AF_APPLETALK	16		/* Apple Talk */
1861541Srgrimes#define	AF_ROUTE	17		/* Internal Routing Protocol */
1871541Srgrimes#define	AF_LINK		18		/* Link layer interface */
1881541Srgrimes#define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
1891541Srgrimes#define	AF_COIP		20		/* connection-oriented IP, aka ST II */
1901541Srgrimes#define	AF_CNT		21		/* Computer Network Technology */
1911541Srgrimes#define pseudo_AF_RTIP	22		/* Help Identify RTIP packets */
1921541Srgrimes#define	AF_IPX		23		/* Novell Internet Protocol */
1931541Srgrimes#define	AF_SIP		24		/* Simple Internet Protocol */
1945413Sse#define	pseudo_AF_PIP	25		/* Help Identify PIP packets */
1955413Sse#define	AF_ISDN		26		/* Integrated Services Digital Network*/
1965413Sse#define	AF_E164		AF_ISDN		/* CCITT E.164 recommendation */
19716368Swollman#define	pseudo_AF_KEY	27		/* Internal key-management function */
198104983Smike#endif
19917938Speter#define	AF_INET6	28		/* IPv6 */
200104983Smike#if __BSD_VISIBLE
20125609Skjc#define	AF_NATM		29		/* native ATM access */
20239271Sphk#define	AF_ATM		30		/* ATM */
20352248Smsmith#define pseudo_AF_HDRCMPLT 31		/* Used by BPF to not rewrite headers
20452248Smsmith					 * in interface output routine
20552248Smsmith					 */
20652424Sjulian#define	AF_NETGRAPH	32		/* Netgraph sockets */
20775847Sgrog#define	AF_SLOW		33		/* 802.3ad slow protocol */
20875847Sgrog#define	AF_SCLUSTER	34		/* Sitara cluster protocol */
209126937Smdodd#define	AF_ARP		35
210129079Semax#define	AF_BLUETOOTH	36		/* Bluetooth sockets */
211160690Ssam#define	AF_IEEE80211	37		/* IEEE 802.11 protocol */
212160690Ssam#define	AF_MAX		38
213104983Smike#endif
2141541Srgrimes
2151541Srgrimes/*
2161541Srgrimes * Structure used by kernel to store most
2171541Srgrimes * addresses.
2181541Srgrimes */
2191541Srgrimesstruct sockaddr {
220104983Smike	unsigned char	sa_len;		/* total length */
22153678Sphk	sa_family_t	sa_family;	/* address family */
22253678Sphk	char		sa_data[14];	/* actually longer; address value */
2231541Srgrimes};
224104983Smike#if __BSD_VISIBLE
22528270Swollman#define	SOCK_MAXADDRLEN	255		/* longest possible addresses */
2261541Srgrimes
2271541Srgrimes/*
2281541Srgrimes * Structure used by kernel to pass protocol
2291541Srgrimes * information in raw sockets.
2301541Srgrimes */
2311541Srgrimesstruct sockproto {
232104983Smike	unsigned short	sp_family;		/* address family */
233104983Smike	unsigned short	sp_protocol;		/* protocol */
2341541Srgrimes};
235104983Smike#endif
2361541Srgrimes
2371541Srgrimes/*
23866240Sasmodai * RFC 2553: protocol-independent placeholder for socket addresses
23952904Sshin */
24090135Smarkm#define	_SS_MAXSIZE	128U
241104983Smike#define	_SS_ALIGNSIZE	(sizeof(__int64_t))
242104983Smike#define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(unsigned char) - \
243104983Smike			    sizeof(sa_family_t))
244104983Smike#define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(unsigned char) - \
245104983Smike			    sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE)
24652904Sshin
24752904Sshinstruct sockaddr_storage {
248104983Smike	unsigned char	ss_len;		/* address length */
24955917Sshin	sa_family_t	ss_family;	/* address family */
25053678Sphk	char		__ss_pad1[_SS_PAD1SIZE];
251104983Smike	__int64_t	__ss_align;	/* force desired struct alignment */
25253678Sphk	char		__ss_pad2[_SS_PAD2SIZE];
25352904Sshin};
25452904Sshin
255104983Smike#if __BSD_VISIBLE
25652904Sshin/*
2571541Srgrimes * Protocol families, same as address families for now.
2581541Srgrimes */
2591541Srgrimes#define	PF_UNSPEC	AF_UNSPEC
2601541Srgrimes#define	PF_LOCAL	AF_LOCAL
2611541Srgrimes#define	PF_UNIX		PF_LOCAL	/* backward compatibility */
2621541Srgrimes#define	PF_INET		AF_INET
2631541Srgrimes#define	PF_IMPLINK	AF_IMPLINK
2641541Srgrimes#define	PF_PUP		AF_PUP
2651541Srgrimes#define	PF_CHAOS	AF_CHAOS
266111926Speter#define	PF_NETBIOS	AF_NETBIOS
2671541Srgrimes#define	PF_ISO		AF_ISO
2681541Srgrimes#define	PF_OSI		AF_ISO
2691541Srgrimes#define	PF_ECMA		AF_ECMA
2701541Srgrimes#define	PF_DATAKIT	AF_DATAKIT
2711541Srgrimes#define	PF_CCITT	AF_CCITT
2721541Srgrimes#define	PF_SNA		AF_SNA
2731541Srgrimes#define PF_DECnet	AF_DECnet
2741541Srgrimes#define PF_DLI		AF_DLI
2751541Srgrimes#define PF_LAT		AF_LAT
2761541Srgrimes#define	PF_HYLINK	AF_HYLINK
2771541Srgrimes#define	PF_APPLETALK	AF_APPLETALK
2781541Srgrimes#define	PF_ROUTE	AF_ROUTE
2791541Srgrimes#define	PF_LINK		AF_LINK
2801541Srgrimes#define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
2811541Srgrimes#define	PF_COIP		AF_COIP
2821541Srgrimes#define	PF_CNT		AF_CNT
2831541Srgrimes#define	PF_SIP		AF_SIP
284111926Speter#define	PF_IPX		AF_IPX
28517603Sjdp#define PF_RTIP		pseudo_AF_RTIP	/* same format as AF_INET */
2861541Srgrimes#define PF_PIP		pseudo_AF_PIP
2875413Sse#define	PF_ISDN		AF_ISDN
28816480Swollman#define	PF_KEY		pseudo_AF_KEY
28917938Speter#define	PF_INET6	AF_INET6
29025609Skjc#define	PF_NATM		AF_NATM
29139271Sphk#define	PF_ATM		AF_ATM
29252419Sjulian#define	PF_NETGRAPH	AF_NETGRAPH
29375847Sgrog#define	PF_SLOW		AF_SLOW
29475847Sgrog#define PF_SCLUSTER	AF_SCLUSTER
295126937Smdodd#define	PF_ARP		AF_ARP
296129079Semax#define	PF_BLUETOOTH	AF_BLUETOOTH
2971541Srgrimes
2981541Srgrimes#define	PF_MAX		AF_MAX
2991541Srgrimes
3001541Srgrimes/*
3011541Srgrimes * Definitions for network related sysctl, CTL_NET.
3021541Srgrimes *
3031541Srgrimes * Second level is protocol family.
3041541Srgrimes * Third level is protocol number.
3051541Srgrimes *
3061541Srgrimes * Further levels are defined by the individual families below.
3071541Srgrimes */
3081541Srgrimes#define NET_MAXID	AF_MAX
3091541Srgrimes
3101541Srgrimes#define CTL_NET_NAMES { \
3111541Srgrimes	{ 0, 0 }, \
3121541Srgrimes	{ "unix", CTLTYPE_NODE }, \
3131541Srgrimes	{ "inet", CTLTYPE_NODE }, \
3141541Srgrimes	{ "implink", CTLTYPE_NODE }, \
3151541Srgrimes	{ "pup", CTLTYPE_NODE }, \
3161541Srgrimes	{ "chaos", CTLTYPE_NODE }, \
3171541Srgrimes	{ "xerox_ns", CTLTYPE_NODE }, \
3181541Srgrimes	{ "iso", CTLTYPE_NODE }, \
3191541Srgrimes	{ "emca", CTLTYPE_NODE }, \
3201541Srgrimes	{ "datakit", CTLTYPE_NODE }, \
3211541Srgrimes	{ "ccitt", CTLTYPE_NODE }, \
3221541Srgrimes	{ "ibm_sna", CTLTYPE_NODE }, \
3231541Srgrimes	{ "decnet", CTLTYPE_NODE }, \
3241541Srgrimes	{ "dec_dli", CTLTYPE_NODE }, \
3251541Srgrimes	{ "lat", CTLTYPE_NODE }, \
3261541Srgrimes	{ "hylink", CTLTYPE_NODE }, \
3271541Srgrimes	{ "appletalk", CTLTYPE_NODE }, \
3281541Srgrimes	{ "route", CTLTYPE_NODE }, \
3291541Srgrimes	{ "link_layer", CTLTYPE_NODE }, \
3301541Srgrimes	{ "xtp", CTLTYPE_NODE }, \
3311541Srgrimes	{ "coip", CTLTYPE_NODE }, \
3321541Srgrimes	{ "cnt", CTLTYPE_NODE }, \
3331541Srgrimes	{ "rtip", CTLTYPE_NODE }, \
3341541Srgrimes	{ "ipx", CTLTYPE_NODE }, \
3351541Srgrimes	{ "sip", CTLTYPE_NODE }, \
3361541Srgrimes	{ "pip", CTLTYPE_NODE }, \
33716368Swollman	{ "isdn", CTLTYPE_NODE }, \
33816368Swollman	{ "key", CTLTYPE_NODE }, \
33933006Salex	{ "inet6", CTLTYPE_NODE }, \
34025609Skjc	{ "natm", CTLTYPE_NODE }, \
34152435Sjulian	{ "atm", CTLTYPE_NODE }, \
34252435Sjulian	{ "hdrcomplete", CTLTYPE_NODE }, \
34352419Sjulian	{ "netgraph", CTLTYPE_NODE }, \
34475847Sgrog	{ "snp", CTLTYPE_NODE }, \
34575847Sgrog	{ "scp", CTLTYPE_NODE }, \
3461541Srgrimes}
3471541Srgrimes
3481541Srgrimes/*
3491541Srgrimes * PF_ROUTE - Routing table
3501541Srgrimes *
3511541Srgrimes * Three additional levels are defined:
3521541Srgrimes *	Fourth: address family, 0 is wildcard
3531541Srgrimes *	Fifth: type of info, defined below
3541541Srgrimes *	Sixth: flag(s) to mask with for NET_RT_FLAGS
3551541Srgrimes */
3561541Srgrimes#define NET_RT_DUMP	1		/* dump; may limit to a.f. */
3571541Srgrimes#define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
3581541Srgrimes#define NET_RT_IFLIST	3		/* survey interface list */
359122685Sbms#define	NET_RT_IFMALIST	4		/* return multicast address list */
360122685Sbms#define	NET_RT_MAXID	5
3611541Srgrimes
3621541Srgrimes#define CTL_NET_RT_NAMES { \
3631541Srgrimes	{ 0, 0 }, \
3641541Srgrimes	{ "dump", CTLTYPE_STRUCT }, \
3651541Srgrimes	{ "flags", CTLTYPE_STRUCT }, \
3661541Srgrimes	{ "iflist", CTLTYPE_STRUCT }, \
367122685Sbms	{ "ifmalist", CTLTYPE_STRUCT }, \
3681541Srgrimes}
369104983Smike#endif /* __BSD_VISIBLE */
3701541Srgrimes
3711541Srgrimes/*
3721541Srgrimes * Maximum queue length specifiable by listen.
3731541Srgrimes */
37413258Sdg#define	SOMAXCONN	128
3751541Srgrimes
3761541Srgrimes/*
3771541Srgrimes * Message header for recvmsg and sendmsg calls.
3781541Srgrimes * Used value-result for recvmsg, value only for sendmsg.
3791541Srgrimes */
3801541Srgrimesstruct msghdr {
38153678Sphk	void		*msg_name;		/* optional address */
38253678Sphk	socklen_t	 msg_namelen;		/* size of address */
38353678Sphk	struct iovec	*msg_iov;		/* scatter/gather array */
38453678Sphk	int		 msg_iovlen;		/* # elements in msg_iov */
38553678Sphk	void		*msg_control;		/* ancillary data, see below */
38653678Sphk	socklen_t	 msg_controllen;	/* ancillary data buffer len */
38753678Sphk	int		 msg_flags;		/* flags on received message */
3881541Srgrimes};
3891541Srgrimes
3901541Srgrimes#define	MSG_OOB		0x1		/* process out-of-band data */
3911541Srgrimes#define	MSG_PEEK	0x2		/* peek at incoming message */
3921541Srgrimes#define	MSG_DONTROUTE	0x4		/* send without using routing tables */
3931541Srgrimes#define	MSG_EOR		0x8		/* data completes record */
3941541Srgrimes#define	MSG_TRUNC	0x10		/* data discarded before delivery */
3951541Srgrimes#define	MSG_CTRUNC	0x20		/* control data lost before delivery */
3961541Srgrimes#define	MSG_WAITALL	0x40		/* wait for full request or error */
397104983Smike#if __BSD_VISIBLE
3981541Srgrimes#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
3996223Swollman#define	MSG_EOF		0x100		/* data completes connection */
400129911Struckman#define	MSG_NBIO	0x4000		/* FIONBIO mode, used by fifofs */
401129929Struckman#define	MSG_COMPAT      0x8000		/* used in sendit() */
402104983Smike#endif
403138206Sps#ifdef _KERNEL
404138206Sps#define	MSG_SOCALLBCK   0x10000		/* for use by socket callbacks - soreceive (TCP) */
405138206Sps#endif
406143308Salfred#if __BSD_VISIBLE
407143308Salfred#define	MSG_NOSIGNAL	0x20000		/* do not generate SIGPIPE on EOF */
408143308Salfred#endif
4091541Srgrimes
4101541Srgrimes/*
4111541Srgrimes * Header for ancillary data objects in msg_control buffer.
4121541Srgrimes * Used for additional information with/about a datagram
4131541Srgrimes * not expressible by flags.  The format is a sequence
4141541Srgrimes * of message elements headed by cmsghdr structures.
4151541Srgrimes */
4161541Srgrimesstruct cmsghdr {
41753678Sphk	socklen_t	cmsg_len;		/* data byte count, including hdr */
41853678Sphk	int		cmsg_level;		/* originating protocol */
41953678Sphk	int		cmsg_type;		/* protocol-specific type */
4201541Srgrimes/* followed by	u_char  cmsg_data[]; */
4211541Srgrimes};
4221541Srgrimes
423104983Smike#if __BSD_VISIBLE
42424083Swpaul/*
42524083Swpaul * While we may have more groups than this, the cmsgcred struct must
42624083Swpaul * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
42724083Swpaul * this.
42824083Swpaul*/
42924083Swpaul#define CMGROUP_MAX 16
43024083Swpaul
43124083Swpaul/*
43224083Swpaul * Credentials structure, used to verify the identity of a peer
43324083Swpaul * process that has sent us a message. This is allocated by the
43424083Swpaul * peer process but filled in by the kernel. This prevents the
43524083Swpaul * peer from lying about its identity. (Note that cmcred_groups[0]
43624083Swpaul * is the effective GID.)
43724083Swpaul */
43824083Swpaulstruct cmsgcred {
43924083Swpaul	pid_t	cmcred_pid;		/* PID of sending process */
44024083Swpaul	uid_t	cmcred_uid;		/* real UID of sending process */
44124083Swpaul	uid_t	cmcred_euid;		/* effective UID of sending process */
44224083Swpaul	gid_t	cmcred_gid;		/* real GID of sending process */
44324083Swpaul	short	cmcred_ngroups;		/* number or groups */
44424083Swpaul	gid_t	cmcred_groups[CMGROUP_MAX];	/* groups */
44524083Swpaul};
446144978Smdodd
447144978Smdodd/*
448144978Smdodd * Socket credentials.
449144978Smdodd */
450144978Smdoddstruct sockcred {
451144978Smdodd	uid_t	sc_uid;			/* real user id */
452144978Smdodd	uid_t	sc_euid;		/* effective user id */
453144978Smdodd	gid_t	sc_gid;			/* real group id */
454144978Smdodd	gid_t	sc_egid;		/* effective group id */
455144978Smdodd	int	sc_ngroups;		/* number of supplemental groups */
456144978Smdodd	gid_t	sc_groups[1];		/* variable length */
457144978Smdodd};
458144978Smdodd
459144978Smdodd/*
460144978Smdodd * Compute size of a sockcred structure with groups.
461144978Smdodd */
462144978Smdodd#define	SOCKCREDSIZE(ngrps) \
463144978Smdodd	(sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
464144978Smdodd
465104983Smike#endif /* __BSD_VISIBLE */
46624083Swpaul
4671541Srgrimes/* given pointer to struct cmsghdr, return pointer to data */
468104983Smike#define	CMSG_DATA(cmsg)		((unsigned char *)(cmsg) + \
46978137Sume				 _ALIGN(sizeof(struct cmsghdr)))
4701541Srgrimes
4711541Srgrimes/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
4721541Srgrimes#define	CMSG_NXTHDR(mhdr, cmsg)	\
473104983Smike	(((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
47478137Sume	  _ALIGN(sizeof(struct cmsghdr)) > \
475104983Smike	    (char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
476132258Sharti	    (struct cmsghdr *)0 : \
477104983Smike	    (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
4781541Srgrimes
479133478Sandre/*
480133478Sandre * RFC 2292 requires to check msg_controllen, in case that the kernel returns
481133478Sandre * an empty list for some reasons.
482133478Sandre */
483133478Sandre#define	CMSG_FIRSTHDR(mhdr) \
484133478Sandre	((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
485133478Sandre	 (struct cmsghdr *)(mhdr)->msg_control : \
486133478Sandre	 (struct cmsghdr *)NULL)
4871541Srgrimes
488104983Smike#if __BSD_VISIBLE
48966255Sasmodai/* RFC 2292 additions */
49078137Sume#define	CMSG_SPACE(l)		(_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
49178137Sume#define	CMSG_LEN(l)		(_ALIGN(sizeof(struct cmsghdr)) + (l))
492104983Smike#endif
49352904Sshin
49478137Sume#ifdef _KERNEL
49578137Sume#define	CMSG_ALIGN(n)	_ALIGN(n)
49678137Sume#endif
49778064Sume
4981541Srgrimes/* "Socket"-level control message types: */
4991541Srgrimes#define	SCM_RIGHTS	0x01		/* access rights (array of int) */
500104983Smike#if __BSD_VISIBLE
50115701Swollman#define	SCM_TIMESTAMP	0x02		/* timestamp (struct timeval) */
50224083Swpaul#define	SCM_CREDS	0x03		/* process creds (struct cmsgcred) */
503125264Sphk#define	SCM_BINTIME	0x04		/* timestamp (struct bintime) */
504104983Smike#endif
5051541Srgrimes
506104983Smike#if __BSD_VISIBLE
5071541Srgrimes/*
5081541Srgrimes * 4.3 compat sockaddr, move to compat file later
5091541Srgrimes */
5101541Srgrimesstruct osockaddr {
511104983Smike	unsigned short sa_family;	/* address family */
5121541Srgrimes	char	sa_data[14];		/* up to 14 bytes of direct address */
5131541Srgrimes};
5141541Srgrimes
5151541Srgrimes/*
5161541Srgrimes * 4.3-compat message header (move to compat file later).
5171541Srgrimes */
5181541Srgrimesstruct omsghdr {
519104983Smike	char	*msg_name;		/* optional address */
5201541Srgrimes	int	msg_namelen;		/* size of address */
5211541Srgrimes	struct	iovec *msg_iov;		/* scatter/gather array */
5221541Srgrimes	int	msg_iovlen;		/* # elements in msg_iov */
523104983Smike	char	*msg_accrights;		/* access rights sent/received */
5241541Srgrimes	int	msg_accrightslen;
5251541Srgrimes};
526104983Smike#endif
5271541Srgrimes
52839114Swollman/*
52939114Swollman * howto arguments for shutdown(2), specified by Posix.1g.
53039114Swollman */
53139114Swollman#define	SHUT_RD		0		/* shut down the reading side */
53239114Swollman#define	SHUT_WR		1		/* shut down the writing side */
53339114Swollman#define	SHUT_RDWR	2		/* shut down both sides */
53439114Swollman
535104983Smike#if __BSD_VISIBLE
53640931Sdg/*
53740931Sdg * sendfile(2) header/trailer struct
53840931Sdg */
53940931Sdgstruct sf_hdtr {
54040931Sdg	struct iovec *headers;	/* pointer to an array of header struct iovec's */
54140931Sdg	int hdr_cnt;		/* number of header iovec's */
54240931Sdg	struct iovec *trailers;	/* pointer to an array of trailer struct iovec's */
54340931Sdg	int trl_cnt;		/* number of trailer iovec's */
54440931Sdg};
545125586Ssilby
546125586Ssilby/*
547125586Ssilby * Sendfile-specific flag(s)
548125586Ssilby */
549163913Sandre#define	SF_NODISKIO     0x00000001
550163913Sandre#define	SF_MNOWAIT	0x00000002
551104983Smike#endif
55240931Sdg
55355205Speter#ifndef	_KERNEL
5541541Srgrimes
5551541Srgrimes#include <sys/cdefs.h>
5561541Srgrimes
5571541Srgrimes__BEGIN_DECLS
558123811Salfredint	accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
55992719Salfredint	bind(int, const struct sockaddr *, socklen_t);
56092719Salfredint	connect(int, const struct sockaddr *, socklen_t);
561123811Salfredint	getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
562123811Salfredint	getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
563123811Salfredint	getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
56492719Salfredint	listen(int, int);
56592719Salfredssize_t	recv(int, void *, size_t, int);
566123811Salfredssize_t	recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict);
56792719Salfredssize_t	recvmsg(int, struct msghdr *, int);
56892719Salfredssize_t	send(int, const void *, size_t, int);
56992719Salfredssize_t	sendto(int, const void *,
57092719Salfred	    size_t, int, const struct sockaddr *, socklen_t);
57192719Salfredssize_t	sendmsg(int, const struct msghdr *, int);
572104983Smike#if __BSD_VISIBLE
57392719Salfredint	sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
574104983Smike#endif
57592719Salfredint	setsockopt(int, int, int, const void *, socklen_t);
57692719Salfredint	shutdown(int, int);
577107872Sfennerint	sockatmark(int);
57892719Salfredint	socket(int, int, int);
57992719Salfredint	socketpair(int, int, int, int *);
5801541Srgrimes__END_DECLS
5811541Srgrimes
58255205Speter#endif /* !_KERNEL */
58331927Sbde
5841541Srgrimes#endif /* !_SYS_SOCKET_H_ */
585