xref: /original-bsd/sys/sys/socket.h (revision d73dd342)
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.20 (Berkeley) 04/08/93
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 #define	SO_REUSEPORT	0x0200		/* allow local address & port reuse */
36 
37 /*
38  * Additional options, not kept in so_options.
39  */
40 #define SO_SNDBUF	0x1001		/* send buffer size */
41 #define SO_RCVBUF	0x1002		/* receive buffer size */
42 #define SO_SNDLOWAT	0x1003		/* send low-water mark */
43 #define SO_RCVLOWAT	0x1004		/* receive low-water mark */
44 #define SO_SNDTIMEO	0x1005		/* send timeout */
45 #define SO_RCVTIMEO	0x1006		/* receive timeout */
46 #define	SO_ERROR	0x1007		/* get error status and clear */
47 #define	SO_TYPE		0x1008		/* get socket type */
48 
49 /*
50  * Structure used for manipulating linger option.
51  */
52 struct	linger {
53 	int	l_onoff;		/* option on/off */
54 	int	l_linger;		/* linger time */
55 };
56 
57 /*
58  * Level number for (get/set)sockopt() to apply to socket itself.
59  */
60 #define	SOL_SOCKET	0xffff		/* options for socket level */
61 
62 /*
63  * Address families.
64  */
65 #define	AF_UNSPEC	0		/* unspecified */
66 #define	AF_UNIX		1		/* local to host (pipes, portals) */
67 #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
68 #define	AF_IMPLINK	3		/* arpanet imp addresses */
69 #define	AF_PUP		4		/* pup protocols: e.g. BSP */
70 #define	AF_CHAOS	5		/* mit CHAOS protocols */
71 #define	AF_NS		6		/* XEROX NS protocols */
72 #define	AF_ISO		7		/* ISO protocols */
73 #define	AF_OSI		AF_ISO
74 #define	AF_ECMA		8		/* european computer manufacturers */
75 #define	AF_DATAKIT	9		/* datakit protocols */
76 #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
77 #define	AF_SNA		11		/* IBM SNA */
78 #define AF_DECnet	12		/* DECnet */
79 #define AF_DLI		13		/* DEC Direct data link interface */
80 #define AF_LAT		14		/* LAT */
81 #define	AF_HYLINK	15		/* NSC Hyperchannel */
82 #define	AF_APPLETALK	16		/* Apple Talk */
83 #define	AF_ROUTE	17		/* Internal Routing Protocol */
84 #define	AF_LINK		18		/* Link layer interface */
85 #define	pseudo_AF_XTP	19		/* eXpress Transfer Protocol (no AF) */
86 #define	AF_COIP		20		/* connection-oriented IP, aka ST II */
87 #define	AF_CNT		21		/* Computer Network Technology */
88 #define pseudo_AF_RTIP	22		/* Help Identify RTIP packets */
89 #define	AF_IPX		23		/* Novell Internet Protocol */
90 #define	AF_SIP		24		/* Simple Internet Protocol */
91 #define pseudo_AF_PIP	25		/* Help Identify PIP packets */
92 
93 #define	AF_MAX		26
94 
95 /*
96  * Structure used by kernel to store most
97  * addresses.
98  */
99 struct sockaddr {
100 	u_char	sa_len;			/* total length */
101 	u_char	sa_family;		/* address family */
102 	char	sa_data[14];		/* actually longer; address value */
103 };
104 
105 /*
106  * Structure used by kernel to pass protocol
107  * information in raw sockets.
108  */
109 struct sockproto {
110 	u_short	sp_family;		/* address family */
111 	u_short	sp_protocol;		/* protocol */
112 };
113 
114 /*
115  * Protocol families, same as address families for now.
116  */
117 #define	PF_UNSPEC	AF_UNSPEC
118 #define	PF_UNIX		AF_UNIX
119 #define	PF_INET		AF_INET
120 #define	PF_IMPLINK	AF_IMPLINK
121 #define	PF_PUP		AF_PUP
122 #define	PF_CHAOS	AF_CHAOS
123 #define	PF_NS		AF_NS
124 #define	PF_ISO		AF_ISO
125 #define	PF_OSI		AF_ISO
126 #define	PF_ECMA		AF_ECMA
127 #define	PF_DATAKIT	AF_DATAKIT
128 #define	PF_CCITT	AF_CCITT
129 #define	PF_SNA		AF_SNA
130 #define PF_DECnet	AF_DECnet
131 #define PF_DLI		AF_DLI
132 #define PF_LAT		AF_LAT
133 #define	PF_HYLINK	AF_HYLINK
134 #define	PF_APPLETALK	AF_APPLETALK
135 #define	PF_ROUTE	AF_ROUTE
136 #define	PF_LINK		AF_LINK
137 #define	PF_XTP		pseudo_AF_XTP	/* really just proto family, no AF */
138 #define	PF_COIP		AF_COIP
139 #define	PF_CNT		AF_CNT
140 #define	PF_SIP		AF_SIP
141 #define	PF_IPX		AF_IPX		/* same format as AF_NS */
142 #define PF_RTIP		pseudo_AF_FTIP	/* same format as AF_INET */
143 #define PF_PIP		pseudo_AF_PIP
144 
145 #define	PF_MAX		AF_MAX
146 
147 /*
148  * Definitions for network related sysctl, CTL_NET.
149  *
150  * Second level is protocol family.
151  * Third level is protocol number.
152  *
153  * Further levels are defined by the individual families below.
154  */
155 #define NET_MAXID	AF_MAX
156 
157 #define CTL_NET_NAMES { \
158 	"unspec", \
159 	"unix", \
160 	"inet", \
161 	"implink", \
162 	"pup", \
163 	"chaos", \
164 	"xerox_ns", \
165 	"iso", \
166 	"emca", \
167 	"datakit", \
168 	"ccitt", \
169 	"ibm_sna", \
170 	"decnet", \
171 	"dec_dli", \
172 	"lat", \
173 	"hylink", \
174 	"appletalk", \
175 	"route", \
176 	"link_layer", \
177 	"xtp", \
178 	"coip", \
179 	"cnt", \
180 }
181 
182 /*
183  * PF_ROUTE - Routing table
184  *
185  * Three additional levels are defined:
186  *	Fourth: address family, 0 is wildcard
187  *	Fifth: type of info, defined below
188  *	Sixth: flag(s) to mask with for NET_RT_FLAGS
189  */
190 #define NET_RT_DUMP	1		/* dump; may limit to a.f. */
191 #define NET_RT_FLAGS	2		/* by flags, e.g. RESOLVING */
192 #define NET_RT_IFLIST	3		/* survey interface list */
193 
194 #define CTL_NET_RT_NAMES { \
195 	"unspec", \
196 	"dump", \
197 	"flags", \
198 	"iflist", \
199 }
200 
201 /*
202  * Maximum queue length specifiable by listen.
203  */
204 #define	SOMAXCONN	5
205 
206 /*
207  * Message header for recvmsg and sendmsg calls.
208  * Used value-result for recvmsg, value only for sendmsg.
209  */
210 struct msghdr {
211 	caddr_t	msg_name;		/* optional address */
212 	u_int	msg_namelen;		/* size of address */
213 	struct	iovec *msg_iov;		/* scatter/gather array */
214 	u_int	msg_iovlen;		/* # elements in msg_iov */
215 	caddr_t	msg_control;		/* ancillary data, see below */
216 	u_int	msg_controllen;		/* ancillary data buffer len */
217 	int	msg_flags;		/* flags on received message */
218 };
219 
220 #define	MSG_OOB		0x1		/* process out-of-band data */
221 #define	MSG_PEEK	0x2		/* peek at incoming message */
222 #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
223 #define	MSG_EOR		0x8		/* data completes record */
224 #define	MSG_TRUNC	0x10		/* data discarded before delivery */
225 #define	MSG_CTRUNC	0x20		/* control data lost before delivery */
226 #define	MSG_WAITALL	0x40		/* wait for full request or error */
227 #define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */
228 
229 /*
230  * Header for ancillary data objects in msg_control buffer.
231  * Used for additional information with/about a datagram
232  * not expressible by flags.  The format is a sequence
233  * of message elements headed by cmsghdr structures.
234  */
235 struct cmsghdr {
236 	u_int	cmsg_len;		/* data byte count, including hdr */
237 	int	cmsg_level;		/* originating protocol */
238 	int	cmsg_type;		/* protocol-specific type */
239 /* followed by	u_char  cmsg_data[]; */
240 };
241 
242 /* given pointer to struct adatahdr, return pointer to data */
243 #define	CMSG_DATA(cmsg)		((u_char *)((cmsg) + 1))
244 
245 /* given pointer to struct adatahdr, return pointer to next adatahdr */
246 #define	CMSG_NXTHDR(mhdr, cmsg)	\
247 	(((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
248 	    (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
249 	    (struct cmsghdr *)NULL : \
250 	    (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
251 
252 #define	CMSG_FIRSTHDR(mhdr)	((struct cmsghdr *)(mhdr)->msg_control)
253 
254 /* "Socket"-level control message types: */
255 #define	SCM_RIGHTS	0x01		/* access rights (array of int) */
256 
257 /*
258  * 4.3 compat sockaddr, move to compat file later
259  */
260 struct osockaddr {
261 	u_short	sa_family;		/* address family */
262 	char	sa_data[14];		/* up to 14 bytes of direct address */
263 };
264 
265 /*
266  * 4.3-compat message header (move to compat file later).
267  */
268 struct omsghdr {
269 	caddr_t	msg_name;		/* optional address */
270 	int	msg_namelen;		/* size of address */
271 	struct	iovec *msg_iov;		/* scatter/gather array */
272 	int	msg_iovlen;		/* # elements in msg_iov */
273 	caddr_t	msg_accrights;		/* access rights sent/received */
274 	int	msg_accrightslen;
275 };
276 
277 #ifndef	KERNEL
278 
279 #include <sys/cdefs.h>
280 
281 __BEGIN_DECLS
282 int	accept __P((int, struct sockaddr *, int *));
283 int	bind __P((int, const struct sockaddr *, int));
284 int	connect __P((int, const struct sockaddr *, int));
285 int	getpeername __P((int, struct sockaddr *, int *));
286 int	getsockname __P((int, struct sockaddr *, int *));
287 int	getsockopt __P((int, int, int, void *, int *));
288 int	listen __P((int, int));
289 int	recv __P((int, void *, int, int));
290 int	recvfrom __P((int, void *, int, int,
291 		struct sockaddr *, int *));
292 int	recvmsg __P((int, struct msghdr *, int));
293 int	send __P((int, const void *, int, int));
294 int	sendto __P((int, const void *, int, int, const struct sockaddr *, int));
295 int	sendmsg __P((int, const struct msghdr *, int));
296 int	setsockopt __P((int, int, int, const void *, int));
297 int	shutdown __P((int, int));
298 int	socket __P((int, int, int));
299 int	socketpair __P((int, int, int, int *));
300 __END_DECLS
301 
302 #endif	/* !KERNEL */
303