Annotation of src/sys/sys/socket.h, Revision 1.17
1.17 ! chuck 1: /* $NetBSD: socket.h,v 1.16 1996/05/03 09:23:22 neil 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.17 ! chuck 124: #define AF_ISDN 26 /* Integrated Services Digital Network*/
! 125: #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
! 126: #define AF_NATM 27 /* native ATM access */
1.1 cgd 127:
1.17 ! chuck 128: #define AF_MAX 28
1.1 cgd 129:
130: /*
131: * Structure used by kernel to store most
132: * addresses.
133: */
134: struct sockaddr {
135: u_char sa_len; /* total length */
136: u_char sa_family; /* address family */
137: char sa_data[14]; /* actually longer; address value */
138: };
139:
140: /*
141: * Structure used by kernel to pass protocol
142: * information in raw sockets.
143: */
144: struct sockproto {
145: u_short sp_family; /* address family */
146: u_short sp_protocol; /* protocol */
147: };
148:
149: /*
150: * Protocol families, same as address families for now.
151: */
152: #define PF_UNSPEC AF_UNSPEC
1.8 mycroft 153: #define PF_LOCAL AF_LOCAL
154: #define PF_UNIX PF_LOCAL /* backward compatibility */
1.1 cgd 155: #define PF_INET AF_INET
156: #define PF_IMPLINK AF_IMPLINK
157: #define PF_PUP AF_PUP
158: #define PF_CHAOS AF_CHAOS
159: #define PF_NS AF_NS
160: #define PF_ISO AF_ISO
161: #define PF_OSI AF_ISO
162: #define PF_ECMA AF_ECMA
163: #define PF_DATAKIT AF_DATAKIT
164: #define PF_CCITT AF_CCITT
165: #define PF_SNA AF_SNA
166: #define PF_DECnet AF_DECnet
167: #define PF_DLI AF_DLI
168: #define PF_LAT AF_LAT
169: #define PF_HYLINK AF_HYLINK
170: #define PF_APPLETALK AF_APPLETALK
171: #define PF_ROUTE AF_ROUTE
172: #define PF_LINK AF_LINK
173: #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
1.8 mycroft 174: #define PF_COIP AF_COIP
175: #define PF_CNT AF_CNT
176: #define PF_SIP AF_SIP
177: #define PF_IPX AF_IPX /* same format as AF_NS */
178: #define PF_RTIP pseudo_AF_FTIP /* same format as AF_INET */
179: #define PF_PIP pseudo_AF_PIP
1.17 ! chuck 180: #define PF_NATM AF_NATM
1.1 cgd 181:
182: #define PF_MAX AF_MAX
183:
184: /*
1.8 mycroft 185: * Definitions for network related sysctl, CTL_NET.
186: *
187: * Second level is protocol family.
188: * Third level is protocol number.
189: *
190: * Further levels are defined by the individual families below.
191: */
192: #define NET_MAXID AF_MAX
193:
194: #define CTL_NET_NAMES { \
195: { 0, 0 }, \
196: { "unix", CTLTYPE_NODE }, \
197: { "inet", CTLTYPE_NODE }, \
198: { "implink", CTLTYPE_NODE }, \
199: { "pup", CTLTYPE_NODE }, \
200: { "chaos", CTLTYPE_NODE }, \
201: { "xerox_ns", CTLTYPE_NODE }, \
202: { "iso", CTLTYPE_NODE }, \
203: { "emca", CTLTYPE_NODE }, \
204: { "datakit", CTLTYPE_NODE }, \
205: { "ccitt", CTLTYPE_NODE }, \
206: { "ibm_sna", CTLTYPE_NODE }, \
207: { "decnet", CTLTYPE_NODE }, \
208: { "dec_dli", CTLTYPE_NODE }, \
209: { "lat", CTLTYPE_NODE }, \
210: { "hylink", CTLTYPE_NODE }, \
211: { "appletalk", CTLTYPE_NODE }, \
212: { "route", CTLTYPE_NODE }, \
213: { "link_layer", CTLTYPE_NODE }, \
214: { "xtp", CTLTYPE_NODE }, \
215: { "coip", CTLTYPE_NODE }, \
216: { "cnt", CTLTYPE_NODE }, \
217: { "rtip", CTLTYPE_NODE }, \
218: { "ipx", CTLTYPE_NODE }, \
219: { "sip", CTLTYPE_NODE }, \
220: { "pip", CTLTYPE_NODE }, \
1.17 ! chuck 221: { "natm", CTLTYPE_NODE }, \
1.8 mycroft 222: }
223:
224: /*
225: * PF_ROUTE - Routing table
226: *
227: * Three additional levels are defined:
228: * Fourth: address family, 0 is wildcard
229: * Fifth: type of info, defined below
230: * Sixth: flag(s) to mask with for NET_RT_FLAGS
231: */
232: #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
233: #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
234: #define NET_RT_IFLIST 3 /* survey interface list */
235: #define NET_RT_MAXID 4
236:
237: #define CTL_NET_RT_NAMES { \
238: { 0, 0 }, \
239: { "dump", CTLTYPE_STRUCT }, \
240: { "flags", CTLTYPE_STRUCT }, \
241: { "iflist", CTLTYPE_STRUCT }, \
242: }
243:
244: /*
1.13 mycroft 245: * Maximum queue length specifiable by listen(2).
1.1 cgd 246: */
1.16 neil 247:
1.13 mycroft 248: #define SOMAXCONN 128
1.16 neil 249:
1.1 cgd 250: /*
251: * Message header for recvmsg and sendmsg calls.
252: * Used value-result for recvmsg, value only for sendmsg.
253: */
254: struct msghdr {
255: caddr_t msg_name; /* optional address */
256: u_int msg_namelen; /* size of address */
257: struct iovec *msg_iov; /* scatter/gather array */
258: u_int msg_iovlen; /* # elements in msg_iov */
259: caddr_t msg_control; /* ancillary data, see below */
260: u_int msg_controllen; /* ancillary data buffer len */
261: int msg_flags; /* flags on received message */
262: };
263:
264: #define MSG_OOB 0x1 /* process out-of-band data */
265: #define MSG_PEEK 0x2 /* peek at incoming message */
266: #define MSG_DONTROUTE 0x4 /* send without using routing tables */
267: #define MSG_EOR 0x8 /* data completes record */
268: #define MSG_TRUNC 0x10 /* data discarded before delivery */
269: #define MSG_CTRUNC 0x20 /* control data lost before delivery */
270: #define MSG_WAITALL 0x40 /* wait for full request or error */
1.8 mycroft 271: #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
1.1 cgd 272:
273: /*
274: * Header for ancillary data objects in msg_control buffer.
275: * Used for additional information with/about a datagram
276: * not expressible by flags. The format is a sequence
277: * of message elements headed by cmsghdr structures.
278: */
279: struct cmsghdr {
280: u_int cmsg_len; /* data byte count, including hdr */
281: int cmsg_level; /* originating protocol */
282: int cmsg_type; /* protocol-specific type */
283: /* followed by u_char cmsg_data[]; */
284: };
285:
1.8 mycroft 286: /* given pointer to struct cmsghdr, return pointer to data */
1.1 cgd 287: #define CMSG_DATA(cmsg) ((u_char *)((cmsg) + 1))
288:
1.8 mycroft 289: /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
1.1 cgd 290: #define CMSG_NXTHDR(mhdr, cmsg) \
291: (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
292: (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
293: (struct cmsghdr *)NULL : \
294: (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
295:
296: #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
297:
298: /* "Socket"-level control message types: */
299: #define SCM_RIGHTS 0x01 /* access rights (array of int) */
300:
301: /*
302: * 4.3 compat sockaddr, move to compat file later
303: */
304: struct osockaddr {
305: u_short sa_family; /* address family */
306: char sa_data[14]; /* up to 14 bytes of direct address */
307: };
308:
309: /*
310: * 4.3-compat message header (move to compat file later).
311: */
312: struct omsghdr {
313: caddr_t msg_name; /* optional address */
314: int msg_namelen; /* size of address */
315: struct iovec *msg_iov; /* scatter/gather array */
316: int msg_iovlen; /* # elements in msg_iov */
317: caddr_t msg_accrights; /* access rights sent/received */
318: int msg_accrightslen;
319: };
320:
1.12 briggs 321: #ifndef _KERNEL
1.1 cgd 322:
323: #include <sys/cdefs.h>
324:
325: __BEGIN_DECLS
326: int accept __P((int, struct sockaddr *, int *));
327: int bind __P((int, const struct sockaddr *, int));
328: int connect __P((int, const struct sockaddr *, int));
329: int getpeername __P((int, struct sockaddr *, int *));
330: int getsockname __P((int, struct sockaddr *, int *));
331: int getsockopt __P((int, int, int, void *, int *));
332: int listen __P((int, int));
1.8 mycroft 333: ssize_t recv __P((int, void *, size_t, int));
334: ssize_t recvfrom __P((int, void *, size_t, int, struct sockaddr *, int *));
335: ssize_t recvmsg __P((int, struct msghdr *, int));
336: ssize_t send __P((int, const void *, size_t, int));
337: ssize_t sendto __P((int, const void *,
338: size_t, int, const struct sockaddr *, int));
339: ssize_t sendmsg __P((int, const struct msghdr *, int));
1.1 cgd 340: int setsockopt __P((int, int, int, const void *, int));
341: int shutdown __P((int, int));
342: int socket __P((int, int, int));
343: int socketpair __P((int, int, int, int *));
344: __END_DECLS
1.14 christos 345: #else
346: # if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_LINUX) || \
347: defined(COMPAT_HPUX) || defined(COMPAT_FREEBSD)
348: # define COMPAT_OLDSOCK
349: # define MSG_COMPAT 0x8000
350: # endif
351: #endif /* !_KERNEL */
1.1 cgd 352:
1.2 mycroft 353: #endif /* !_SYS_SOCKET_H_ */
CVSweb <webmaster@jp.NetBSD.org>