Annotation of src/sys/sys/socket.h, Revision 1.14
1.14 ! christos 1: /* $NetBSD: socket.h,v 1.13 1996/02/09 06:32:22 mycroft Exp $ */
1.10 cgd 2:
1.1 cgd 3: /*
1.8 mycroft 4: * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
5: * The Regents of the University of California. All rights reserved.
1.1 cgd 6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: *
1.9 cgd 35: * @(#)socket.h 8.4 (Berkeley) 2/21/94
1.1 cgd 36: */
37:
1.2 mycroft 38: #ifndef _SYS_SOCKET_H_
1.8 mycroft 39: #define _SYS_SOCKET_H_
1.2 mycroft 40:
1.1 cgd 41: /*
42: * Definitions related to sockets: types, address families, options.
43: */
44:
45: /*
46: * Types
47: */
48: #define SOCK_STREAM 1 /* stream socket */
49: #define SOCK_DGRAM 2 /* datagram socket */
50: #define SOCK_RAW 3 /* raw-protocol interface */
51: #define SOCK_RDM 4 /* reliably-delivered message */
52: #define SOCK_SEQPACKET 5 /* sequenced packet stream */
53:
54: /*
55: * Option flags per-socket.
56: */
57: #define SO_DEBUG 0x0001 /* turn on debugging info recording */
58: #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
59: #define SO_REUSEADDR 0x0004 /* allow local address reuse */
60: #define SO_KEEPALIVE 0x0008 /* keep connections alive */
61: #define SO_DONTROUTE 0x0010 /* just use interface addresses */
62: #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
63: #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
64: #define SO_LINGER 0x0080 /* linger on close if data present */
65: #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
1.8 mycroft 66: #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
1.1 cgd 67:
68: /*
69: * Additional options, not kept in so_options.
70: */
71: #define SO_SNDBUF 0x1001 /* send buffer size */
72: #define SO_RCVBUF 0x1002 /* receive buffer size */
73: #define SO_SNDLOWAT 0x1003 /* send low-water mark */
74: #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
75: #define SO_SNDTIMEO 0x1005 /* send timeout */
76: #define SO_RCVTIMEO 0x1006 /* receive timeout */
77: #define SO_ERROR 0x1007 /* get error status and clear */
78: #define SO_TYPE 0x1008 /* get socket type */
79:
80: /*
81: * Structure used for manipulating linger option.
82: */
83: struct linger {
84: int l_onoff; /* option on/off */
85: int l_linger; /* linger time */
86: };
87:
88: /*
89: * Level number for (get/set)sockopt() to apply to socket itself.
90: */
91: #define SOL_SOCKET 0xffff /* options for socket level */
92:
93: /*
94: * Address families.
95: */
96: #define AF_UNSPEC 0 /* unspecified */
1.8 mycroft 97: #define AF_LOCAL 1 /* local to host (pipes, portals) */
98: #define AF_UNIX AF_LOCAL /* backward compatibility */
1.1 cgd 99: #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
100: #define AF_IMPLINK 3 /* arpanet imp addresses */
101: #define AF_PUP 4 /* pup protocols: e.g. BSP */
102: #define AF_CHAOS 5 /* mit CHAOS protocols */
103: #define AF_NS 6 /* XEROX NS protocols */
104: #define AF_ISO 7 /* ISO protocols */
105: #define AF_OSI AF_ISO
106: #define AF_ECMA 8 /* european computer manufacturers */
107: #define AF_DATAKIT 9 /* datakit protocols */
108: #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
109: #define AF_SNA 11 /* IBM SNA */
110: #define AF_DECnet 12 /* DECnet */
111: #define AF_DLI 13 /* DEC Direct data link interface */
112: #define AF_LAT 14 /* LAT */
113: #define AF_HYLINK 15 /* NSC Hyperchannel */
114: #define AF_APPLETALK 16 /* Apple Talk */
115: #define AF_ROUTE 17 /* Internal Routing Protocol */
116: #define AF_LINK 18 /* Link layer interface */
117: #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
1.8 mycroft 118: #define AF_COIP 20 /* connection-oriented IP, aka ST II */
119: #define AF_CNT 21 /* Computer Network Technology */
120: #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
121: #define AF_IPX 23 /* Novell Internet Protocol */
122: #define AF_SIP 24 /* Simple Internet Protocol */
123: #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
1.1 cgd 124:
1.8 mycroft 125: #define AF_MAX 26
1.1 cgd 126:
127: /*
128: * Structure used by kernel to store most
129: * addresses.
130: */
131: struct sockaddr {
132: u_char sa_len; /* total length */
133: u_char sa_family; /* address family */
134: char sa_data[14]; /* actually longer; address value */
135: };
136:
137: /*
138: * Structure used by kernel to pass protocol
139: * information in raw sockets.
140: */
141: struct sockproto {
142: u_short sp_family; /* address family */
143: u_short sp_protocol; /* protocol */
144: };
145:
146: /*
147: * Protocol families, same as address families for now.
148: */
149: #define PF_UNSPEC AF_UNSPEC
1.8 mycroft 150: #define PF_LOCAL AF_LOCAL
151: #define PF_UNIX PF_LOCAL /* backward compatibility */
1.1 cgd 152: #define PF_INET AF_INET
153: #define PF_IMPLINK AF_IMPLINK
154: #define PF_PUP AF_PUP
155: #define PF_CHAOS AF_CHAOS
156: #define PF_NS AF_NS
157: #define PF_ISO AF_ISO
158: #define PF_OSI AF_ISO
159: #define PF_ECMA AF_ECMA
160: #define PF_DATAKIT AF_DATAKIT
161: #define PF_CCITT AF_CCITT
162: #define PF_SNA AF_SNA
163: #define PF_DECnet AF_DECnet
164: #define PF_DLI AF_DLI
165: #define PF_LAT AF_LAT
166: #define PF_HYLINK AF_HYLINK
167: #define PF_APPLETALK AF_APPLETALK
168: #define PF_ROUTE AF_ROUTE
169: #define PF_LINK AF_LINK
170: #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
1.8 mycroft 171: #define PF_COIP AF_COIP
172: #define PF_CNT AF_CNT
173: #define PF_SIP AF_SIP
174: #define PF_IPX AF_IPX /* same format as AF_NS */
175: #define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */
176: #define PF_PIP pseudo_AF_PIP
1.1 cgd 177:
178: #define PF_MAX AF_MAX
179:
180: /*
1.8 mycroft 181: * Definitions for network related sysctl, CTL_NET.
182: *
183: * Second level is protocol family.
184: * Third level is protocol number.
185: *
186: * Further levels are defined by the individual families below.
187: */
188: #define NET_MAXID AF_MAX
189:
190: #define CTL_NET_NAMES { \
191: { 0, 0 }, \
192: { "unix", CTLTYPE_NODE }, \
193: { "inet", CTLTYPE_NODE }, \
194: { "implink", CTLTYPE_NODE }, \
195: { "pup", CTLTYPE_NODE }, \
196: { "chaos", CTLTYPE_NODE }, \
197: { "xerox_ns", CTLTYPE_NODE }, \
198: { "iso", CTLTYPE_NODE }, \
199: { "emca", CTLTYPE_NODE }, \
200: { "datakit", CTLTYPE_NODE }, \
201: { "ccitt", CTLTYPE_NODE }, \
202: { "ibm_sna", CTLTYPE_NODE }, \
203: { "decnet", CTLTYPE_NODE }, \
204: { "dec_dli", CTLTYPE_NODE }, \
205: { "lat", CTLTYPE_NODE }, \
206: { "hylink", CTLTYPE_NODE }, \
207: { "appletalk", CTLTYPE_NODE }, \
208: { "route", CTLTYPE_NODE }, \
209: { "link_layer", CTLTYPE_NODE }, \
210: { "xtp", CTLTYPE_NODE }, \
211: { "coip", CTLTYPE_NODE }, \
212: { "cnt", CTLTYPE_NODE }, \
213: { "rtip", CTLTYPE_NODE }, \
214: { "ipx", CTLTYPE_NODE }, \
215: { "sip", CTLTYPE_NODE }, \
216: { "pip", CTLTYPE_NODE }, \
217: }
218:
219: /*
220: * PF_ROUTE - Routing table
221: *
222: * Three additional levels are defined:
223: * Fourth: address family, 0 is wildcard
224: * Fifth: type of info, defined below
225: * Sixth: flag(s) to mask with for NET_RT_FLAGS
226: */
227: #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
228: #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
229: #define NET_RT_IFLIST 3 /* survey interface list */
230: #define NET_RT_MAXID 4
231:
232: #define CTL_NET_RT_NAMES { \
233: { 0, 0 }, \
234: { "dump", CTLTYPE_STRUCT }, \
235: { "flags", CTLTYPE_STRUCT }, \
236: { "iflist", CTLTYPE_STRUCT }, \
237: }
238:
239: /*
1.13 mycroft 240: * Maximum queue length specifiable by listen(2).
1.1 cgd 241: */
1.13 mycroft 242: #define SOMAXCONN 128
1.1 cgd 243:
244: /*
245: * Message header for recvmsg and sendmsg calls.
246: * Used value-result for recvmsg, value only for sendmsg.
247: */
248: struct msghdr {
249: caddr_t msg_name; /* optional address */
250: u_int msg_namelen; /* size of address */
251: struct iovec *msg_iov; /* scatter/gather array */
252: u_int msg_iovlen; /* # elements in msg_iov */
253: caddr_t msg_control; /* ancillary data, see below */
254: u_int msg_controllen; /* ancillary data buffer len */
255: int msg_flags; /* flags on received message */
256: };
257:
258: #define MSG_OOB 0x1 /* process out-of-band data */
259: #define MSG_PEEK 0x2 /* peek at incoming message */
260: #define MSG_DONTROUTE 0x4 /* send without using routing tables */
261: #define MSG_EOR 0x8 /* data completes record */
262: #define MSG_TRUNC 0x10 /* data discarded before delivery */
263: #define MSG_CTRUNC 0x20 /* control data lost before delivery */
264: #define MSG_WAITALL 0x40 /* wait for full request or error */
1.8 mycroft 265: #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
1.1 cgd 266:
267: /*
268: * Header for ancillary data objects in msg_control buffer.
269: * Used for additional information with/about a datagram
270: * not expressible by flags. The format is a sequence
271: * of message elements headed by cmsghdr structures.
272: */
273: struct cmsghdr {
274: u_int cmsg_len; /* data byte count, including hdr */
275: int cmsg_level; /* originating protocol */
276: int cmsg_type; /* protocol-specific type */
277: /* followed by u_char cmsg_data[]; */
278: };
279:
1.8 mycroft 280: /* given pointer to struct cmsghdr, return pointer to data */
1.1 cgd 281: #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
282:
1.8 mycroft 283: /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
1.1 cgd 284: #define CMSG_NXTHDR(mhdr, cmsg) \
285: (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
286: (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
287: (struct cmsghdr *)NULL : \
288: (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
289:
290: #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
291:
292: /* "Socket"-level control message types: */
293: #define SCM_RIGHTS 0x01 /* access rights (array of int) */
294:
295: /*
296: * 4.3 compat sockaddr, move to compat file later
297: */
298: struct osockaddr {
299: u_short sa_family; /* address family */
300: char sa_data[14]; /* up to 14 bytes of direct address */
301: };
302:
303: /*
304: * 4.3-compat message header (move to compat file later).
305: */
306: struct omsghdr {
307: caddr_t msg_name; /* optional address */
308: int msg_namelen; /* size of address */
309: struct iovec *msg_iov; /* scatter/gather array */
310: int msg_iovlen; /* # elements in msg_iov */
311: caddr_t msg_accrights; /* access rights sent/received */
312: int msg_accrightslen;
313: };
314:
1.12 briggs 315: #ifndef _KERNEL
1.1 cgd 316:
317: #include <sys/cdefs.h>
318:
319: __BEGIN_DECLS
320: int accept __P((int, struct sockaddr *, int *));
321: int bind __P((int, const struct sockaddr *, int));
322: int connect __P((int, const struct sockaddr *, int));
323: int getpeername __P((int, struct sockaddr *, int *));
324: int getsockname __P((int, struct sockaddr *, int *));
325: int getsockopt __P((int, int, int, void *, int *));
326: int listen __P((int, int));
1.8 mycroft 327: ssize_t recv __P((int, void *, size_t, int));
328: ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *));
329: ssize_t recvmsg __P((int, struct msghdr *, int));
330: ssize_t send __P((int, const void *, size_t, int));
331: ssize_t sendto __P((int, const void *,
332: size_t, int, const struct sockaddr *, int));
333: ssize_t sendmsg __P((int, const struct msghdr *, int));
1.1 cgd 334: int setsockopt __P((int, int, int, const void *, int));
335: int shutdown __P((int, int));
336: int socket __P((int, int, int));
337: int socketpair __P((int, int, int, int *));
338: __END_DECLS
1.14 ! christos 339: #else
! 340: # if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_LINUX) || \
! 341: defined(COMPAT_HPUX) || defined(COMPAT_FREEBSD)
! 342: # define COMPAT_OLDSOCK
! 343: # define MSG_COMPAT 0x8000
! 344: # endif
! 345: #endif /* !_KERNEL */
1.1 cgd 346:
1.2 mycroft 347: #endif /* !_SYS_SOCKET_H_ */
CVSweb <webmaster@jp.NetBSD.org>