socket.h revision 75458
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 75458 2001-04-13 03:50:37Z alfred $
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 */
991541Srgrimesstruct	linger {
1001541Srgrimes	int	l_onoff;		/* option on/off */
1011541Srgrimes	int	l_linger;		/* linger time */
1021541Srgrimes};
1031541Srgrimes
10461837Salfredstruct	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 */
1551541Srgrimes
15652424Sjulian#define	AF_MAX		33
1571541Srgrimes
1581541Srgrimes/*
1591541Srgrimes * Structure used by kernel to store most
1601541Srgrimes * addresses.
1611541Srgrimes */
1621541Srgrimesstruct sockaddr {
16353678Sphk	u_char		sa_len;		/* total length */
16453678Sphk	sa_family_t	sa_family;	/* address family */
16553678Sphk	char		sa_data[14];	/* actually longer; address value */
1661541Srgrimes};
16728270Swollman#define	SOCK_MAXADDRLEN	255		/* longest possible addresses */
1681541Srgrimes
1691541Srgrimes/*
1701541Srgrimes * Structure used by kernel to pass protocol
1711541Srgrimes * information in raw sockets.
1721541Srgrimes */
1731541Srgrimesstruct sockproto {
1741541Srgrimes	u_short	sp_family;		/* address family */
1751541Srgrimes	u_short	sp_protocol;		/* protocol */
1761541Srgrimes};
1771541Srgrimes
1781541Srgrimes/*
17966240Sasmodai * RFC 2553: protocol-independent placeholder for socket addresses
18052904Sshin */
18152904Sshin#define	_SS_MAXSIZE	128
18252904Sshin#define	_SS_ALIGNSIZE	(sizeof(int64_t))
18357911Sshin#define	_SS_PAD1SIZE	(_SS_ALIGNSIZE - sizeof(u_char) - sizeof(sa_family_t))
18457911Sshin#define	_SS_PAD2SIZE	(_SS_MAXSIZE - sizeof(u_char) - sizeof(sa_family_t) - \
18552904Sshin				_SS_PAD1SIZE - _SS_ALIGNSIZE)
18652904Sshin
18752904Sshinstruct sockaddr_storage {
18855917Sshin	u_char		ss_len;		/* address length */
18955917Sshin	sa_family_t	ss_family;	/* address family */
19053678Sphk	char		__ss_pad1[_SS_PAD1SIZE];
19153678Sphk	int64_t		__ss_align;	/* force desired structure storage alignment */
19253678Sphk	char		__ss_pad2[_SS_PAD2SIZE];
19352904Sshin};
19452904Sshin
19552904Sshin/*
1961541Srgrimes * Protocol families, same as address families for now.
1971541Srgrimes */
1981541Srgrimes#define	PF_UNSPEC	AF_UNSPEC
1991541Srgrimes#define	PF_LOCAL	AF_LOCAL
2001541Srgrimes#define	PF_UNIX		PF_LOCAL	/* backward compatibility */
2011541Srgrimes#define	PF_INET		AF_INET
2021541Srgrimes#define	PF_IMPLINK	AF_IMPLINK
2031541Srgrimes#define	PF_PUP		AF_PUP
2041541Srgrimes#define	PF_CHAOS	AF_CHAOS
2051541Srgrimes#define	PF_NS		AF_NS
2061541Srgrimes#define	PF_ISO		AF_ISO
2071541Srgrimes#define	PF_OSI		AF_ISO
2081541Srgrimes#define	PF_ECMA		AF_ECMA
2091541Srgrimes#define	PF_DATAKIT	AF_DATAKIT
2101541Srgrimes#define	PF_CCITT	AF_CCITT
2111541Srgrimes#define	PF_SNA		AF_SNA
2121541Srgrimes#define PF_DECnet	AF_DECnet
2131541Srgrimes#define PF_DLI		AF_DLI
2141541Srgrimes#define PF_LAT		AF_LAT
2151541Srgrimes#define	PF_HYLINK	AF_HYLINK
2161541Srgrimes#define	PF_APPLETALK	AF_APPLETALK
2171541Srgrimes#define	PF_ROUTE	AF_ROUTE
2181541Srgrimes#define	PF_LINK		AF_LINK
2191541Srgrimes#define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
2201541Srgrimes#define	PF_COIP		AF_COIP
2211541Srgrimes#define	PF_CNT		AF_CNT
2221541Srgrimes#define	PF_SIP		AF_SIP
2231541Srgrimes#define	PF_IPX		AF_IPX		/* same format as AF_NS */
22417603Sjdp#define PF_RTIP		pseudo_AF_RTIP	/* same format as AF_INET */
2251541Srgrimes#define PF_PIP		pseudo_AF_PIP
2265413Sse#define	PF_ISDN		AF_ISDN
22716480Swollman#define	PF_KEY		pseudo_AF_KEY
22817938Speter#define	PF_INET6	AF_INET6
22925609Skjc#define	PF_NATM		AF_NATM
23039271Sphk#define	PF_ATM		AF_ATM
23152419Sjulian#define	PF_NETGRAPH	AF_NETGRAPH
2321541Srgrimes
2331541Srgrimes#define	PF_MAX		AF_MAX
2341541Srgrimes
2351541Srgrimes/*
2361541Srgrimes * Definitions for network related sysctl, CTL_NET.
2371541Srgrimes *
2381541Srgrimes * Second level is protocol family.
2391541Srgrimes * Third level is protocol number.
2401541Srgrimes *
2411541Srgrimes * Further levels are defined by the individual families below.
2421541Srgrimes */
2431541Srgrimes#define NET_MAXID	AF_MAX
2441541Srgrimes
2451541Srgrimes#define CTL_NET_NAMES { \
2461541Srgrimes	{ 0, 0 }, \
2471541Srgrimes	{ "unix", CTLTYPE_NODE }, \
2481541Srgrimes	{ "inet", CTLTYPE_NODE }, \
2491541Srgrimes	{ "implink", CTLTYPE_NODE }, \
2501541Srgrimes	{ "pup", CTLTYPE_NODE }, \
2511541Srgrimes	{ "chaos", CTLTYPE_NODE }, \
2521541Srgrimes	{ "xerox_ns", CTLTYPE_NODE }, \
2531541Srgrimes	{ "iso", CTLTYPE_NODE }, \
2541541Srgrimes	{ "emca", CTLTYPE_NODE }, \
2551541Srgrimes	{ "datakit", CTLTYPE_NODE }, \
2561541Srgrimes	{ "ccitt", CTLTYPE_NODE }, \
2571541Srgrimes	{ "ibm_sna", CTLTYPE_NODE }, \
2581541Srgrimes	{ "decnet", CTLTYPE_NODE }, \
2591541Srgrimes	{ "dec_dli", CTLTYPE_NODE }, \
2601541Srgrimes	{ "lat", CTLTYPE_NODE }, \
2611541Srgrimes	{ "hylink", CTLTYPE_NODE }, \
2621541Srgrimes	{ "appletalk", CTLTYPE_NODE }, \
2631541Srgrimes	{ "route", CTLTYPE_NODE }, \
2641541Srgrimes	{ "link_layer", CTLTYPE_NODE }, \
2651541Srgrimes	{ "xtp", CTLTYPE_NODE }, \
2661541Srgrimes	{ "coip", CTLTYPE_NODE }, \
2671541Srgrimes	{ "cnt", CTLTYPE_NODE }, \
2681541Srgrimes	{ "rtip", CTLTYPE_NODE }, \
2691541Srgrimes	{ "ipx", CTLTYPE_NODE }, \
2701541Srgrimes	{ "sip", CTLTYPE_NODE }, \
2711541Srgrimes	{ "pip", CTLTYPE_NODE }, \
27216368Swollman	{ "isdn", CTLTYPE_NODE }, \
27316368Swollman	{ "key", CTLTYPE_NODE }, \
27433006Salex	{ "inet6", CTLTYPE_NODE }, \
27525609Skjc	{ "natm", CTLTYPE_NODE }, \
27652435Sjulian	{ "atm", CTLTYPE_NODE }, \
27752435Sjulian	{ "hdrcomplete", CTLTYPE_NODE }, \
27852419Sjulian	{ "netgraph", CTLTYPE_NODE }, \
2791541Srgrimes}
2801541Srgrimes
2811541Srgrimes/*
2821541Srgrimes * PF_ROUTE - Routing table
2831541Srgrimes *
2841541Srgrimes * Three additional levels are defined:
2851541Srgrimes *	Fourth: address family, 0 is wildcard
2861541Srgrimes *	Fifth: type of info, defined below
2871541Srgrimes *	Sixth: flag(s) to mask with for NET_RT_FLAGS
2881541Srgrimes */
2891541Srgrimes#define NET_RT_DUMP	1		/* dump; may limit to a.f. */
2901541Srgrimes#define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
2911541Srgrimes#define NET_RT_IFLIST	3		/* survey interface list */
2921541Srgrimes#define	NET_RT_MAXID	4
2931541Srgrimes
2941541Srgrimes#define CTL_NET_RT_NAMES { \
2951541Srgrimes	{ 0, 0 }, \
2961541Srgrimes	{ "dump", CTLTYPE_STRUCT }, \
2971541Srgrimes	{ "flags", CTLTYPE_STRUCT }, \
2981541Srgrimes	{ "iflist", CTLTYPE_STRUCT }, \
2991541Srgrimes}
3001541Srgrimes
3011541Srgrimes/*
3021541Srgrimes * Maximum queue length specifiable by listen.
3031541Srgrimes */
30475458Salfred#ifndef	SOMAXCONN
30513258Sdg#define	SOMAXCONN	128
30675458Salfred#endif
3071541Srgrimes
3081541Srgrimes/*
3091541Srgrimes * Message header for recvmsg and sendmsg calls.
3101541Srgrimes * Used value-result for recvmsg, value only for sendmsg.
3111541Srgrimes */
3121541Srgrimesstruct msghdr {
31353678Sphk	void		*msg_name;		/* optional address */
31453678Sphk	socklen_t	 msg_namelen;		/* size of address */
31553678Sphk	struct iovec	*msg_iov;		/* scatter/gather array */
31653678Sphk	int		 msg_iovlen;		/* # elements in msg_iov */
31753678Sphk	void		*msg_control;		/* ancillary data, see below */
31853678Sphk	socklen_t	 msg_controllen;	/* ancillary data buffer len */
31953678Sphk	int		 msg_flags;		/* flags on received message */
3201541Srgrimes};
3211541Srgrimes
3221541Srgrimes#define	MSG_OOB		0x1		/* process out-of-band data */
3231541Srgrimes#define	MSG_PEEK	0x2		/* peek at incoming message */
3241541Srgrimes#define	MSG_DONTROUTE	0x4		/* send without using routing tables */
3251541Srgrimes#define	MSG_EOR		0x8		/* data completes record */
3261541Srgrimes#define	MSG_TRUNC	0x10		/* data discarded before delivery */
3271541Srgrimes#define	MSG_CTRUNC	0x20		/* control data lost before delivery */
3281541Srgrimes#define	MSG_WAITALL	0x40		/* wait for full request or error */
3291541Srgrimes#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
3306223Swollman#define	MSG_EOF		0x100		/* data completes connection */
3313304Sphk#define MSG_COMPAT      0x8000		/* used in sendit() */
3321541Srgrimes
3331541Srgrimes/*
3341541Srgrimes * Header for ancillary data objects in msg_control buffer.
3351541Srgrimes * Used for additional information with/about a datagram
3361541Srgrimes * not expressible by flags.  The format is a sequence
3371541Srgrimes * of message elements headed by cmsghdr structures.
3381541Srgrimes */
3391541Srgrimesstruct cmsghdr {
34053678Sphk	socklen_t	cmsg_len;		/* data byte count, including hdr */
34153678Sphk	int		cmsg_level;		/* originating protocol */
34253678Sphk	int		cmsg_type;		/* protocol-specific type */
3431541Srgrimes/* followed by	u_char  cmsg_data[]; */
3441541Srgrimes};
3451541Srgrimes
34624083Swpaul/*
34724083Swpaul * While we may have more groups than this, the cmsgcred struct must
34824083Swpaul * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
34924083Swpaul * this.
35024083Swpaul*/
35124083Swpaul#define CMGROUP_MAX 16
35224083Swpaul
35324083Swpaul/*
35424083Swpaul * Credentials structure, used to verify the identity of a peer
35524083Swpaul * process that has sent us a message. This is allocated by the
35624083Swpaul * peer process but filled in by the kernel. This prevents the
35724083Swpaul * peer from lying about its identity. (Note that cmcred_groups[0]
35824083Swpaul * is the effective GID.)
35924083Swpaul */
36024083Swpaulstruct cmsgcred {
36124083Swpaul	pid_t	cmcred_pid;		/* PID of sending process */
36224083Swpaul	uid_t	cmcred_uid;		/* real UID of sending process */
36324083Swpaul	uid_t	cmcred_euid;		/* effective UID of sending process */
36424083Swpaul	gid_t	cmcred_gid;		/* real GID of sending process */
36524083Swpaul	short	cmcred_ngroups;		/* number or groups */
36624083Swpaul	gid_t	cmcred_groups[CMGROUP_MAX];	/* groups */
36724083Swpaul};
36824083Swpaul
3691541Srgrimes/* given pointer to struct cmsghdr, return pointer to data */
37057719Sshin#define	CMSG_DATA(cmsg)		((u_char *)(cmsg) + \
37168498Sasmodai				 _ALIGN(sizeof(struct cmsghdr)))
3721541Srgrimes
3731541Srgrimes/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
3741541Srgrimes#define	CMSG_NXTHDR(mhdr, cmsg)	\
37568498Sasmodai	(((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
37668498Sasmodai	  _ALIGN(sizeof(struct cmsghdr)) > \
37755009Sshin	    (caddr_t)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
3781541Srgrimes	    (struct cmsghdr *)NULL : \
37968498Sasmodai	    (struct cmsghdr *)((caddr_t)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
3801541Srgrimes
3811541Srgrimes#define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
3821541Srgrimes
38366255Sasmodai/* RFC 2292 additions */
38466255Sasmodai
38568498Sasmodai#define	CMSG_SPACE(l)		(_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(l))
38668498Sasmodai#define	CMSG_LEN(l)		(_ALIGN(sizeof(struct cmsghdr)) + (l))
38752904Sshin
3881541Srgrimes/* "Socket"-level control message types: */
3891541Srgrimes#define	SCM_RIGHTS	0x01		/* access rights (array of int) */
39015701Swollman#define	SCM_TIMESTAMP	0x02		/* timestamp (struct timeval) */
39124083Swpaul#define	SCM_CREDS	0x03		/* process creds (struct cmsgcred) */
3921541Srgrimes
3931541Srgrimes/*
3941541Srgrimes * 4.3 compat sockaddr, move to compat file later
3951541Srgrimes */
3961541Srgrimesstruct osockaddr {
3971541Srgrimes	u_short	sa_family;		/* address family */
3981541Srgrimes	char	sa_data[14];		/* up to 14 bytes of direct address */
3991541Srgrimes};
4001541Srgrimes
4011541Srgrimes/*
4021541Srgrimes * 4.3-compat message header (move to compat file later).
4031541Srgrimes */
4041541Srgrimesstruct omsghdr {
4051541Srgrimes	caddr_t	msg_name;		/* optional address */
4061541Srgrimes	int	msg_namelen;		/* size of address */
4071541Srgrimes	struct	iovec *msg_iov;		/* scatter/gather array */
4081541Srgrimes	int	msg_iovlen;		/* # elements in msg_iov */
4091541Srgrimes	caddr_t	msg_accrights;		/* access rights sent/received */
4101541Srgrimes	int	msg_accrightslen;
4111541Srgrimes};
4121541Srgrimes
41339114Swollman/*
41439114Swollman * howto arguments for shutdown(2), specified by Posix.1g.
41539114Swollman */
41639114Swollman#define	SHUT_RD		0		/* shut down the reading side */
41739114Swollman#define	SHUT_WR		1		/* shut down the writing side */
41839114Swollman#define	SHUT_RDWR	2		/* shut down both sides */
41939114Swollman
42040931Sdg/*
42140931Sdg * sendfile(2) header/trailer struct
42240931Sdg */
42340931Sdgstruct sf_hdtr {
42440931Sdg	struct iovec *headers;	/* pointer to an array of header struct iovec's */
42540931Sdg	int hdr_cnt;		/* number of header iovec's */
42640931Sdg	struct iovec *trailers;	/* pointer to an array of trailer struct iovec's */
42740931Sdg	int trl_cnt;		/* number of trailer iovec's */
42840931Sdg};
42940931Sdg
43055205Speter#ifndef	_KERNEL
4311541Srgrimes
4321541Srgrimes#include <sys/cdefs.h>
4331541Srgrimes
4341541Srgrimes__BEGIN_DECLS
43553678Sphkint	accept __P((int, struct sockaddr *, socklen_t *));
43653678Sphkint	bind __P((int, const struct sockaddr *, socklen_t));
43753678Sphkint	connect __P((int, const struct sockaddr *, socklen_t));
43853678Sphkint	getpeername __P((int, struct sockaddr *, socklen_t *));
43953678Sphkint	getsockname __P((int, struct sockaddr *, socklen_t *));
44053678Sphkint	getsockopt __P((int, int, int, void *, socklen_t *));
4411541Srgrimesint	listen __P((int, int));
4421541Srgrimesssize_t	recv __P((int, void *, size_t, int));
44353678Sphkssize_t	recvfrom __P((int, void *, size_t, int, struct sockaddr *, socklen_t *));
4441541Srgrimesssize_t	recvmsg __P((int, struct msghdr *, int));
4451541Srgrimesssize_t	send __P((int, const void *, size_t, int));
4461541Srgrimesssize_t	sendto __P((int, const void *,
44753678Sphk	    size_t, int, const struct sockaddr *, socklen_t));
4481541Srgrimesssize_t	sendmsg __P((int, const struct msghdr *, int));
44940931Sdgint	sendfile __P((int, int, off_t, size_t, struct sf_hdtr *, off_t *, int));
45053678Sphkint	setsockopt __P((int, int, int, const void *, socklen_t));
4511541Srgrimesint	shutdown __P((int, int));
4521541Srgrimesint	socket __P((int, int, int));
4531541Srgrimesint	socketpair __P((int, int, int, int *));
4541541Srgrimes__END_DECLS
4551541Srgrimes
45655205Speter#endif /* !_KERNEL */
45731927Sbde
4581541Srgrimes#endif /* !_SYS_SOCKET_H_ */
459