xref: /csrg-svn/sys/sys/socket.h (revision 40764)
123438Smckusick /*
235796Ssklower  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
333186Sbostic  * All rights reserved.
423438Smckusick  *
533186Sbostic  * Redistribution and use in source and binary forms are permitted
634841Sbostic  * provided that the above copyright notice and this paragraph are
734841Sbostic  * duplicated in all such forms and that any documentation,
834841Sbostic  * advertising materials, and other materials related to such
934841Sbostic  * distribution and use acknowledge that the software was developed
1034841Sbostic  * by the University of California, Berkeley.  The name of the
1134841Sbostic  * University may not be used to endorse or promote products derived
1234841Sbostic  * from this software without specific prior written permission.
1334841Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434841Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534841Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633186Sbostic  *
17*40764Skarels  *	@(#)socket.h	7.7 (Berkeley) 04/04/90
1823438Smckusick  */
194658Swnj 
204658Swnj /*
2112787Ssam  * Definitions related to sockets: types, address families, options.
224658Swnj  */
234892Swnj 
244892Swnj /*
2512787Ssam  * Types
264892Swnj  */
274930Swnj #define	SOCK_STREAM	1		/* stream socket */
284930Swnj #define	SOCK_DGRAM	2		/* datagram socket */
294930Swnj #define	SOCK_RAW	3		/* raw-protocol interface */
304930Swnj #define	SOCK_RDM	4		/* reliably-delivered message */
3112787Ssam #define	SOCK_SEQPACKET	5		/* sequenced packet stream */
324658Swnj 
334812Swnj /*
344812Swnj  * Option flags per-socket.
354812Swnj  */
3627192Skarels #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
3727192Skarels #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
3827192Skarels #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
3927192Skarels #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
4027192Skarels #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
4127192Skarels #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
4227192Skarels #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
4327192Skarels #define	SO_LINGER	0x0080		/* linger on close if data present */
4427192Skarels #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
454930Swnj 
464930Swnj /*
4717552Skarels  * Additional options, not kept in so_options.
4817552Skarels  */
4917552Skarels #define SO_SNDBUF	0x1001		/* send buffer size */
5017552Skarels #define SO_RCVBUF	0x1002		/* receive buffer size */
5117552Skarels #define SO_SNDLOWAT	0x1003		/* send low-water mark */
5217552Skarels #define SO_RCVLOWAT	0x1004		/* receive low-water mark */
5317552Skarels #define SO_SNDTIMEO	0x1005		/* send timeout */
5417552Skarels #define SO_RCVTIMEO	0x1006		/* receive timeout */
5524825Skarels #define	SO_ERROR	0x1007		/* get error status and clear */
5625503Skarels #define	SO_TYPE		0x1008		/* get socket type */
5717552Skarels 
5817552Skarels /*
5917160Ssam  * Structure used for manipulating linger option.
6017052Skarels  */
6117160Ssam struct	linger {
6217160Ssam 	int	l_onoff;		/* option on/off */
6317160Ssam 	int	l_linger;		/* linger time */
6417160Ssam };
6517052Skarels 
6617052Skarels /*
6717160Ssam  * Level number for (get/set)sockopt() to apply to socket itself.
6817160Ssam  */
6917160Ssam #define	SOL_SOCKET	0xffff		/* options for socket level */
7017160Ssam 
7117160Ssam /*
7212787Ssam  * Address families.
734930Swnj  */
7412787Ssam #define	AF_UNSPEC	0		/* unspecified */
7512787Ssam #define	AF_UNIX		1		/* local to host (pipes, portals) */
7612787Ssam #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
7712787Ssam #define	AF_IMPLINK	3		/* arpanet imp addresses */
7812787Ssam #define	AF_PUP		4		/* pup protocols: e.g. BSP */
7912787Ssam #define	AF_CHAOS	5		/* mit CHAOS protocols */
8012787Ssam #define	AF_NS		6		/* XEROX NS protocols */
8136353Ssklower #define	AF_ISO		7		/* ISO protocols */
82*40764Skarels #define	AF_OSI		AF_ISO
8312787Ssam #define	AF_ECMA		8		/* european computer manufacturers */
8412787Ssam #define	AF_DATAKIT	9		/* datakit protocols */
8512787Ssam #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
8612787Ssam #define	AF_SNA		11		/* IBM SNA */
8723751Skarels #define AF_DECnet	12		/* DECnet */
88*40764Skarels #define AF_DLI		13		/* DEC Direct data link interface */
8923751Skarels #define AF_LAT		14		/* LAT */
9023751Skarels #define	AF_HYLINK	15		/* NSC Hyperchannel */
9128881Skarels #define	AF_APPLETALK	16		/* Apple Talk */
9236353Ssklower #define	AF_ROUTE	17		/* Internal Routing Protocol */
93*40764Skarels #define	AF_LINK		18		/* Link layer interface */
94*40764Skarels #define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
954930Swnj 
96*40764Skarels #define	AF_MAX		20
974930Swnj 
984930Swnj /*
9912787Ssam  * Structure used by kernel to store most
10012787Ssam  * addresses.
1014930Swnj  */
1024930Swnj struct sockaddr {
10335796Ssklower 	u_char	sa_len;			/* total length */
10435796Ssklower 	u_char	sa_family;		/* address family */
10536353Ssklower 	char	sa_data[14];		/* actually longer; address value */
10635796Ssklower };
1074930Swnj 
1084930Swnj /*
10912787Ssam  * Structure used by kernel to pass protocol
11012787Ssam  * information in raw sockets.
1114930Swnj  */
11212787Ssam struct sockproto {
11312787Ssam 	u_short	sp_family;		/* address family */
11412787Ssam 	u_short	sp_protocol;		/* protocol */
11512787Ssam };
1166620Ssam 
11712787Ssam /*
11812787Ssam  * Protocol families, same as address families for now.
11912787Ssam  */
12012787Ssam #define	PF_UNSPEC	AF_UNSPEC
12112787Ssam #define	PF_UNIX		AF_UNIX
12212787Ssam #define	PF_INET		AF_INET
12312787Ssam #define	PF_IMPLINK	AF_IMPLINK
12412787Ssam #define	PF_PUP		AF_PUP
12512787Ssam #define	PF_CHAOS	AF_CHAOS
12612787Ssam #define	PF_NS		AF_NS
12736353Ssklower #define	PF_ISO		AF_ISO
128*40764Skarels #define	PF_OSI		AF_ISO
12912787Ssam #define	PF_ECMA		AF_ECMA
13012787Ssam #define	PF_DATAKIT	AF_DATAKIT
13112787Ssam #define	PF_CCITT	AF_CCITT
13212787Ssam #define	PF_SNA		AF_SNA
13323751Skarels #define PF_DECnet	AF_DECnet
13423751Skarels #define PF_DLI		AF_DLI
13523751Skarels #define PF_LAT		AF_LAT
13623751Skarels #define	PF_HYLINK	AF_HYLINK
13728881Skarels #define	PF_APPLETALK	AF_APPLETALK
13836353Ssklower #define	PF_ROUTE	AF_ROUTE
139*40764Skarels #define	PF_LINK		AF_LINK
140*40764Skarels #define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
1418274Sroot 
14223751Skarels #define	PF_MAX		AF_MAX
14312787Ssam 
14412787Ssam /*
14512787Ssam  * Maximum queue length specifiable by listen.
14612787Ssam  */
14712787Ssam #define	SOMAXCONN	5
14812787Ssam 
14912787Ssam /*
15012787Ssam  * Message header for recvmsg and sendmsg calls.
15135796Ssklower  * Used value-result for recvmsg, value only for sendmsg.
15212787Ssam  */
15312787Ssam struct msghdr {
15412787Ssam 	caddr_t	msg_name;		/* optional address */
15512787Ssam 	int	msg_namelen;		/* size of address */
15612787Ssam 	struct	iovec *msg_iov;		/* scatter/gather array */
15712787Ssam 	int	msg_iovlen;		/* # elements in msg_iov */
158*40764Skarels 	caddr_t	msg_control;		/* ancillary data, see below */
159*40764Skarels 	int	msg_controllen;		/* ancillary data buffer len */
16035796Ssklower 	int	msg_flags;		/* flags on received message */
16112787Ssam };
16212787Ssam 
16312787Ssam #define	MSG_OOB		0x1		/* process out-of-band data */
16412787Ssam #define	MSG_PEEK	0x2		/* peek at incoming message */
16512787Ssam #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
16635796Ssklower #define	MSG_EOR		0x8		/* data completes record */
16735796Ssklower #define	MSG_TRUNC	0x10		/* data discarded before delivery */
16835796Ssklower #define	MSG_CTRUNC	0x20		/* control data lost before delivery */
169*40764Skarels #define	MSG_WAITALL	0x40		/* wait for full request or error */
17012787Ssam 
171*40764Skarels #define	MSG_MAXIOVLEN	16
172*40764Skarels 
17335796Ssklower /*
174*40764Skarels  * Header for ancillary data objects in msg_control buffer.
175*40764Skarels  * Used for additional information with/about a datagram
176*40764Skarels  * not expressible by flags.  The format is a sequence
177*40764Skarels  * of message elements headed by cmsghdr structures.
178*40764Skarels  */
179*40764Skarels struct cmsghdr {
180*40764Skarels 	u_int	cmsg_len;		/* data byte count, including hdr */
181*40764Skarels 	u_int	cmsg_level;		/* originating protocol */
182*40764Skarels 	u_int	cmsg_type;		/* protocol-specific type */
183*40764Skarels /* followed by	u_char  cmsg_data[]; */
184*40764Skarels };
185*40764Skarels 
186*40764Skarels /* given pointer to struct adatahdr, return pointer to data */
187*40764Skarels #define	CMSG_DATA(cmsg)		((u_char *)((cmsg) + 1))
188*40764Skarels 
189*40764Skarels /* given pointer to struct adatahdr, return pointer to next adatahdr */
190*40764Skarels #define	CMSG_NXTHDR(mhdr, cmsg)	\
191*40764Skarels 	(((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
192*40764Skarels 	    (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
193*40764Skarels 	    (struct cmsghdr *)NULL : \
194*40764Skarels 	    (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
195*40764Skarels 
196*40764Skarels #define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
197*40764Skarels 
198*40764Skarels /* "Socket"-level control message types: */
199*40764Skarels #define	SCM_RIGHTS	0x01		/* access rights (array of int) */
200*40764Skarels 
201*40764Skarels /*
202*40764Skarels  * 4.3 compat sockaddr, move to compat file later
203*40764Skarels  */
204*40764Skarels struct osockaddr {
205*40764Skarels 	u_short	sa_family;		/* address family */
206*40764Skarels 	char	sa_data[14];		/* up to 14 bytes of direct address */
207*40764Skarels };
208*40764Skarels 
209*40764Skarels /*
21035796Ssklower  * 4.3-compat message header (move to compat file later).
21135796Ssklower  */
21235796Ssklower struct omsghdr {
21335796Ssklower 	caddr_t	msg_name;		/* optional address */
21435796Ssklower 	int	msg_namelen;		/* size of address */
21535796Ssklower 	struct	iovec *msg_iov;		/* scatter/gather array */
21635796Ssklower 	int	msg_iovlen;		/* # elements in msg_iov */
21735796Ssklower 	caddr_t	msg_accrights;		/* access rights sent/received */
21835796Ssklower 	int	msg_accrightslen;
21935796Ssklower };
220