Fri Jan 20 01:17:01 2012 UTC ()
CMSG_ALIGN is only for the kernel.


(joerg)
diff -r1.102 -r1.103 src/sys/sys/socket.h

cvs diff -r1.102 -r1.103 src/sys/sys/socket.h (switch to unified diff)

--- src/sys/sys/socket.h 2012/01/20 00:25:29 1.102
+++ src/sys/sys/socket.h 2012/01/20 01:17:01 1.103
@@ -1,642 +1,641 @@ @@ -1,642 +1,641 @@
1/* $NetBSD: socket.h,v 1.102 2012/01/20 00:25:29 joerg Exp $ */ 1/* $NetBSD: socket.h,v 1.103 2012/01/20 01:17:01 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors 15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 33 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
34 * The Regents of the University of California. All rights reserved. 34 * The Regents of the University of California. All rights reserved.
35 * 35 *
36 * Redistribution and use in source and binary forms, with or without 36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions 37 * modification, are permitted provided that the following conditions
38 * are met: 38 * are met:
39 * 1. Redistributions of source code must retain the above copyright 39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer. 40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright 41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the 42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution. 43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors 44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software 45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission. 46 * without specific prior written permission.
47 * 47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 * 59 *
60 * @(#)socket.h 8.6 (Berkeley) 5/3/95 60 * @(#)socket.h 8.6 (Berkeley) 5/3/95
61 */ 61 */
62 62
63#ifndef _SYS_SOCKET_H_ 63#ifndef _SYS_SOCKET_H_
64#define _SYS_SOCKET_H_ 64#define _SYS_SOCKET_H_
65 65
66#include <sys/featuretest.h> 66#include <sys/featuretest.h>
67 67
68/* 68/*
69 * Definitions related to sockets: types, address families, options. 69 * Definitions related to sockets: types, address families, options.
70 */ 70 */
71 71
72/* 72/*
73 * Data types. 73 * Data types.
74 */ 74 */
75#include <sys/ansi.h> 75#include <sys/ansi.h>
76 76
77#ifndef sa_family_t 77#ifndef sa_family_t
78typedef __sa_family_t sa_family_t; 78typedef __sa_family_t sa_family_t;
79#define sa_family_t __sa_family_t 79#define sa_family_t __sa_family_t
80#endif 80#endif
81 81
82#ifndef socklen_t 82#ifndef socklen_t
83typedef __socklen_t socklen_t; 83typedef __socklen_t socklen_t;
84#define socklen_t __socklen_t 84#define socklen_t __socklen_t
85#endif 85#endif
86 86
87#include <machine/ansi.h> 87#include <machine/ansi.h>
88 88
89#ifdef _BSD_SIZE_T_ 89#ifdef _BSD_SIZE_T_
90typedef _BSD_SIZE_T_ size_t; 90typedef _BSD_SIZE_T_ size_t;
91#undef _BSD_SIZE_T_ 91#undef _BSD_SIZE_T_
92#endif 92#endif
93 93
94#ifdef _BSD_SSIZE_T_ 94#ifdef _BSD_SSIZE_T_
95typedef _BSD_SSIZE_T_ ssize_t; 95typedef _BSD_SSIZE_T_ ssize_t;
96#undef _BSD_SSIZE_T_ 96#undef _BSD_SSIZE_T_
97#endif 97#endif
98 98
99#include <sys/uio.h> 99#include <sys/uio.h>
100#include <sys/sigtypes.h> 100#include <sys/sigtypes.h>
101 101
102/* 102/*
103 * Socket types. 103 * Socket types.
104 */ 104 */
105#define SOCK_STREAM 1 /* stream socket */ 105#define SOCK_STREAM 1 /* stream socket */
106#define SOCK_DGRAM 2 /* datagram socket */ 106#define SOCK_DGRAM 2 /* datagram socket */
107#define SOCK_RAW 3 /* raw-protocol interface */ 107#define SOCK_RAW 3 /* raw-protocol interface */
108#define SOCK_RDM 4 /* reliably-delivered message */ 108#define SOCK_RDM 4 /* reliably-delivered message */
109#define SOCK_SEQPACKET 5 /* sequenced packet stream */ 109#define SOCK_SEQPACKET 5 /* sequenced packet stream */
110 110
111#define SOCK_CLOEXEC 0x10000000 /* set close on exec on socket */ 111#define SOCK_CLOEXEC 0x10000000 /* set close on exec on socket */
112#define SOCK_NONBLOCK 0x20000000 /* set non blocking i/o socket */ 112#define SOCK_NONBLOCK 0x20000000 /* set non blocking i/o socket */
113#define SOCK_FLAGS_MASK 0xf0000000 /* flags mask */ 113#define SOCK_FLAGS_MASK 0xf0000000 /* flags mask */
114 114
115/* 115/*
116 * Option flags per-socket. 116 * Option flags per-socket.
117 */ 117 */
118#define SO_DEBUG 0x0001 /* turn on debugging info recording */ 118#define SO_DEBUG 0x0001 /* turn on debugging info recording */
119#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 119#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
120#define SO_REUSEADDR 0x0004 /* allow local address reuse */ 120#define SO_REUSEADDR 0x0004 /* allow local address reuse */
121#define SO_KEEPALIVE 0x0008 /* keep connections alive */ 121#define SO_KEEPALIVE 0x0008 /* keep connections alive */
122#define SO_DONTROUTE 0x0010 /* just use interface addresses */ 122#define SO_DONTROUTE 0x0010 /* just use interface addresses */
123#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ 123#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
124#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 124#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
125#define SO_LINGER 0x0080 /* linger on close if data present */ 125#define SO_LINGER 0x0080 /* linger on close if data present */
126#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ 126#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
127#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ 127#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
128/* SO_OTIMESTAMP 0x0400 */ 128/* SO_OTIMESTAMP 0x0400 */
129#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ 129#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
130#define SO_TIMESTAMP 0x2000 /* timestamp received dgram traffic */ 130#define SO_TIMESTAMP 0x2000 /* timestamp received dgram traffic */
131 131
132 132
133/* 133/*
134 * Additional options, not kept in so_options. 134 * Additional options, not kept in so_options.
135 */ 135 */
136#define SO_SNDBUF 0x1001 /* send buffer size */ 136#define SO_SNDBUF 0x1001 /* send buffer size */
137#define SO_RCVBUF 0x1002 /* receive buffer size */ 137#define SO_RCVBUF 0x1002 /* receive buffer size */
138#define SO_SNDLOWAT 0x1003 /* send low-water mark */ 138#define SO_SNDLOWAT 0x1003 /* send low-water mark */
139#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ 139#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
140/* SO_OSNDTIMEO 0x1005 */ 140/* SO_OSNDTIMEO 0x1005 */
141/* SO_ORCVTIMEO 0x1006 */ 141/* SO_ORCVTIMEO 0x1006 */
142#define SO_ERROR 0x1007 /* get error status and clear */ 142#define SO_ERROR 0x1007 /* get error status and clear */
143#define SO_TYPE 0x1008 /* get socket type */ 143#define SO_TYPE 0x1008 /* get socket type */
144#define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */ 144#define SO_OVERFLOWED 0x1009 /* datagrams: return packets dropped */
145 145
146#define SO_NOHEADER 0x100a /* user supplies no header to kernel; 146#define SO_NOHEADER 0x100a /* user supplies no header to kernel;
147 * kernel removes header and supplies 147 * kernel removes header and supplies
148 * payload 148 * payload
149 */ 149 */
150#define SO_SNDTIMEO 0x100b /* send timeout */ 150#define SO_SNDTIMEO 0x100b /* send timeout */
151#define SO_RCVTIMEO 0x100c /* receive timeout */ 151#define SO_RCVTIMEO 0x100c /* receive timeout */
152/* 152/*
153 * Structure used for manipulating linger option. 153 * Structure used for manipulating linger option.
154 */ 154 */
155struct linger { 155struct linger {
156 int l_onoff; /* option on/off */ 156 int l_onoff; /* option on/off */
157 int l_linger; /* linger time in seconds */ 157 int l_linger; /* linger time in seconds */
158}; 158};
159 159
160struct accept_filter_arg { 160struct accept_filter_arg {
161 char af_name[16]; 161 char af_name[16];
162 char af_arg[256-16]; 162 char af_arg[256-16];
163}; 163};
164 164
165/* 165/*
166 * Level number for (get/set)sockopt() to apply to socket itself. 166 * Level number for (get/set)sockopt() to apply to socket itself.
167 */ 167 */
168#define SOL_SOCKET 0xffff /* options for socket level */ 168#define SOL_SOCKET 0xffff /* options for socket level */
169 169
170/* 170/*
171 * Address families. 171 * Address families.
172 */ 172 */
173#define AF_UNSPEC 0 /* unspecified */ 173#define AF_UNSPEC 0 /* unspecified */
174#define AF_LOCAL 1 /* local to host */ 174#define AF_LOCAL 1 /* local to host */
175#define AF_UNIX AF_LOCAL /* backward compatibility */ 175#define AF_UNIX AF_LOCAL /* backward compatibility */
176#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ 176#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
177#define AF_IMPLINK 3 /* arpanet imp addresses */ 177#define AF_IMPLINK 3 /* arpanet imp addresses */
178#define AF_PUP 4 /* pup protocols: e.g. BSP */ 178#define AF_PUP 4 /* pup protocols: e.g. BSP */
179#define AF_CHAOS 5 /* mit CHAOS protocols */ 179#define AF_CHAOS 5 /* mit CHAOS protocols */
180#define AF_NS 6 /* XEROX NS protocols */ 180#define AF_NS 6 /* XEROX NS protocols */
181#define AF_ISO 7 /* ISO protocols */ 181#define AF_ISO 7 /* ISO protocols */
182#define AF_OSI AF_ISO 182#define AF_OSI AF_ISO
183#define AF_ECMA 8 /* european computer manufacturers */ 183#define AF_ECMA 8 /* european computer manufacturers */
184#define AF_DATAKIT 9 /* datakit protocols */ 184#define AF_DATAKIT 9 /* datakit protocols */
185#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ 185#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
186#define AF_SNA 11 /* IBM SNA */ 186#define AF_SNA 11 /* IBM SNA */
187#define AF_DECnet 12 /* DECnet */ 187#define AF_DECnet 12 /* DECnet */
188#define AF_DLI 13 /* DEC Direct data link interface */ 188#define AF_DLI 13 /* DEC Direct data link interface */
189#define AF_LAT 14 /* LAT */ 189#define AF_LAT 14 /* LAT */
190#define AF_HYLINK 15 /* NSC Hyperchannel */ 190#define AF_HYLINK 15 /* NSC Hyperchannel */
191#define AF_APPLETALK 16 /* Apple Talk */ 191#define AF_APPLETALK 16 /* Apple Talk */
192#define AF_OROUTE 17 /* Internal Routing Protocol */ 192#define AF_OROUTE 17 /* Internal Routing Protocol */
193#define AF_LINK 18 /* Link layer interface */ 193#define AF_LINK 18 /* Link layer interface */
194#if defined(_NETBSD_SOURCE) 194#if defined(_NETBSD_SOURCE)
195#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ 195#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
196#endif 196#endif
197#define AF_COIP 20 /* connection-oriented IP, aka ST II */ 197#define AF_COIP 20 /* connection-oriented IP, aka ST II */
198#define AF_CNT 21 /* Computer Network Technology */ 198#define AF_CNT 21 /* Computer Network Technology */
199#if defined(_NETBSD_SOURCE) 199#if defined(_NETBSD_SOURCE)
200#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ 200#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
201#endif 201#endif
202#define AF_IPX 23 /* Novell Internet Protocol */ 202#define AF_IPX 23 /* Novell Internet Protocol */
203#define AF_INET6 24 /* IP version 6 */ 203#define AF_INET6 24 /* IP version 6 */
204#if defined(_NETBSD_SOURCE) 204#if defined(_NETBSD_SOURCE)
205#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ 205#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
206#endif 206#endif
207#define AF_ISDN 26 /* Integrated Services Digital Network*/ 207#define AF_ISDN 26 /* Integrated Services Digital Network*/
208#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ 208#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
209#define AF_NATM 27 /* native ATM access */ 209#define AF_NATM 27 /* native ATM access */
210#define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */ 210#define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
211#if defined(_NETBSD_SOURCE) 211#if defined(_NETBSD_SOURCE)
212#define pseudo_AF_KEY 29 /* Internal key management protocol */ 212#define pseudo_AF_KEY 29 /* Internal key management protocol */
213#define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs 213#define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs
214 in interface output routine */ 214 in interface output routine */
215#endif 215#endif
216#define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */ 216#define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
217#define AF_IEEE80211 32 /* IEEE80211 */ 217#define AF_IEEE80211 32 /* IEEE80211 */
218#define AF_MPLS 33 /* MultiProtocol Label Switching */ 218#define AF_MPLS 33 /* MultiProtocol Label Switching */
219#define AF_ROUTE 34 /* Internal Routing Protocol */ 219#define AF_ROUTE 34 /* Internal Routing Protocol */
220#define AF_MAX 35 220#define AF_MAX 35
221 221
222/* 222/*
223 * Structure used by kernel to store most 223 * Structure used by kernel to store most
224 * addresses. 224 * addresses.
225 */ 225 */
226struct sockaddr { 226struct sockaddr {
227 __uint8_t sa_len; /* total length */ 227 __uint8_t sa_len; /* total length */
228 sa_family_t sa_family; /* address family */ 228 sa_family_t sa_family; /* address family */
229 char sa_data[14]; /* actually longer; address value */ 229 char sa_data[14]; /* actually longer; address value */
230}; 230};
231 231
232#if defined(_KERNEL) 232#if defined(_KERNEL)
233/* 233/*
234 * Structure used by kernel to pass protocol 234 * Structure used by kernel to pass protocol
235 * information in raw sockets. 235 * information in raw sockets.
236 */ 236 */
237struct sockproto { 237struct sockproto {
238 u_short sp_family; /* address family */ 238 u_short sp_family; /* address family */
239 u_short sp_protocol; /* protocol */ 239 u_short sp_protocol; /* protocol */
240}; 240};
241#endif /* _KERNEL */ 241#endif /* _KERNEL */
242 242
243#if 1 243#if 1
244/* 244/*
245 * RFC 2553: protocol-independent placeholder for socket addresses 245 * RFC 2553: protocol-independent placeholder for socket addresses
246 */ 246 */
247#define _SS_MAXSIZE 128 247#define _SS_MAXSIZE 128
248#define _SS_ALIGNSIZE (sizeof(__int64_t)) 248#define _SS_ALIGNSIZE (sizeof(__int64_t))
249#define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2) 249#define _SS_PAD1SIZE (_SS_ALIGNSIZE - 2)
250#define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - \ 250#define _SS_PAD2SIZE (_SS_MAXSIZE - 2 - \
251 _SS_PAD1SIZE - _SS_ALIGNSIZE) 251 _SS_PAD1SIZE - _SS_ALIGNSIZE)
252 252
253#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 253#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
254struct sockaddr_storage { 254struct sockaddr_storage {
255 __uint8_t ss_len; /* address length */ 255 __uint8_t ss_len; /* address length */
256 sa_family_t ss_family; /* address family */ 256 sa_family_t ss_family; /* address family */
257 char __ss_pad1[_SS_PAD1SIZE]; 257 char __ss_pad1[_SS_PAD1SIZE];
258 __int64_t __ss_align;/* force desired structure storage alignment */ 258 __int64_t __ss_align;/* force desired structure storage alignment */
259 char __ss_pad2[_SS_PAD2SIZE]; 259 char __ss_pad2[_SS_PAD2SIZE];
260}; 260};
261#define sstosa(__ss) ((struct sockaddr *)(__ss)) 261#define sstosa(__ss) ((struct sockaddr *)(__ss))
262#define sstocsa(__ss) ((const struct sockaddr *)(__ss)) 262#define sstocsa(__ss) ((const struct sockaddr *)(__ss))
263#endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */ 263#endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
264#endif /* 1 */ 264#endif /* 1 */
265 265
266/* 266/*
267 * Protocol families, same as address families for now. 267 * Protocol families, same as address families for now.
268 */ 268 */
269#define PF_UNSPEC AF_UNSPEC 269#define PF_UNSPEC AF_UNSPEC
270#define PF_LOCAL AF_LOCAL 270#define PF_LOCAL AF_LOCAL
271#define PF_UNIX PF_LOCAL /* backward compatibility */ 271#define PF_UNIX PF_LOCAL /* backward compatibility */
272#define PF_INET AF_INET 272#define PF_INET AF_INET
273#define PF_IMPLINK AF_IMPLINK 273#define PF_IMPLINK AF_IMPLINK
274#define PF_PUP AF_PUP 274#define PF_PUP AF_PUP
275#define PF_CHAOS AF_CHAOS 275#define PF_CHAOS AF_CHAOS
276#define PF_NS AF_NS 276#define PF_NS AF_NS
277#define PF_ISO AF_ISO 277#define PF_ISO AF_ISO
278#define PF_OSI AF_ISO 278#define PF_OSI AF_ISO
279#define PF_ECMA AF_ECMA 279#define PF_ECMA AF_ECMA
280#define PF_DATAKIT AF_DATAKIT 280#define PF_DATAKIT AF_DATAKIT
281#define PF_CCITT AF_CCITT 281#define PF_CCITT AF_CCITT
282#define PF_SNA AF_SNA 282#define PF_SNA AF_SNA
283#define PF_DECnet AF_DECnet 283#define PF_DECnet AF_DECnet
284#define PF_DLI AF_DLI 284#define PF_DLI AF_DLI
285#define PF_LAT AF_LAT 285#define PF_LAT AF_LAT
286#define PF_HYLINK AF_HYLINK 286#define PF_HYLINK AF_HYLINK
287#define PF_APPLETALK AF_APPLETALK 287#define PF_APPLETALK AF_APPLETALK
288#define PF_OROUTE AF_OROUTE 288#define PF_OROUTE AF_OROUTE
289#define PF_LINK AF_LINK 289#define PF_LINK AF_LINK
290#if defined(_NETBSD_SOURCE) 290#if defined(_NETBSD_SOURCE)
291#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ 291#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
292#endif 292#endif
293#define PF_COIP AF_COIP 293#define PF_COIP AF_COIP
294#define PF_CNT AF_CNT 294#define PF_CNT AF_CNT
295#define PF_INET6 AF_INET6 295#define PF_INET6 AF_INET6
296#define PF_IPX AF_IPX /* same format as AF_NS */ 296#define PF_IPX AF_IPX /* same format as AF_NS */
297#if defined(_NETBSD_SOURCE) 297#if defined(_NETBSD_SOURCE)
298#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ 298#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
299#define PF_PIP pseudo_AF_PIP 299#define PF_PIP pseudo_AF_PIP
300#endif 300#endif
301#define PF_ISDN AF_ISDN /* same as E164 */ 301#define PF_ISDN AF_ISDN /* same as E164 */
302#define PF_E164 AF_E164 302#define PF_E164 AF_E164
303#define PF_NATM AF_NATM 303#define PF_NATM AF_NATM
304#define PF_ARP AF_ARP 304#define PF_ARP AF_ARP
305#if defined(_NETBSD_SOURCE) 305#if defined(_NETBSD_SOURCE)
306#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */ 306#define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
307#endif 307#endif
308#define PF_BLUETOOTH AF_BLUETOOTH 308#define PF_BLUETOOTH AF_BLUETOOTH
309#define PF_MPLS AF_MPLS 309#define PF_MPLS AF_MPLS
310#define PF_ROUTE AF_ROUTE 310#define PF_ROUTE AF_ROUTE
311 311
312#define PF_MAX AF_MAX 312#define PF_MAX AF_MAX
313 313
314#if defined(_NETBSD_SOURCE) 314#if defined(_NETBSD_SOURCE)
315 315
316#ifndef gid_t 316#ifndef gid_t
317typedef __gid_t gid_t; /* group id */ 317typedef __gid_t gid_t; /* group id */
318#define gid_t __gid_t 318#define gid_t __gid_t
319#endif 319#endif
320 320
321#ifndef uid_t 321#ifndef uid_t
322typedef __uid_t uid_t; /* user id */ 322typedef __uid_t uid_t; /* user id */
323#define uid_t __uid_t 323#define uid_t __uid_t
324#endif 324#endif
325 325
326/* 326/*
327 * Socket credentials. 327 * Socket credentials.
328 */ 328 */
329struct sockcred { 329struct sockcred {
330 uid_t sc_uid; /* real user id */ 330 uid_t sc_uid; /* real user id */
331 uid_t sc_euid; /* effective user id */ 331 uid_t sc_euid; /* effective user id */
332 gid_t sc_gid; /* real group id */ 332 gid_t sc_gid; /* real group id */
333 gid_t sc_egid; /* effective group id */ 333 gid_t sc_egid; /* effective group id */
334 int sc_ngroups; /* number of supplemental groups */ 334 int sc_ngroups; /* number of supplemental groups */
335 gid_t sc_groups[1]; /* variable length */ 335 gid_t sc_groups[1]; /* variable length */
336}; 336};
337 337
338/* 338/*
339 * Compute size of a sockcred structure with groups. 339 * Compute size of a sockcred structure with groups.
340 */ 340 */
341#define SOCKCREDSIZE(ngrps) \ 341#define SOCKCREDSIZE(ngrps) \
342 (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1))) 342 (sizeof(struct sockcred) + (sizeof(gid_t) * ((ngrps) - 1)))
343#endif /* _NETBSD_SOURCE */ 343#endif /* _NETBSD_SOURCE */
344 344
345 345
346#if defined(_NETBSD_SOURCE) 346#if defined(_NETBSD_SOURCE)
347/* 347/*
348 * Definitions for network related sysctl, CTL_NET. 348 * Definitions for network related sysctl, CTL_NET.
349 * 349 *
350 * Second level is protocol family. 350 * Second level is protocol family.
351 * Third level is protocol number. 351 * Third level is protocol number.
352 * 352 *
353 * Further levels are defined by the individual families below. 353 * Further levels are defined by the individual families below.
354 */ 354 */
355#define NET_MAXID AF_MAX 355#define NET_MAXID AF_MAX
356 356
357#define CTL_NET_NAMES { \ 357#define CTL_NET_NAMES { \
358 { 0, 0 }, \ 358 { 0, 0 }, \
359 { "local", CTLTYPE_NODE }, \ 359 { "local", CTLTYPE_NODE }, \
360 { "inet", CTLTYPE_NODE }, \ 360 { "inet", CTLTYPE_NODE }, \
361 { "implink", CTLTYPE_NODE }, \ 361 { "implink", CTLTYPE_NODE }, \
362 { "pup", CTLTYPE_NODE }, \ 362 { "pup", CTLTYPE_NODE }, \
363 { "chaos", CTLTYPE_NODE }, \ 363 { "chaos", CTLTYPE_NODE }, \
364 { "xerox_ns", CTLTYPE_NODE }, \ 364 { "xerox_ns", CTLTYPE_NODE }, \
365 { "iso", CTLTYPE_NODE }, \ 365 { "iso", CTLTYPE_NODE }, \
366 { "emca", CTLTYPE_NODE }, \ 366 { "emca", CTLTYPE_NODE }, \
367 { "datakit", CTLTYPE_NODE }, \ 367 { "datakit", CTLTYPE_NODE }, \
368 { "ccitt", CTLTYPE_NODE }, \ 368 { "ccitt", CTLTYPE_NODE }, \
369 { "ibm_sna", CTLTYPE_NODE }, \ 369 { "ibm_sna", CTLTYPE_NODE }, \
370 { "decnet", CTLTYPE_NODE }, \ 370 { "decnet", CTLTYPE_NODE }, \
371 { "dec_dli", CTLTYPE_NODE }, \ 371 { "dec_dli", CTLTYPE_NODE }, \
372 { "lat", CTLTYPE_NODE }, \ 372 { "lat", CTLTYPE_NODE }, \
373 { "hylink", CTLTYPE_NODE }, \ 373 { "hylink", CTLTYPE_NODE }, \
374 { "appletalk", CTLTYPE_NODE }, \ 374 { "appletalk", CTLTYPE_NODE }, \
375 { "oroute", CTLTYPE_NODE }, \ 375 { "oroute", CTLTYPE_NODE }, \
376 { "link_layer", CTLTYPE_NODE }, \ 376 { "link_layer", CTLTYPE_NODE }, \
377 { "xtp", CTLTYPE_NODE }, \ 377 { "xtp", CTLTYPE_NODE }, \
378 { "coip", CTLTYPE_NODE }, \ 378 { "coip", CTLTYPE_NODE }, \
379 { "cnt", CTLTYPE_NODE }, \ 379 { "cnt", CTLTYPE_NODE }, \
380 { "rtip", CTLTYPE_NODE }, \ 380 { "rtip", CTLTYPE_NODE }, \
381 { "ipx", CTLTYPE_NODE }, \ 381 { "ipx", CTLTYPE_NODE }, \
382 { "inet6", CTLTYPE_NODE }, \ 382 { "inet6", CTLTYPE_NODE }, \
383 { "pip", CTLTYPE_NODE }, \ 383 { "pip", CTLTYPE_NODE }, \
384 { "isdn", CTLTYPE_NODE }, \ 384 { "isdn", CTLTYPE_NODE }, \
385 { "natm", CTLTYPE_NODE }, \ 385 { "natm", CTLTYPE_NODE }, \
386 { "arp", CTLTYPE_NODE }, \ 386 { "arp", CTLTYPE_NODE }, \
387 { "key", CTLTYPE_NODE }, \ 387 { "key", CTLTYPE_NODE }, \
388 { "ieee80211", CTLTYPE_NODE }, \ 388 { "ieee80211", CTLTYPE_NODE }, \
389 { "mlps", CTLTYPE_NODE }, \ 389 { "mlps", CTLTYPE_NODE }, \
390 { "route", CTLTYPE_NODE }, \ 390 { "route", CTLTYPE_NODE }, \
391} 391}
392 392
393struct kinfo_pcb { 393struct kinfo_pcb {
394 __uint64_t ki_pcbaddr; /* PTR: pcb addr */ 394 __uint64_t ki_pcbaddr; /* PTR: pcb addr */
395 __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */ 395 __uint64_t ki_ppcbaddr; /* PTR: ppcb addr */
396 __uint64_t ki_sockaddr; /* PTR: socket addr */ 396 __uint64_t ki_sockaddr; /* PTR: socket addr */
397 397
398 __uint32_t ki_family; /* INT: protocol family */ 398 __uint32_t ki_family; /* INT: protocol family */
399 __uint32_t ki_type; /* INT: socket type */ 399 __uint32_t ki_type; /* INT: socket type */
400 __uint32_t ki_protocol; /* INT: protocol */ 400 __uint32_t ki_protocol; /* INT: protocol */
401 __uint32_t ki_pflags; /* INT: generic protocol flags */ 401 __uint32_t ki_pflags; /* INT: generic protocol flags */
402 402
403 __uint32_t ki_sostate; /* INT: socket state */ 403 __uint32_t ki_sostate; /* INT: socket state */
404 __uint32_t ki_prstate; /* INT: protocol state */ 404 __uint32_t ki_prstate; /* INT: protocol state */
405 __int32_t ki_tstate; /* INT: tcp state */ 405 __int32_t ki_tstate; /* INT: tcp state */
406 __uint32_t ki_tflags; /* INT: tcp flags */ 406 __uint32_t ki_tflags; /* INT: tcp flags */
407 407
408 __uint64_t ki_rcvq; /* U_LONG: receive queue len */ 408 __uint64_t ki_rcvq; /* U_LONG: receive queue len */
409 __uint64_t ki_sndq; /* U_LONG: send queue len */ 409 __uint64_t ki_sndq; /* U_LONG: send queue len */
410 410
411 union { 411 union {
412 struct sockaddr _kis_src; /* STRUCT: local address */ 412 struct sockaddr _kis_src; /* STRUCT: local address */
413 char _kis_pad[256 + 8]; /* pad to max addr length */ 413 char _kis_pad[256 + 8]; /* pad to max addr length */
414 } ki_s; 414 } ki_s;
415 union { 415 union {
416 struct sockaddr _kid_dst; /* STRUCT: remote address */ 416 struct sockaddr _kid_dst; /* STRUCT: remote address */
417 char _kid_pad[256 + 8]; /* pad to max addr length */ 417 char _kid_pad[256 + 8]; /* pad to max addr length */
418 } ki_d; 418 } ki_d;
419 419
420 __uint64_t ki_inode; /* INO_T: fake inode number */ 420 __uint64_t ki_inode; /* INO_T: fake inode number */
421 __uint64_t ki_vnode; /* PTR: if associated with file */ 421 __uint64_t ki_vnode; /* PTR: if associated with file */
422 __uint64_t ki_conn; /* PTR: control block of peer */ 422 __uint64_t ki_conn; /* PTR: control block of peer */
423 __uint64_t ki_refs; /* PTR: referencing socket */ 423 __uint64_t ki_refs; /* PTR: referencing socket */
424 __uint64_t ki_nextref; /* PTR: link in refs list */ 424 __uint64_t ki_nextref; /* PTR: link in refs list */
425}; 425};
426 426
427#define ki_src ki_s._kis_src 427#define ki_src ki_s._kis_src
428#define ki_dst ki_d._kid_dst 428#define ki_dst ki_d._kid_dst
429 429
430#define PCB_SLOP 20 430#define PCB_SLOP 20
431#define PCB_ALL 0 431#define PCB_ALL 0
432 432
433#endif /* _NETBSD_SOURCE */ 433#endif /* _NETBSD_SOURCE */
434 434
435#if defined(_NETBSD_SOURCE) 435#if defined(_NETBSD_SOURCE)
436/* 436/*
437 * PF_ROUTE - Routing table 437 * PF_ROUTE - Routing table
438 * 438 *
439 * Three additional levels are defined: 439 * Three additional levels are defined:
440 * Fourth: address family, 0 is wildcard 440 * Fourth: address family, 0 is wildcard
441 * Fifth: type of info, defined below 441 * Fifth: type of info, defined below
442 * Sixth: flag(s) to mask with for NET_RT_FLAGS 442 * Sixth: flag(s) to mask with for NET_RT_FLAGS
443 */ 443 */
444#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ 444#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
445#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ 445#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
446#define NET_RT_OOIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */ 446#define NET_RT_OOIFLIST 3 /* old NET_RT_IFLIST (pre 1.5) */
447#define NET_RT_OIFLIST 4 /* survey interface list */ 447#define NET_RT_OIFLIST 4 /* survey interface list */
448#define NET_RT_IFLIST 5 448#define NET_RT_IFLIST 5
449#define NET_RT_MAXID 6 449#define NET_RT_MAXID 6
450 450
451#define CTL_NET_RT_NAMES { \ 451#define CTL_NET_RT_NAMES { \
452 { 0, 0 }, \ 452 { 0, 0 }, \
453 { "dump", CTLTYPE_STRUCT }, \ 453 { "dump", CTLTYPE_STRUCT }, \
454 { "flags", CTLTYPE_STRUCT }, \ 454 { "flags", CTLTYPE_STRUCT }, \
455 { 0, 0 }, \ 455 { 0, 0 }, \
456 { 0, 0 }, \ 456 { 0, 0 }, \
457 { "iflist", CTLTYPE_STRUCT }, \ 457 { "iflist", CTLTYPE_STRUCT }, \
458} 458}
459#endif /* _NETBSD_SOURCE */ 459#endif /* _NETBSD_SOURCE */
460 460
461/* 461/*
462 * Maximum queue length specifiable by listen(2). 462 * Maximum queue length specifiable by listen(2).
463 */ 463 */
464#ifndef SOMAXCONN 464#ifndef SOMAXCONN
465#define SOMAXCONN 128 465#define SOMAXCONN 128
466#endif 466#endif
467 467
468/* 468/*
469 * Message header for recvmsg and sendmsg calls. 469 * Message header for recvmsg and sendmsg calls.
470 * Used value-result for recvmsg, value only for sendmsg. 470 * Used value-result for recvmsg, value only for sendmsg.
471 */ 471 */
472struct msghdr { 472struct msghdr {
473 void *msg_name; /* optional address */ 473 void *msg_name; /* optional address */
474 socklen_t msg_namelen; /* size of address */ 474 socklen_t msg_namelen; /* size of address */
475 struct iovec *msg_iov; /* scatter/gather array */ 475 struct iovec *msg_iov; /* scatter/gather array */
476 int msg_iovlen; /* # elements in msg_iov */ 476 int msg_iovlen; /* # elements in msg_iov */
477 void *msg_control; /* ancillary data, see below */ 477 void *msg_control; /* ancillary data, see below */
478 socklen_t msg_controllen; /* ancillary data buffer len */ 478 socklen_t msg_controllen; /* ancillary data buffer len */
479 int msg_flags; /* flags on received message */ 479 int msg_flags; /* flags on received message */
480}; 480};
481 481
482#define MSG_OOB 0x0001 /* process out-of-band data */ 482#define MSG_OOB 0x0001 /* process out-of-band data */
483#define MSG_PEEK 0x0002 /* peek at incoming message */ 483#define MSG_PEEK 0x0002 /* peek at incoming message */
484#define MSG_DONTROUTE 0x0004 /* send without using routing tables */ 484#define MSG_DONTROUTE 0x0004 /* send without using routing tables */
485#define MSG_EOR 0x0008 /* data completes record */ 485#define MSG_EOR 0x0008 /* data completes record */
486#define MSG_TRUNC 0x0010 /* data discarded before delivery */ 486#define MSG_TRUNC 0x0010 /* data discarded before delivery */
487#define MSG_CTRUNC 0x0020 /* control data lost before delivery */ 487#define MSG_CTRUNC 0x0020 /* control data lost before delivery */
488#define MSG_WAITALL 0x0040 /* wait for full request or error */ 488#define MSG_WAITALL 0x0040 /* wait for full request or error */
489#define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */ 489#define MSG_DONTWAIT 0x0080 /* this message should be nonblocking */
490#define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */ 490#define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */
491#define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */ 491#define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */
492#define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */ 492#define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */
493#if defined(_NETBSD_SOURCE) 493#if defined(_NETBSD_SOURCE)
494#define MSG_CMSG_CLOEXEC 0x0800 /* close on exec receiving fd */ 494#define MSG_CMSG_CLOEXEC 0x0800 /* close on exec receiving fd */
495#define MSG_NBIO 0x1000 /* use non-blocking I/O */ 495#define MSG_NBIO 0x1000 /* use non-blocking I/O */
496#endif 496#endif
497 497
498/* Extra flags used internally only */ 498/* Extra flags used internally only */
499#define MSG_USERFLAGS 0x0ffffff 499#define MSG_USERFLAGS 0x0ffffff
500#define MSG_NAMEMBUF 0x1000000 /* msg_name is an mbuf */ 500#define MSG_NAMEMBUF 0x1000000 /* msg_name is an mbuf */
501#define MSG_CONTROLMBUF 0x2000000 /* msg_control is an mbuf */ 501#define MSG_CONTROLMBUF 0x2000000 /* msg_control is an mbuf */
502#define MSG_IOVUSRSPACE 0x4000000 /* msg_iov is in user space */ 502#define MSG_IOVUSRSPACE 0x4000000 /* msg_iov is in user space */
503#define MSG_LENUSRSPACE 0x8000000 /* address length is in user space */ 503#define MSG_LENUSRSPACE 0x8000000 /* address length is in user space */
504 504
505/* 505/*
506 * Header for ancillary data objects in msg_control buffer. 506 * Header for ancillary data objects in msg_control buffer.
507 * Used for additional information with/about a datagram 507 * Used for additional information with/about a datagram
508 * not expressible by flags. The format is a sequence 508 * not expressible by flags. The format is a sequence
509 * of message elements headed by cmsghdr structures. 509 * of message elements headed by cmsghdr structures.
510 */ 510 */
511struct cmsghdr { 511struct cmsghdr {
512 socklen_t cmsg_len; /* data byte count, including hdr */ 512 socklen_t cmsg_len; /* data byte count, including hdr */
513 int cmsg_level; /* originating protocol */ 513 int cmsg_level; /* originating protocol */
514 int cmsg_type; /* protocol-specific type */ 514 int cmsg_type; /* protocol-specific type */
515/* followed by u_char cmsg_data[]; */ 515/* followed by u_char cmsg_data[]; */
516}; 516};
517 517
518/* given pointer to struct cmsghdr, return pointer to data */ 518/* given pointer to struct cmsghdr, return pointer to data */
519#define CMSG_DATA(cmsg) \ 519#define CMSG_DATA(cmsg) \
520 ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr))) 520 ((u_char *)(void *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
521#define CCMSG_DATA(cmsg) \ 521#define CCMSG_DATA(cmsg) \
522 ((const u_char *)(const void *)(cmsg) + \ 522 ((const u_char *)(const void *)(cmsg) + \
523 __CMSG_ALIGN(sizeof(struct cmsghdr))) 523 __CMSG_ALIGN(sizeof(struct cmsghdr)))
524 524
525/* 525/*
526 * Alignment requirement for CMSG struct manipulation. 526 * Alignment requirement for CMSG struct manipulation.
527 * This basically behaves the same as ALIGN() ARCH/include/param.h. 527 * This basically behaves the same as ALIGN() ARCH/include/param.h.
528 * We declare it separately for two reasons: 528 * We declare it separately for two reasons:
529 * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's 529 * (1) avoid dependency between machine/param.h, and (2) to sync with kernel's
530 * idea of ALIGNBYTES at runtime. 530 * idea of ALIGNBYTES at runtime.
531 * without (2), we can't guarantee binary compatibility in case of future 531 * without (2), we can't guarantee binary compatibility in case of future
532 * changes in ALIGNBYTES. 532 * changes in ALIGNBYTES.
533 */ 533 */
534#ifdef _KERNEL 534#ifdef _KERNEL
535#define __CMSG_ALIGN(n) (((n) + ALIGNBYTES) & ~ALIGNBYTES) 535#define __CMSG_ALIGN(n) (((n) + ALIGNBYTES) & ~ALIGNBYTES)
536#define CMSG_ALIGN(n) __CMSG_ALIGN(n) 536#define CMSG_ALIGN(n) __CMSG_ALIGN(n)
537#else 537#else
538#define __CMSG_ALIGN(n) (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes()) 538#define __CMSG_ALIGN(n) (((n) + __cmsg_alignbytes()) & ~__cmsg_alignbytes())
539#define CMSG_ALIGN(n) __CMSG_ALIGN(n) 
540#endif 539#endif
541 540
542/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ 541/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
543#define CMSG_NXTHDR(mhdr, cmsg) \ 542#define CMSG_NXTHDR(mhdr, cmsg) \
544 (((char *)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \ 543 (((char *)(cmsg) + __CMSG_ALIGN((cmsg)->cmsg_len) + \
545 __CMSG_ALIGN(sizeof(struct cmsghdr)) > \ 544 __CMSG_ALIGN(sizeof(struct cmsghdr)) > \
546 (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \ 545 (((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen)) ? \
547 (struct cmsghdr *)0 : \ 546 (struct cmsghdr *)0 : \
548 (struct cmsghdr *)((char *)(cmsg) + \ 547 (struct cmsghdr *)((char *)(cmsg) + \
549 __CMSG_ALIGN((cmsg)->cmsg_len))) 548 __CMSG_ALIGN((cmsg)->cmsg_len)))
550 549
551/* 550/*
552 * RFC 2292 requires to check msg_controllen, in case that the kernel returns 551 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
553 * an empty list for some reasons. 552 * an empty list for some reasons.
554 */ 553 */
555#define CMSG_FIRSTHDR(mhdr) \ 554#define CMSG_FIRSTHDR(mhdr) \
556 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 555 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
557 (struct cmsghdr *)(mhdr)->msg_control : \ 556 (struct cmsghdr *)(mhdr)->msg_control : \
558 (struct cmsghdr *)0) 557 (struct cmsghdr *)0)
559 558
560#define CMSG_SPACE(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l)) 559#define CMSG_SPACE(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(l))
561#define CMSG_LEN(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l)) 560#define CMSG_LEN(l) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
562 561
563/* "Socket"-level control message types: */ 562/* "Socket"-level control message types: */
564#define SCM_RIGHTS 0x01 /* access rights (array of int) */ 563#define SCM_RIGHTS 0x01 /* access rights (array of int) */
565#if defined(_NETBSD_SOURCE) 564#if defined(_NETBSD_SOURCE)
566/* 0x02 timestamp (struct timeval50) */ 565/* 0x02 timestamp (struct timeval50) */
567#define SCM_CREDS 0x04 /* credentials (struct sockcred) */ 566#define SCM_CREDS 0x04 /* credentials (struct sockcred) */
568#define SCM_TIMESTAMP 0x08 /* timestamp (struct timeval) */ 567#define SCM_TIMESTAMP 0x08 /* timestamp (struct timeval) */
569#endif 568#endif
570 569
571/* 570/*
572 * Types of socket shutdown(2). 571 * Types of socket shutdown(2).
573 */ 572 */
574#define SHUT_RD 0 /* Disallow further receives. */ 573#define SHUT_RD 0 /* Disallow further receives. */
575#define SHUT_WR 1 /* Disallow further sends. */ 574#define SHUT_WR 1 /* Disallow further sends. */
576#define SHUT_RDWR 2 /* Disallow further sends/receives. */ 575#define SHUT_RDWR 2 /* Disallow further sends/receives. */
577 576
578#include <sys/cdefs.h> 577#include <sys/cdefs.h>
579 578
580#ifndef _KERNEL 579#ifndef _KERNEL
581__BEGIN_DECLS 580__BEGIN_DECLS
582int __cmsg_alignbytes(void) __constfunc; 581int __cmsg_alignbytes(void) __constfunc;
583__END_DECLS 582__END_DECLS
584#endif 583#endif
585 584
586#ifdef _KERNEL 585#ifdef _KERNEL
587static inline socklen_t 586static inline socklen_t
588sockaddr_getlen(const struct sockaddr *sa) 587sockaddr_getlen(const struct sockaddr *sa)
589{ 588{
590 return sa->sa_len; 589 return sa->sa_len;
591} 590}
592 591
593__BEGIN_DECLS 592__BEGIN_DECLS
594struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t, 593struct sockaddr *sockaddr_copy(struct sockaddr *, socklen_t,
595 const struct sockaddr *); 594 const struct sockaddr *);
596struct sockaddr *sockaddr_externalize(struct sockaddr *, socklen_t, 595struct sockaddr *sockaddr_externalize(struct sockaddr *, socklen_t,
597 const struct sockaddr *); 596 const struct sockaddr *);
598struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int); 597struct sockaddr *sockaddr_alloc(sa_family_t, socklen_t, int);
599const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *); 598const void *sockaddr_const_addr(const struct sockaddr *, socklen_t *);
600void *sockaddr_addr(struct sockaddr *, socklen_t *); 599void *sockaddr_addr(struct sockaddr *, socklen_t *);
601const struct sockaddr *sockaddr_any(const struct sockaddr *); 600const struct sockaddr *sockaddr_any(const struct sockaddr *);
602const struct sockaddr *sockaddr_any_by_family(int); 601const struct sockaddr *sockaddr_any_by_family(int);
603const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *); 602const void *sockaddr_anyaddr(const struct sockaddr *, socklen_t *);
604int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *); 603int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *);
605struct sockaddr *sockaddr_dup(const struct sockaddr *, int); 604struct sockaddr *sockaddr_dup(const struct sockaddr *, int);
606void sockaddr_free(struct sockaddr *); 605void sockaddr_free(struct sockaddr *);
607__END_DECLS 606__END_DECLS
608#endif /* _KERNEL */ 607#endif /* _KERNEL */
609 608
610#ifndef _KERNEL 609#ifndef _KERNEL
611 610
612__BEGIN_DECLS 611__BEGIN_DECLS
613int accept(int, struct sockaddr * __restrict, socklen_t * __restrict); 612int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
614int bind(int, const struct sockaddr *, socklen_t); 613int bind(int, const struct sockaddr *, socklen_t);
615int connect(int, const struct sockaddr *, socklen_t); 614int connect(int, const struct sockaddr *, socklen_t);
616int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); 615int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
617int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); 616int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
618int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict); 617int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict);
619int listen(int, int); 618int listen(int, int);
620int paccept(int, struct sockaddr * __restrict, socklen_t * __restrict, 619int paccept(int, struct sockaddr * __restrict, socklen_t * __restrict,
621 const sigset_t * __restrict, int); 620 const sigset_t * __restrict, int);
622ssize_t recv(int, void *, size_t, int); 621ssize_t recv(int, void *, size_t, int);
623ssize_t recvfrom(int, void *__restrict, size_t, int, 622ssize_t recvfrom(int, void *__restrict, size_t, int,
624 struct sockaddr * __restrict, socklen_t * __restrict); 623 struct sockaddr * __restrict, socklen_t * __restrict);
625ssize_t recvmsg(int, struct msghdr *, int); 624ssize_t recvmsg(int, struct msghdr *, int);
626ssize_t send(int, const void *, size_t, int); 625ssize_t send(int, const void *, size_t, int);
627ssize_t sendto(int, const void *, 626ssize_t sendto(int, const void *,
628 size_t, int, const struct sockaddr *, socklen_t); 627 size_t, int, const struct sockaddr *, socklen_t);
629ssize_t sendmsg(int, const struct msghdr *, int); 628ssize_t sendmsg(int, const struct msghdr *, int);
630int setsockopt(int, int, int, const void *, socklen_t); 629int setsockopt(int, int, int, const void *, socklen_t);
631int shutdown(int, int); 630int shutdown(int, int);
632int sockatmark(int); 631int sockatmark(int);
633int socket(int, int, int) 632int socket(int, int, int)
634#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE) 633#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
635__RENAME(__socket30) 634__RENAME(__socket30)
636#endif 635#endif
637 ; 636 ;
638int socketpair(int, int, int, int *); 637int socketpair(int, int, int, int *);
639__END_DECLS 638__END_DECLS
640#endif /* !_KERNEL */ 639#endif /* !_KERNEL */
641 640
642#endif /* !_SYS_SOCKET_H_ */ 641#endif /* !_SYS_SOCKET_H_ */