socket.h revision 83045
11541Srgrimes/*
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 * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)socket.h	8.4 (Berkeley) 2/21/94
3450477Speter * $FreeBSD: head/sys/sys/socket.h 83045 2001-09-05 01:22:14Z obrien $
351541Srgrimes */
361541Srgrimes
371541Srgrimes#ifndef _SYS_SOCKET_H_
381541Srgrimes#define	_SYS_SOCKET_H_
391541Srgrimes
4072554Sbde#include <machine/ansi.h>
4168498Sasmodai#define _NO_NAMESPACE_POLLUTION
4268498Sasmodai#include <machine/param.h>
4368498Sasmodai#undef _NO_NAMESPACE_POLLUTION
4468498Sasmodai
451541Srgrimes/*
461541Srgrimes * Definitions related to sockets: types, address families, options.
471541Srgrimes */
481541Srgrimes
491541Srgrimes/*
5053678Sphk * Data types.
5153678Sphk */
5253678Sphktypedef u_char		sa_family_t;
5372510Sume#ifdef	_BSD_SOCKLEN_T_
5472510Sumetypedef	_BSD_SOCKLEN_T_	socklen_t;
5572510Sume#undef	_BSD_SOCKLEN_T_
5672510Sume#endif
5753678Sphk
5853678Sphk/*
591541Srgrimes * Types
601541Srgrimes */
611541Srgrimes#define	SOCK_STREAM	1		/* stream socket */
621541Srgrimes#define	SOCK_DGRAM	2		/* datagram socket */
631541Srgrimes#define	SOCK_RAW	3		/* raw-protocol interface */
641541Srgrimes#define	SOCK_RDM	4		/* reliably-delivered message */
651541Srgrimes#define	SOCK_SEQPACKET	5		/* sequenced packet stream */
661541Srgrimes
671541Srgrimes/*
681541Srgrimes * Option flags per-socket.
691541Srgrimes */
701541Srgrimes#define	SO_DEBUG	0x0001		/* turn on debugging info recording */
711541Srgrimes#define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
721541Srgrimes#define	SO_REUSEADDR	0x0004		/* allow local address reuse */
731541Srgrimes#define	SO_KEEPALIVE	0x0008		/* keep connections alive */
741541Srgrimes#define	SO_DONTROUTE	0x0010		/* just use interface addresses */
751541Srgrimes#define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
761541Srgrimes#define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
771541Srgrimes#define	SO_LINGER	0x0080		/* linger on close if data present */
781541Srgrimes#define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
791541Srgrimes#define	SO_REUSEPORT	0x0200		/* allow local address & port reuse */
8015701Swollman#define	SO_TIMESTAMP	0x0400		/* timestamp received dgram traffic */
8161837Salfred#define	SO_ACCEPTFILTER	0x1000		/* there is an accept filter */
821541Srgrimes
831541Srgrimes/*
841541Srgrimes * Additional options, not kept in so_options.
851541Srgrimes */
861541Srgrimes#define SO_SNDBUF	0x1001		/* send buffer size */
871541Srgrimes#define SO_RCVBUF	0x1002		/* receive buffer size */
881541Srgrimes#define SO_SNDLOWAT	0x1003		/* send low-water mark */
891541Srgrimes#define SO_RCVLOWAT	0x1004		/* receive low-water mark */
901541Srgrimes#define SO_SNDTIMEO	0x1005		/* send timeout */
911541Srgrimes#define SO_RCVTIMEO	0x1006		/* receive timeout */
921541Srgrimes#define	SO_ERROR	0x1007		/* get error status and clear */
931541Srgrimes#define	SO_TYPE		0x1008		/* get socket type */
9425311Swollman/*efine	SO_PRIVSTATE	0x1009		   get/deny privileged state */
951541Srgrimes
961541Srgrimes/*
971541Srgrimes * Structure used for manipulating linger option.
981541Srgrimes */
9983045Sobrienstruct linger {
1001541Srgrimes	int	l_onoff;		/* option on/off */
1011541Srgrimes	int	l_linger;		/* linger time */
1021541Srgrimes};
1031541Srgrimes
10483045Sobrienstruct accept_filter_arg {
10561837Salfred	char	af_name[16];
10661837Salfred	char	af_arg[256-16];
10761837Salfred};
10861837Salfred
1091541Srgrimes/*
1101541Srgrimes * Level number for (get/set)sockopt() to apply to socket itself.
1111541Srgrimes */
1121541Srgrimes#define	SOL_SOCKET	0xffff		/* options for socket level */
1131541Srgrimes
1141541Srgrimes/*
1151541Srgrimes * Address families.
1161541Srgrimes */
1171541Srgrimes#define	AF_UNSPEC	0		/* unspecified */
1181541Srgrimes#define	AF_LOCAL	1		/* local to host (pipes, portals) */
1191541Srgrimes#define	AF_UNIX		AF_LOCAL	/* backward compatibility */
1201541Srgrimes#define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
1211541Srgrimes#define	AF_IMPLINK	3		/* arpanet imp addresses */
1221541Srgrimes#define	AF_PUP		4		/* pup protocols: e.g. BSP */
1231541Srgrimes#define	AF_CHAOS	5		/* mit CHAOS protocols */
1241541Srgrimes#define	AF_NS		6		/* XEROX NS protocols */
1251541Srgrimes#define	AF_ISO		7		/* ISO protocols */
1261541Srgrimes#define	AF_OSI		AF_ISO
12713765Smpp#define	AF_ECMA		8		/* European computer manufacturers */
1281541Srgrimes#define	AF_DATAKIT	9		/* datakit protocols */
1291541Srgrimes#define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
1301541Srgrimes#define	AF_SNA		11		/* IBM SNA */
1311541Srgrimes#define AF_DECnet	12		/* DECnet */
1321541Srgrimes#define AF_DLI		13		/* DEC Direct data link interface */
1331541Srgrimes#define AF_LAT		14		/* LAT */
1341541Srgrimes#define	AF_HYLINK	15		/* NSC Hyperchannel */
1351541Srgrimes#define	AF_APPLETALK	16		/* Apple Talk */
1361541Srgrimes#define	AF_ROUTE	17		/* Internal Routing Protocol */
1371541Srgrimes#define	AF_LINK		18		/* Link layer interface */
1381541Srgrimes#define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
1391541Srgrimes#define	AF_COIP		20		/* connection-oriented IP, aka ST II */
1401541Srgrimes#define	AF_CNT		21		/* Computer Network Technology */
1411541Srgrimes#define pseudo_AF_RTIP	22		/* Help Identify RTIP packets */
1421541Srgrimes#define	AF_IPX		23		/* Novell Internet Protocol */
1431541Srgrimes#define	AF_SIP		24		/* Simple Internet Protocol */
1445413Sse#define	pseudo_AF_PIP	25		/* Help Identify PIP packets */
1455413Sse#define	AF_ISDN		26		/* Integrated Services Digital Network*/
1465413Sse#define	AF_E164		AF_ISDN		/* CCITT E.164 recommendation */
14716368Swollman#define	pseudo_AF_KEY	27		/* Internal key-management function */
14817938Speter#define	AF_INET6	28		/* IPv6 */
14925609Skjc#define	AF_NATM		29		/* native ATM access */
15039271Sphk#define	AF_ATM		30		/* ATM */
15152248Smsmith#define pseudo_AF_HDRCMPLT 31		/* Used by BPF to not rewrite headers
15252248Smsmith					 * in interface output routine
15352248Smsmith					 */
15452424Sjulian#define	AF_NETGRAPH	32		/* Netgraph sockets */
15575847Sgrog#define	AF_SLOW		33		/* 802.3ad slow protocol */
15675847Sgrog#define	AF_SCLUSTER	34		/* Sitara cluster protocol */
15775847Sgrog#define	AF_MAX		35
1581541Srgrimes
1591541Srgrimes/*
1601541Srgrimes * Structure used by kernel to store most
1611541Srgrimes * addresses.
1621541Srgrimes */
1631541Srgrimesstruct sockaddr {
16453678Sphk	u_char		sa_len;		/* total length */
16553678Sphk	sa_family_t	sa_family;	/* address family */
16653678Sphk	char		sa_data[14];	/* actually longer; address value */
1671541Srgrimes};
16828270Swollman#define	SOCK_MAXADDRLEN	255		/* longest possible addresses */
1691541Srgrimes
1701541Srgrimes/*
1711541Srgrimes * Structure used by kernel to pass protocol
1721541Srgrimes * information in raw sockets.
1731541Srgrimes */
1741541Srgrimesstruct sockproto {
1751541Srgrimes	u_short	sp_family;		/* address family */
1761541Srgrimes	u_short	sp_protocol;		/* protocol */
1771541Srgrimes};
1781541Srgrimes
1791541Srgrimes/*
18066240Sasmodai * RFC 2553: protocol-independent placeholder for socket addresses
18152904Sshin */
18252904Sshin#define	_SS_MAXSIZE	128
18352904Sshin#define	_SS_ALIGNSIZE	(sizeof(int64_t))
18457911Sshin#define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(u_char) - sizeof(sa_family_t))
18557911Sshin#define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(u_char) - sizeof(sa_family_t) - \
18652904Sshin				_SS_PAD1SIZE - _SS_ALIGNSIZE)
18752904Sshin
18852904Sshinstruct sockaddr_storage {
18955917Sshin	u_char		ss_len;		/* address length */
19055917Sshin	sa_family_t	ss_family;	/* address family */
19153678Sphk	char		__ss_pad1[_SS_PAD1SIZE];
19253678Sphk	int64_t		__ss_align;	/* force desired structure storage alignment */
19353678Sphk	char		__ss_pad2[_SS_PAD2SIZE];
19452904Sshin};
19552904Sshin
19652904Sshin/*
1971541Srgrimes * Protocol families, same as address families for now.
1981541Srgrimes */
1991541Srgrimes#define	PF_UNSPEC	AF_UNSPEC
2001541Srgrimes#define	PF_LOCAL	AF_LOCAL
2011541Srgrimes#define	PF_UNIX		PF_LOCAL	/* backward compatibility */
2021541Srgrimes#define	PF_INET		AF_INET
2031541Srgrimes#define	PF_IMPLINK	AF_IMPLINK
2041541Srgrimes#define	PF_PUP		AF_PUP
2051541Srgrimes#define	PF_CHAOS	AF_CHAOS
2061541Srgrimes#define	PF_NS		AF_NS
2071541Srgrimes#define	PF_ISO		AF_ISO
2081541Srgrimes#define	PF_OSI		AF_ISO
2091541Srgrimes#define	PF_ECMA		AF_ECMA
2101541Srgrimes#define	PF_DATAKIT	AF_DATAKIT
2111541Srgrimes#define	PF_CCITT	AF_CCITT
2121541Srgrimes#define	PF_SNA		AF_SNA
2131541Srgrimes#define PF_DECnet	AF_DECnet
2141541Srgrimes#define PF_DLI		AF_DLI
2151541Srgrimes#define PF_LAT		AF_LAT
2161541Srgrimes#define	PF_HYLINK	AF_HYLINK
2171541Srgrimes#define	PF_APPLETALK	AF_APPLETALK
2181541Srgrimes#define	PF_ROUTE	AF_ROUTE
2191541Srgrimes#define	PF_LINK		AF_LINK
2201541Srgrimes#define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
2211541Srgrimes#define	PF_COIP		AF_COIP
2221541Srgrimes#define	PF_CNT		AF_CNT
2231541Srgrimes#define	PF_SIP		AF_SIP
2241541Srgrimes#define	PF_IPX		AF_IPX		/* same format as AF_NS */
22517603Sjdp#define PF_RTIP		pseudo_AF_RTIP	/* same format as AF_INET */
2261541Srgrimes#define PF_PIP		pseudo_AF_PIP
2275413Sse#define	PF_ISDN		AF_ISDN
22816480Swollman#define	PF_KEY		pseudo_AF_KEY
22917938Speter#define	PF_INET6	AF_INET6
23025609Skjc#define	PF_NATM		AF_NATM
23139271Sphk#define	PF_ATM		AF_ATM
23252419Sjulian#define	PF_NETGRAPH	AF_NETGRAPH
23375847Sgrog#define	PF_SLOW		AF_SLOW
23475847Sgrog#define PF_SCLUSTER	AF_SCLUSTER
2351541Srgrimes
2361541Srgrimes#define	PF_MAX		AF_MAX
2371541Srgrimes
2381541Srgrimes/*
2391541Srgrimes * Definitions for network related sysctl, CTL_NET.
2401541Srgrimes *
2411541Srgrimes * Second level is protocol family.
2421541Srgrimes * Third level is protocol number.
2431541Srgrimes *
2441541Srgrimes * Further levels are defined by the individual families below.
2451541Srgrimes */
2461541Srgrimes#define NET_MAXID	AF_MAX
2471541Srgrimes
2481541Srgrimes#define CTL_NET_NAMES { \
2491541Srgrimes	{ 0, 0 }, \
2501541Srgrimes	{ "unix", CTLTYPE_NODE }, \
2511541Srgrimes	{ "inet", CTLTYPE_NODE }, \
2521541Srgrimes	{ "implink", CTLTYPE_NODE }, \
2531541Srgrimes	{ "pup", CTLTYPE_NODE }, \
2541541Srgrimes	{ "chaos", CTLTYPE_NODE }, \
2551541Srgrimes	{ "xerox_ns", CTLTYPE_NODE }, \
2561541Srgrimes	{ "iso", CTLTYPE_NODE }, \
2571541Srgrimes	{ "emca", CTLTYPE_NODE }, \
2581541Srgrimes	{ "datakit", CTLTYPE_NODE }, \
2591541Srgrimes	{ "ccitt", CTLTYPE_NODE }, \
2601541Srgrimes	{ "ibm_sna", CTLTYPE_NODE }, \
2611541Srgrimes	{ "decnet", CTLTYPE_NODE }, \
2621541Srgrimes	{ "dec_dli", CTLTYPE_NODE }, \
2631541Srgrimes	{ "lat", CTLTYPE_NODE }, \
2641541Srgrimes	{ "hylink", CTLTYPE_NODE }, \
2651541Srgrimes	{ "appletalk", CTLTYPE_NODE }, \
2661541Srgrimes	{ "route", CTLTYPE_NODE }, \
2671541Srgrimes	{ "link_layer", CTLTYPE_NODE }, \
2681541Srgrimes	{ "xtp", CTLTYPE_NODE }, \
2691541Srgrimes	{ "coip", CTLTYPE_NODE }, \
2701541Srgrimes	{ "cnt", CTLTYPE_NODE }, \
2711541Srgrimes	{ "rtip", CTLTYPE_NODE }, \
2721541Srgrimes	{ "ipx", CTLTYPE_NODE }, \
2731541Srgrimes	{ "sip", CTLTYPE_NODE }, \
2741541Srgrimes	{ "pip", CTLTYPE_NODE }, \
27516368Swollman	{ "isdn", CTLTYPE_NODE }, \
27616368Swollman	{ "key", CTLTYPE_NODE }, \
27733006Salex	{ "inet6", CTLTYPE_NODE }, \
27825609Skjc	{ "natm", CTLTYPE_NODE }, \
27952435Sjulian	{ "atm", CTLTYPE_NODE }, \
28052435Sjulian	{ "hdrcomplete", CTLTYPE_NODE }, \
28152419Sjulian	{ "netgraph", CTLTYPE_NODE }, \
28275847Sgrog	{ "snp", CTLTYPE_NODE }, \
28375847Sgrog	{ "scp", CTLTYPE_NODE }, \
2841541Srgrimes}
2851541Srgrimes
2861541Srgrimes/*
2871541Srgrimes * PF_ROUTE - Routing table
2881541Srgrimes *
2891541Srgrimes * Three additional levels are defined:
2901541Srgrimes *	Fourth: address family, 0 is wildcard
2911541Srgrimes *	Fifth: type of info, defined below
2921541Srgrimes *	Sixth: flag(s) to mask with for NET_RT_FLAGS
2931541Srgrimes */
2941541Srgrimes#define NET_RT_DUMP	1		/* dump; may limit to a.f. */
2951541Srgrimes#define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
2961541Srgrimes#define NET_RT_IFLIST	3		/* survey interface list */
2971541Srgrimes#define	NET_RT_MAXID	4
2981541Srgrimes
2991541Srgrimes#define CTL_NET_RT_NAMES { \
3001541Srgrimes	{ 0, 0 }, \
3011541Srgrimes	{ "dump", CTLTYPE_STRUCT }, \
3021541Srgrimes	{ "flags", CTLTYPE_STRUCT }, \
3031541Srgrimes	{ "iflist", CTLTYPE_STRUCT }, \
3041541Srgrimes}
3051541Srgrimes
3061541Srgrimes/*
3071541Srgrimes * Maximum queue length specifiable by listen.
3081541Srgrimes */
30975458Salfred#ifndef	SOMAXCONN
31013258Sdg#define	SOMAXCONN	128
31175458Salfred#endif
3121541Srgrimes
3131541Srgrimes/*
3141541Srgrimes * Message header for recvmsg and sendmsg calls.
3151541Srgrimes * Used value-result for recvmsg, value only for sendmsg.
3161541Srgrimes */
3171541Srgrimesstruct msghdr {
31853678Sphk	void		*msg_name;		/* optional address */
31953678Sphk	socklen_t	 msg_namelen;		/* size of address */
32053678Sphk	struct iovec	*msg_iov;		/* scatter/gather array */
32153678Sphk	int		 msg_iovlen;		/* # elements in msg_iov */
32253678Sphk	void		*msg_control;		/* ancillary data, see below */
32353678Sphk	socklen_t	 msg_controllen;	/* ancillary data buffer len */
32453678Sphk	int		 msg_flags;		/* flags on received message */
3251541Srgrimes};
3261541Srgrimes
3271541Srgrimes#define	MSG_OOB		0x1		/* process out-of-band data */
3281541Srgrimes#define	MSG_PEEK	0x2		/* peek at incoming message */
3291541Srgrimes#define	MSG_DONTROUTE	0x4		/* send without using routing tables */
3301541Srgrimes#define	MSG_EOR		0x8		/* data completes record */
3311541Srgrimes#define	MSG_TRUNC	0x10		/* data discarded before delivery */
3321541Srgrimes#define	MSG_CTRUNC	0x20		/* control data lost before delivery */
3331541Srgrimes#define	MSG_WAITALL	0x40		/* wait for full request or error */
3341541Srgrimes#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
3356223Swollman#define	MSG_EOF		0x100		/* data completes connection */
3363304Sphk#define MSG_COMPAT      0x8000		/* used in sendit() */
3371541Srgrimes
3381541Srgrimes/*
3391541Srgrimes * Header for ancillary data objects in msg_control buffer.
3401541Srgrimes * Used for additional information with/about a datagram
3411541Srgrimes * not expressible by flags.  The format is a sequence
3421541Srgrimes * of message elements headed by cmsghdr structures.
3431541Srgrimes */
3441541Srgrimesstruct cmsghdr {
34553678Sphk	socklen_t	cmsg_len;		/* data byte count, including hdr */
34653678Sphk	int		cmsg_level;		/* originating protocol */
34753678Sphk	int		cmsg_type;		/* protocol-specific type */
3481541Srgrimes/* followed by	u_char  cmsg_data[]; */
3491541Srgrimes};
3501541Srgrimes
35124083Swpaul/*
35224083Swpaul * While we may have more groups than this, the cmsgcred struct must
35324083Swpaul * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
35424083Swpaul * this.
35524083Swpaul*/
35624083Swpaul#define CMGROUP_MAX 16
35724083Swpaul
35824083Swpaul/*
35924083Swpaul * Credentials structure, used to verify the identity of a peer
36024083Swpaul * process that has sent us a message. This is allocated by the
36124083Swpaul * peer process but filled in by the kernel. This prevents the
36224083Swpaul * peer from lying about its identity. (Note that cmcred_groups[0]
36324083Swpaul * is the effective GID.)
36424083Swpaul */
36524083Swpaulstruct cmsgcred {
36624083Swpaul	pid_t	cmcred_pid;		/* PID of sending process */
36724083Swpaul	uid_t	cmcred_uid;		/* real UID of sending process */
36824083Swpaul	uid_t	cmcred_euid;		/* effective UID of sending process */
36924083Swpaul	gid_t	cmcred_gid;		/* real GID of sending process */
37024083Swpaul	short	cmcred_ngroups;		/* number or groups */
37124083Swpaul	gid_t	cmcred_groups[CMGROUP_MAX];	/* groups */
37224083Swpaul};
37324083Swpaul
3741541Srgrimes/* given pointer to struct cmsghdr, return pointer to data */
37557719Sshin#define	CMSG_DATA(cmsg)		((u_char *)(cmsg) + \
37678137Sume				 _ALIGN(sizeof(struct cmsghdr)))
3771541Srgrimes
3781541Srgrimes/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
3791541Srgrimes#define	CMSG_NXTHDR(mhdr, cmsg)	\
38078137Sume	(((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
38178137Sume	  _ALIGN(sizeof(struct cmsghdr)) > \
38255009Sshin	    (caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
3831541Srgrimes	    (struct cmsghdr *)NULL : \
38478137Sume	    (struct cmsghdr *)((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
3851541Srgrimes
3861541Srgrimes#define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
3871541Srgrimes
38866255Sasmodai/* RFC 2292 additions */
38978137Sume
39078137Sume#define	CMSG_SPACE(l)		(_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
39178137Sume#define	CMSG_LEN(l)		(_ALIGN(sizeof(struct cmsghdr)) + (l))
39252904Sshin
39378137Sume#ifdef _KERNEL
39478137Sume#define	CMSG_ALIGN(n)	_ALIGN(n)
39578137Sume#endif
39678064Sume
3971541Srgrimes/* "Socket"-level control message types: */
3981541Srgrimes#define	SCM_RIGHTS	0x01		/* access rights (array of int) */
39915701Swollman#define	SCM_TIMESTAMP	0x02		/* timestamp (struct timeval) */
40024083Swpaul#define	SCM_CREDS	0x03		/* process creds (struct cmsgcred) */
4011541Srgrimes
4021541Srgrimes/*
4031541Srgrimes * 4.3 compat sockaddr, move to compat file later
4041541Srgrimes */
4051541Srgrimesstruct osockaddr {
4061541Srgrimes	u_short	sa_family;		/* address family */
4071541Srgrimes	char	sa_data[14];		/* up to 14 bytes of direct address */
4081541Srgrimes};
4091541Srgrimes
4101541Srgrimes/*
4111541Srgrimes * 4.3-compat message header (move to compat file later).
4121541Srgrimes */
4131541Srgrimesstruct omsghdr {
4141541Srgrimes	caddr_t	msg_name;		/* optional address */
4151541Srgrimes	int	msg_namelen;		/* size of address */
4161541Srgrimes	struct	iovec *msg_iov;		/* scatter/gather array */
4171541Srgrimes	int	msg_iovlen;		/* # elements in msg_iov */
4181541Srgrimes	caddr_t	msg_accrights;		/* access rights sent/received */
4191541Srgrimes	int	msg_accrightslen;
4201541Srgrimes};
4211541Srgrimes
42239114Swollman/*
42339114Swollman * howto arguments for shutdown(2), specified by Posix.1g.
42439114Swollman */
42539114Swollman#define	SHUT_RD		0		/* shut down the reading side */
42639114Swollman#define	SHUT_WR		1		/* shut down the writing side */
42739114Swollman#define	SHUT_RDWR	2		/* shut down both sides */
42839114Swollman
42940931Sdg/*
43040931Sdg * sendfile(2) header/trailer struct
43140931Sdg */
43240931Sdgstruct sf_hdtr {
43340931Sdg	struct iovec *headers;	/* pointer to an array of header struct iovec's */
43440931Sdg	int hdr_cnt;		/* number of header iovec's */
43540931Sdg	struct iovec *trailers;	/* pointer to an array of trailer struct iovec's */
43640931Sdg	int trl_cnt;		/* number of trailer iovec's */
43740931Sdg};
43840931Sdg
43955205Speter#ifndef	_KERNEL
4401541Srgrimes
4411541Srgrimes#include <sys/cdefs.h>
4421541Srgrimes
4431541Srgrimes__BEGIN_DECLS
44453678Sphkint	accept __P((int, struct sockaddr *, socklen_t *));
44553678Sphkint	bind __P((int, const struct sockaddr *, socklen_t));
44653678Sphkint	connect __P((int, const struct sockaddr *, socklen_t));
44753678Sphkint	getpeername __P((int, struct sockaddr *, socklen_t *));
44853678Sphkint	getsockname __P((int, struct sockaddr *, socklen_t *));
44953678Sphkint	getsockopt __P((int, int, int, void *, socklen_t *));
4501541Srgrimesint	listen __P((int, int));
4511541Srgrimesssize_t	recv __P((int, void *, size_t, int));
45253678Sphkssize_t	recvfrom __P((int, void *, size_t, int, struct sockaddr *, socklen_t *));
4531541Srgrimesssize_t	recvmsg __P((int, struct msghdr *, int));
4541541Srgrimesssize_t	send __P((int, const void *, size_t, int));
4551541Srgrimesssize_t	sendto __P((int, const void *,
45653678Sphk	    size_t, int, const struct sockaddr *, socklen_t));
4571541Srgrimesssize_t	sendmsg __P((int, const struct msghdr *, int));
45840931Sdgint	sendfile __P((int, int, off_t, size_t, struct sf_hdtr *, off_t *, int));
45953678Sphkint	setsockopt __P((int, int, int, const void *, socklen_t));
4601541Srgrimesint	shutdown __P((int, int));
4611541Srgrimesint	socket __P((int, int, int));
4621541Srgrimesint	socketpair __P((int, int, int, int *));
4631541Srgrimes__END_DECLS
4641541Srgrimes
46555205Speter#endif /* !_KERNEL */
46631927Sbde
4671541Srgrimes#endif /* !_SYS_SOCKET_H_ */
468