xref: /original-bsd/sys/sys/socket.h (revision 2301fdfb)
1 /*
2  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)socket.h	7.5 (Berkeley) 12/13/88
18  */
19 
20 /*
21  * Definitions related to sockets: types, address families, options.
22  */
23 
24 /*
25  * Types
26  */
27 #define	SOCK_STREAM	1		/* stream socket */
28 #define	SOCK_DGRAM	2		/* datagram socket */
29 #define	SOCK_RAW	3		/* raw-protocol interface */
30 #define	SOCK_RDM	4		/* reliably-delivered message */
31 #define	SOCK_SEQPACKET	5		/* sequenced packet stream */
32 
33 /*
34  * Option flags per-socket.
35  */
36 #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
37 #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
38 #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
39 #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
40 #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
41 #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
42 #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
43 #define	SO_LINGER	0x0080		/* linger on close if data present */
44 #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
45 
46 /*
47  * Additional options, not kept in so_options.
48  */
49 #define SO_SNDBUF	0x1001		/* send buffer size */
50 #define SO_RCVBUF	0x1002		/* receive buffer size */
51 #define SO_SNDLOWAT	0x1003		/* send low-water mark */
52 #define SO_RCVLOWAT	0x1004		/* receive low-water mark */
53 #define SO_SNDTIMEO	0x1005		/* send timeout */
54 #define SO_RCVTIMEO	0x1006		/* receive timeout */
55 #define	SO_ERROR	0x1007		/* get error status and clear */
56 #define	SO_TYPE		0x1008		/* get socket type */
57 
58 /*
59  * Structure used for manipulating linger option.
60  */
61 struct	linger {
62 	int	l_onoff;		/* option on/off */
63 	int	l_linger;		/* linger time */
64 };
65 
66 /*
67  * Level number for (get/set)sockopt() to apply to socket itself.
68  */
69 #define	SOL_SOCKET	0xffff		/* options for socket level */
70 
71 /*
72  * Address families.
73  */
74 #define	AF_UNSPEC	0		/* unspecified */
75 #define	AF_UNIX		1		/* local to host (pipes, portals) */
76 #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
77 #define	AF_IMPLINK	3		/* arpanet imp addresses */
78 #define	AF_PUP		4		/* pup protocols: e.g. BSP */
79 #define	AF_CHAOS	5		/* mit CHAOS protocols */
80 #define	AF_NS		6		/* XEROX NS protocols */
81 #define	AF_ISO		7		/* ISO protocols */
82 #define	AF_ECMA		8		/* european computer manufacturers */
83 #define	AF_DATAKIT	9		/* datakit protocols */
84 #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
85 #define	AF_SNA		11		/* IBM SNA */
86 #define AF_DECnet	12		/* DECnet */
87 #define AF_DLI		13		/* Direct data link interface */
88 #define AF_LAT		14		/* LAT */
89 #define	AF_HYLINK	15		/* NSC Hyperchannel */
90 #define	AF_APPLETALK	16		/* Apple Talk */
91 #define	AF_ROUTE	17		/* Internal Routing Protocol */
92 
93 #define	AF_MAX		18
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  * 4.3 compat sockaddr, move to compat file later
106  */
107 struct osockaddr {
108 	u_short	sa_family;		/* address family */
109 	char	sa_data[14];		/* up to 14 bytes of direct address */
110 };
111 
112 /*
113  * Structure used by kernel to pass protocol
114  * information in raw sockets.
115  */
116 struct sockproto {
117 	u_short	sp_family;		/* address family */
118 	u_short	sp_protocol;		/* protocol */
119 };
120 
121 /*
122  * Protocol families, same as address families for now.
123  */
124 #define	PF_UNSPEC	AF_UNSPEC
125 #define	PF_UNIX		AF_UNIX
126 #define	PF_INET		AF_INET
127 #define	PF_IMPLINK	AF_IMPLINK
128 #define	PF_PUP		AF_PUP
129 #define	PF_CHAOS	AF_CHAOS
130 #define	PF_NS		AF_NS
131 #define	PF_ISO		AF_ISO
132 #define	PF_ECMA		AF_ECMA
133 #define	PF_DATAKIT	AF_DATAKIT
134 #define	PF_CCITT	AF_CCITT
135 #define	PF_SNA		AF_SNA
136 #define PF_DECnet	AF_DECnet
137 #define PF_DLI		AF_DLI
138 #define PF_LAT		AF_LAT
139 #define	PF_HYLINK	AF_HYLINK
140 #define	PF_APPLETALK	AF_APPLETALK
141 #define	PF_ROUTE	AF_ROUTE
142 
143 #define	PF_MAX		AF_MAX
144 
145 /*
146  * Maximum queue length specifiable by listen.
147  */
148 #define	SOMAXCONN	5
149 
150 /*
151  * Message header for recvmsg and sendmsg calls.
152  * Used value-result for recvmsg, value only for sendmsg.
153  */
154 struct msghdr {
155 	caddr_t	msg_name;		/* optional address */
156 	int	msg_namelen;		/* size of address */
157 	struct	iovec *msg_iov;		/* scatter/gather array */
158 	int	msg_iovlen;		/* # elements in msg_iov */
159 	caddr_t	msg_accrights;		/* access rights sent/received */
160 	int	msg_accrightslen;
161 	caddr_t	msg_control;		/* ancillary data not conveyable
162 					 * by flags; msgs of the form
163 					 *	u_short type;
164 					 *	u_short count;
165 					 *	u_char  data[count];
166 					 */
167 	int	msg_controllen;
168 	int	msg_flags;		/* flags on received message */
169 };
170 
171 #define	MSG_OOB		0x1		/* process out-of-band data */
172 #define	MSG_PEEK	0x2		/* peek at incoming message */
173 #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
174 #define	MSG_EOR		0x8		/* data completes record */
175 #define	MSG_TRUNC	0x10		/* data discarded before delivery */
176 #define	MSG_CTRUNC	0x20		/* control data lost before delivery */
177 
178 /*
179  * 4.3-compat message header (move to compat file later).
180  */
181 struct omsghdr {
182 	caddr_t	msg_name;		/* optional address */
183 	int	msg_namelen;		/* size of address */
184 	struct	iovec *msg_iov;		/* scatter/gather array */
185 	int	msg_iovlen;		/* # elements in msg_iov */
186 	caddr_t	msg_accrights;		/* access rights sent/received */
187 	int	msg_accrightslen;
188 };
189 
190 #define	MSG_MAXIOVLEN	16
191