xref: /csrg-svn/sys/sys/socket.h (revision 42464)
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*42464Ssklower  *	@(#)socket.h	7.9 (Berkeley) 05/30/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 */
8240764Skarels #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 */
8840764Skarels #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 */
9340764Skarels #define	AF_LINK		18		/* Link layer interface */
9440764Skarels #define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
954930Swnj 
9640764Skarels #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
12840764Skarels #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
13940764Skarels #define	PF_LINK		AF_LINK
14040764Skarels #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 */
155*42464Ssklower 	u_int	msg_namelen;		/* size of address */
15612787Ssam 	struct	iovec *msg_iov;		/* scatter/gather array */
157*42464Ssklower 	u_int	msg_iovlen;		/* # elements in msg_iov */
15840764Skarels 	caddr_t	msg_control;		/* ancillary data, see below */
159*42464Ssklower 	u_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 */
16940764Skarels #define	MSG_WAITALL	0x40		/* wait for full request or error */
17012787Ssam 
17135796Ssklower /*
17240764Skarels  * Header for ancillary data objects in msg_control buffer.
17340764Skarels  * Used for additional information with/about a datagram
17440764Skarels  * not expressible by flags.  The format is a sequence
17540764Skarels  * of message elements headed by cmsghdr structures.
17640764Skarels  */
17740764Skarels struct cmsghdr {
17840764Skarels 	u_int	cmsg_len;		/* data byte count, including hdr */
179*42464Ssklower 	int	cmsg_level;		/* originating protocol */
180*42464Ssklower 	int	cmsg_type;		/* protocol-specific type */
18140764Skarels /* followed by	u_char  cmsg_data[]; */
18240764Skarels };
18340764Skarels 
18440764Skarels /* given pointer to struct adatahdr, return pointer to data */
18540764Skarels #define	CMSG_DATA(cmsg)		((u_char *)((cmsg) + 1))
18640764Skarels 
18740764Skarels /* given pointer to struct adatahdr, return pointer to next adatahdr */
18840764Skarels #define	CMSG_NXTHDR(mhdr, cmsg)	\
18940764Skarels 	(((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
19040764Skarels 	    (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
19140764Skarels 	    (struct cmsghdr *)NULL : \
19240764Skarels 	    (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
19340764Skarels 
19440764Skarels #define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
19540764Skarels 
19640764Skarels /* "Socket"-level control message types: */
19740764Skarels #define	SCM_RIGHTS	0x01		/* access rights (array of int) */
19840764Skarels 
19940764Skarels /*
20040764Skarels  * 4.3 compat sockaddr, move to compat file later
20140764Skarels  */
20240764Skarels struct osockaddr {
20340764Skarels 	u_short	sa_family;		/* address family */
20440764Skarels 	char	sa_data[14];		/* up to 14 bytes of direct address */
20540764Skarels };
20640764Skarels 
20740764Skarels /*
20835796Ssklower  * 4.3-compat message header (move to compat file later).
20935796Ssklower  */
21035796Ssklower struct omsghdr {
21135796Ssklower 	caddr_t	msg_name;		/* optional address */
21235796Ssklower 	int	msg_namelen;		/* size of address */
21335796Ssklower 	struct	iovec *msg_iov;		/* scatter/gather array */
21435796Ssklower 	int	msg_iovlen;		/* # elements in msg_iov */
21535796Ssklower 	caddr_t	msg_accrights;		/* access rights sent/received */
21635796Ssklower 	int	msg_accrightslen;
21735796Ssklower };
218