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