xref: /original-bsd/sys/sys/socket.h (revision 68d9582f)
1 /*
2  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)socket.h	7.16 (Berkeley) 05/19/92
8  */
9 
10 /*
11  * Definitions related to sockets: types, address families, options.
12  */
13 
14 /*
15  * Types
16  */
17 #define	SOCK_STREAM	1		/* stream socket */
18 #define	SOCK_DGRAM	2		/* datagram socket */
19 #define	SOCK_RAW	3		/* raw-protocol interface */
20 #define	SOCK_RDM	4		/* reliably-delivered message */
21 #define	SOCK_SEQPACKET	5		/* sequenced packet stream */
22 
23 /*
24  * Option flags per-socket.
25  */
26 #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
27 #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
28 #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
29 #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
30 #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
31 #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
32 #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
33 #define	SO_LINGER	0x0080		/* linger on close if data present */
34 #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
35 
36 /*
37  * Additional options, not kept in so_options.
38  */
39 #define SO_SNDBUF	0x1001		/* send buffer size */
40 #define SO_RCVBUF	0x1002		/* receive buffer size */
41 #define SO_SNDLOWAT	0x1003		/* send low-water mark */
42 #define SO_RCVLOWAT	0x1004		/* receive low-water mark */
43 #define SO_SNDTIMEO	0x1005		/* send timeout */
44 #define SO_RCVTIMEO	0x1006		/* receive timeout */
45 #define	SO_ERROR	0x1007		/* get error status and clear */
46 #define	SO_TYPE		0x1008		/* get socket type */
47 
48 /*
49  * Structure used for manipulating linger option.
50  */
51 struct	linger {
52 	int	l_onoff;		/* option on/off */
53 	int	l_linger;		/* linger time */
54 };
55 
56 /*
57  * Level number for (get/set)sockopt() to apply to socket itself.
58  */
59 #define	SOL_SOCKET	0xffff		/* options for socket level */
60 
61 /*
62  * Address families.
63  */
64 #define	AF_UNSPEC	0		/* unspecified */
65 #define	AF_UNIX		1		/* local to host (pipes, portals) */
66 #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
67 #define	AF_IMPLINK	3		/* arpanet imp addresses */
68 #define	AF_PUP		4		/* pup protocols: e.g. BSP */
69 #define	AF_CHAOS	5		/* mit CHAOS protocols */
70 #define	AF_NS		6		/* XEROX NS protocols */
71 #define	AF_ISO		7		/* ISO protocols */
72 #define	AF_OSI		AF_ISO
73 #define	AF_ECMA		8		/* european computer manufacturers */
74 #define	AF_DATAKIT	9		/* datakit protocols */
75 #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
76 #define	AF_SNA		11		/* IBM SNA */
77 #define AF_DECnet	12		/* DECnet */
78 #define AF_DLI		13		/* DEC Direct data link interface */
79 #define AF_LAT		14		/* LAT */
80 #define	AF_HYLINK	15		/* NSC Hyperchannel */
81 #define	AF_APPLETALK	16		/* Apple Talk */
82 #define	AF_ROUTE	17		/* Internal Routing Protocol */
83 #define	AF_LINK		18		/* Link layer interface */
84 #define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
85 #define	AF_COIP		20		/* connection-oriented IP, aka ST II */
86 #define	AF_CNT		21		/* Computer Network Technology */
87 
88 #define	AF_MAX		22
89 
90 /*
91  * Structure used by kernel to store most
92  * addresses.
93  */
94 struct sockaddr {
95 	u_char	sa_len;			/* total length */
96 	u_char	sa_family;		/* address family */
97 	char	sa_data[14];		/* actually longer; address value */
98 };
99 
100 /*
101  * Structure used by kernel to pass protocol
102  * information in raw sockets.
103  */
104 struct sockproto {
105 	u_short	sp_family;		/* address family */
106 	u_short	sp_protocol;		/* protocol */
107 };
108 
109 /*
110  * Protocol families, same as address families for now.
111  */
112 #define	PF_UNSPEC	AF_UNSPEC
113 #define	PF_UNIX		AF_UNIX
114 #define	PF_INET		AF_INET
115 #define	PF_IMPLINK	AF_IMPLINK
116 #define	PF_PUP		AF_PUP
117 #define	PF_CHAOS	AF_CHAOS
118 #define	PF_NS		AF_NS
119 #define	PF_ISO		AF_ISO
120 #define	PF_OSI		AF_ISO
121 #define	PF_ECMA		AF_ECMA
122 #define	PF_DATAKIT	AF_DATAKIT
123 #define	PF_CCITT	AF_CCITT
124 #define	PF_SNA		AF_SNA
125 #define PF_DECnet	AF_DECnet
126 #define PF_DLI		AF_DLI
127 #define PF_LAT		AF_LAT
128 #define	PF_HYLINK	AF_HYLINK
129 #define	PF_APPLETALK	AF_APPLETALK
130 #define	PF_ROUTE	AF_ROUTE
131 #define	PF_LINK		AF_LINK
132 #define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
133 #define	PF_COIP		AF_COIP
134 #define	PF_CNT		AF_CNT
135 
136 #define	PF_MAX		AF_MAX
137 
138 /*
139  * Maximum queue length specifiable by listen.
140  */
141 #define	SOMAXCONN	5
142 
143 /*
144  * Message header for recvmsg and sendmsg calls.
145  * Used value-result for recvmsg, value only for sendmsg.
146  */
147 struct msghdr {
148 	caddr_t	msg_name;		/* optional address */
149 	u_int	msg_namelen;		/* size of address */
150 	struct	iovec *msg_iov;		/* scatter/gather array */
151 	u_int	msg_iovlen;		/* # elements in msg_iov */
152 	caddr_t	msg_control;		/* ancillary data, see below */
153 	u_int	msg_controllen;		/* ancillary data buffer len */
154 	int	msg_flags;		/* flags on received message */
155 };
156 
157 #define	MSG_OOB		0x1		/* process out-of-band data */
158 #define	MSG_PEEK	0x2		/* peek at incoming message */
159 #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
160 #define	MSG_EOR		0x8		/* data completes record */
161 #define	MSG_TRUNC	0x10		/* data discarded before delivery */
162 #define	MSG_CTRUNC	0x20		/* control data lost before delivery */
163 #define	MSG_WAITALL	0x40		/* wait for full request or error */
164 #define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
165 
166 /*
167  * Header for ancillary data objects in msg_control buffer.
168  * Used for additional information with/about a datagram
169  * not expressible by flags.  The format is a sequence
170  * of message elements headed by cmsghdr structures.
171  */
172 struct cmsghdr {
173 	u_int	cmsg_len;		/* data byte count, including hdr */
174 	int	cmsg_level;		/* originating protocol */
175 	int	cmsg_type;		/* protocol-specific type */
176 /* followed by	u_char  cmsg_data[]; */
177 };
178 
179 /* given pointer to struct adatahdr, return pointer to data */
180 #define	CMSG_DATA(cmsg)		((u_char *)((cmsg) + 1))
181 
182 /* given pointer to struct adatahdr, return pointer to next adatahdr */
183 #define	CMSG_NXTHDR(mhdr, cmsg)	\
184 	(((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
185 	    (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
186 	    (struct cmsghdr *)NULL : \
187 	    (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
188 
189 #define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
190 
191 /* "Socket"-level control message types: */
192 #define	SCM_RIGHTS	0x01		/* access rights (array of int) */
193 
194 /*
195  * 4.3 compat sockaddr, move to compat file later
196  */
197 struct osockaddr {
198 	u_short	sa_family;		/* address family */
199 	char	sa_data[14];		/* up to 14 bytes of direct address */
200 };
201 
202 /*
203  * 4.3-compat message header (move to compat file later).
204  */
205 struct omsghdr {
206 	caddr_t	msg_name;		/* optional address */
207 	int	msg_namelen;		/* size of address */
208 	struct	iovec *msg_iov;		/* scatter/gather array */
209 	int	msg_iovlen;		/* # elements in msg_iov */
210 	caddr_t	msg_accrights;		/* access rights sent/received */
211 	int	msg_accrightslen;
212 };
213 
214 #ifndef	KERNEL
215 
216 #include <sys/cdefs.h>
217 
218 __BEGIN_DECLS
219 int	accept __P((int, struct sockaddr *, int *));
220 int	bind __P((int, const struct sockaddr *, int));
221 int	connect __P((int, const struct sockaddr *, int));
222 int	getpeername __P((int, struct sockaddr *, int *));
223 int	getsockname __P((int, struct sockaddr *, int *));
224 int	getsockopt __P((int, int, int, void *, int *));
225 int	listen __P((int, int));
226 int	recv __P((int, void *, int, int));
227 int	recvfrom __P((int, void *, int, int,
228 		struct sockaddr *, int *));
229 int	recvmsg __P((int, struct msghdr *, int));
230 int	send __P((int, const void *, int, int));
231 int	sendto __P((int, const void *, int, int, const struct sockaddr *, int));
232 int	sendmsg __P((int, const struct msghdr *, int));
233 int	setsockopt __P((int, int, int, const void *, int));
234 int	shutdown __P((int, int));
235 int	socket __P((int, int, int));
236 int	socketpair __P((int, int, int, int *));
237 __END_DECLS
238 
239 #endif	/* !KERNEL */
240