]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */ | |
29 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
30 | /* | |
31 | * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 | |
32 | * The Regents of the University of California. All rights reserved. | |
33 | * | |
34 | * Redistribution and use in source and binary forms, with or without | |
35 | * modification, are permitted provided that the following conditions | |
36 | * are met: | |
37 | * 1. Redistributions of source code must retain the above copyright | |
38 | * notice, this list of conditions and the following disclaimer. | |
39 | * 2. Redistributions in binary form must reproduce the above copyright | |
40 | * notice, this list of conditions and the following disclaimer in the | |
41 | * documentation and/or other materials provided with the distribution. | |
42 | * 3. All advertising materials mentioning features or use of this software | |
43 | * must display the following acknowledgement: | |
44 | * This product includes software developed by the University of | |
45 | * California, Berkeley and its contributors. | |
46 | * 4. Neither the name of the University nor the names of its contributors | |
47 | * may be used to endorse or promote products derived from this software | |
48 | * without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
51 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
53 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
54 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
55 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
56 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
57 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
58 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
59 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
60 | * SUCH DAMAGE. | |
61 | * | |
62 | * @(#)socket.h 8.4 (Berkeley) 2/21/94 | |
9bccf70c | 63 | * $FreeBSD: src/sys/sys/socket.h,v 1.39.2.7 2001/07/03 11:02:01 ume Exp $ |
1c79356b | 64 | */ |
2d21ac55 A |
65 | /* |
66 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce | |
67 | * support for mandatory and extensible security protections. This notice | |
68 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
69 | * Version 2.0. | |
70 | */ | |
1c79356b A |
71 | |
72 | #ifndef _SYS_SOCKET_H_ | |
73 | #define _SYS_SOCKET_H_ | |
74 | ||
91447636 A |
75 | #include <sys/_types.h> |
76 | #include <sys/cdefs.h> | |
2d21ac55 | 77 | #include <machine/_param.h> |
1c79356b A |
78 | |
79 | /* | |
80 | * Definitions related to sockets: types, address families, options. | |
81 | */ | |
82 | ||
9bccf70c A |
83 | /* |
84 | * Data types. | |
85 | */ | |
91447636 A |
86 | #ifndef _GID_T |
87 | typedef __darwin_gid_t gid_t; | |
88 | #define _GID_T | |
89 | #endif | |
90 | ||
91 | #ifndef _OFF_T | |
92 | typedef __darwin_off_t off_t; | |
93 | #define _OFF_T | |
94 | #endif | |
95 | ||
96 | #ifndef _PID_T | |
97 | typedef __darwin_pid_t pid_t; | |
98 | #define _PID_T | |
99 | #endif | |
100 | ||
101 | #ifndef _SA_FAMILY_T | |
102 | #define _SA_FAMILY_T | |
103 | typedef __uint8_t sa_family_t; | |
104 | #endif | |
105 | ||
106 | #ifndef _SOCKLEN_T | |
107 | #define _SOCKLEN_T | |
108 | typedef __darwin_socklen_t socklen_t; | |
109 | #endif | |
110 | ||
111 | /* XXX Not explicitly defined by POSIX, but function return types are */ | |
112 | #ifndef _SIZE_T | |
113 | #define _SIZE_T | |
114 | typedef __darwin_size_t size_t; | |
115 | #endif | |
116 | ||
117 | /* XXX Not explicitly defined by POSIX, but function return types are */ | |
118 | #ifndef _SSIZE_T | |
119 | #define _SSIZE_T | |
120 | typedef __darwin_ssize_t ssize_t; | |
121 | #endif | |
122 | ||
123 | /* | |
124 | * [XSI] The iovec structure shall be defined as described in <sys/uio.h>. | |
125 | */ | |
126 | #ifndef _STRUCT_IOVEC | |
127 | #define _STRUCT_IOVEC | |
128 | struct iovec { | |
129 | void * iov_base; /* [XSI] Base address of I/O memory region */ | |
130 | size_t iov_len; /* [XSI] Size of region iov_base points to */ | |
131 | }; | |
9bccf70c A |
132 | #endif |
133 | ||
1c79356b A |
134 | /* |
135 | * Types | |
136 | */ | |
137 | #define SOCK_STREAM 1 /* stream socket */ | |
138 | #define SOCK_DGRAM 2 /* datagram socket */ | |
139 | #define SOCK_RAW 3 /* raw-protocol interface */ | |
2d21ac55 | 140 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b | 141 | #define SOCK_RDM 4 /* reliably-delivered message */ |
2d21ac55 | 142 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b A |
143 | #define SOCK_SEQPACKET 5 /* sequenced packet stream */ |
144 | ||
145 | /* | |
146 | * Option flags per-socket. | |
147 | */ | |
148 | #define SO_DEBUG 0x0001 /* turn on debugging info recording */ | |
149 | #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ | |
150 | #define SO_REUSEADDR 0x0004 /* allow local address reuse */ | |
151 | #define SO_KEEPALIVE 0x0008 /* keep connections alive */ | |
152 | #define SO_DONTROUTE 0x0010 /* just use interface addresses */ | |
153 | #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ | |
2d21ac55 | 154 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b | 155 | #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ |
91447636 A |
156 | #define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */ |
157 | #else | |
158 | #define SO_LINGER 0x1080 /* linger on close if data present (in seconds) */ | |
2d21ac55 | 159 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b | 160 | #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ |
2d21ac55 | 161 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b A |
162 | #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ |
163 | #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ | |
9bccf70c A |
164 | #ifndef __APPLE__ |
165 | #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ | |
166 | #else | |
1c79356b A |
167 | #define SO_DONTTRUNC 0x2000 /* APPLE: Retain unread data */ |
168 | /* (ATOMIC proto) */ | |
9bccf70c A |
169 | #define SO_WANTMORE 0x4000 /* APPLE: Give hint when more data ready */ |
170 | #define SO_WANTOOBFLAG 0x8000 /* APPLE: Want OOB in MSG_FLAG on receive */ | |
171 | #endif | |
2d21ac55 | 172 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b A |
173 | |
174 | /* | |
175 | * Additional options, not kept in so_options. | |
176 | */ | |
177 | #define SO_SNDBUF 0x1001 /* send buffer size */ | |
178 | #define SO_RCVBUF 0x1002 /* receive buffer size */ | |
179 | #define SO_SNDLOWAT 0x1003 /* send low-water mark */ | |
180 | #define SO_RCVLOWAT 0x1004 /* receive low-water mark */ | |
181 | #define SO_SNDTIMEO 0x1005 /* send timeout */ | |
182 | #define SO_RCVTIMEO 0x1006 /* receive timeout */ | |
183 | #define SO_ERROR 0x1007 /* get error status and clear */ | |
184 | #define SO_TYPE 0x1008 /* get socket type */ | |
2d21ac55 | 185 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
9bccf70c A |
186 | /*efine SO_PRIVSTATE 0x1009 get/deny privileged state */ |
187 | #ifdef __APPLE__ | |
1c79356b A |
188 | #define SO_NREAD 0x1020 /* APPLE: get 1st-packet byte count */ |
189 | #define SO_NKE 0x1021 /* APPLE: Install socket-level NKE */ | |
9bccf70c | 190 | #define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */ |
55e303ae | 191 | #define SO_NOADDRERR 0x1023 /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */ |
91447636 | 192 | #define SO_NWRITE 0x1024 /* APPLE: Get number of bytes currently in send socket buffer */ |
2d21ac55 A |
193 | #define SO_REUSESHAREUID 0x1025 /* APPLE: Allow reuse of port/socket by different userids */ |
194 | #ifdef __APPLE_API_PRIVATE | |
195 | #define SO_NOTIFYCONFLICT 0x1026 /* APPLE: send notification if there is a bind on a port which is already in use */ | |
196 | #endif | |
91447636 | 197 | #define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */ |
2d21ac55 A |
198 | #define SO_RESTRICTIONS 0x1081 /* APPLE: deny inbound/outbound/both/flag set */ |
199 | #define SO_RESTRICT_DENYIN 0x00000001 /* flag for SO_RESTRICTIONS - deny inbound */ | |
200 | #define SO_RESTRICT_DENYOUT 0x00000002 /* flag for SO_RESTRICTIONS - deny outbound */ | |
201 | #define SO_RESTRICT_DENYSET 0x80000000 /* flag for SO_RESTRICTIONS - deny has been set */ | |
9bccf70c | 202 | #endif |
2d21ac55 A |
203 | #ifdef PRIVATE |
204 | #define SO_EXECPATH 0x1085 /* Application Firewall Socket option */ | |
205 | #endif | |
206 | #define SO_LABEL 0x1010 /* socket's MAC label */ | |
207 | #define SO_PEERLABEL 0x1011 /* socket's peer MAC label */ | |
208 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ | |
91447636 | 209 | |
1c79356b A |
210 | /* |
211 | * Structure used for manipulating linger option. | |
212 | */ | |
213 | struct linger { | |
214 | int l_onoff; /* option on/off */ | |
215 | int l_linger; /* linger time */ | |
216 | }; | |
217 | ||
9bccf70c A |
218 | #ifndef __APPLE__ |
219 | struct accept_filter_arg { | |
220 | char af_name[16]; | |
221 | char af_arg[256-16]; | |
222 | }; | |
223 | #endif | |
224 | ||
1c79356b A |
225 | /* |
226 | * Level number for (get/set)sockopt() to apply to socket itself. | |
227 | */ | |
228 | #define SOL_SOCKET 0xffff /* options for socket level */ | |
229 | ||
2d21ac55 | 230 | |
1c79356b A |
231 | /* |
232 | * Address families. | |
233 | */ | |
234 | #define AF_UNSPEC 0 /* unspecified */ | |
91447636 | 235 | #define AF_UNIX 1 /* local to host (pipes) */ |
2d21ac55 | 236 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
91447636 | 237 | #define AF_LOCAL AF_UNIX /* backward compatibility */ |
2d21ac55 | 238 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b | 239 | #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ |
2d21ac55 | 240 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b A |
241 | #define AF_IMPLINK 3 /* arpanet imp addresses */ |
242 | #define AF_PUP 4 /* pup protocols: e.g. BSP */ | |
243 | #define AF_CHAOS 5 /* mit CHAOS protocols */ | |
244 | #define AF_NS 6 /* XEROX NS protocols */ | |
245 | #define AF_ISO 7 /* ISO protocols */ | |
246 | #define AF_OSI AF_ISO | |
9bccf70c | 247 | #define AF_ECMA 8 /* European computer manufacturers */ |
1c79356b A |
248 | #define AF_DATAKIT 9 /* datakit protocols */ |
249 | #define AF_CCITT 10 /* CCITT protocols, X.25 etc */ | |
250 | #define AF_SNA 11 /* IBM SNA */ | |
251 | #define AF_DECnet 12 /* DECnet */ | |
252 | #define AF_DLI 13 /* DEC Direct data link interface */ | |
253 | #define AF_LAT 14 /* LAT */ | |
254 | #define AF_HYLINK 15 /* NSC Hyperchannel */ | |
255 | #define AF_APPLETALK 16 /* Apple Talk */ | |
256 | #define AF_ROUTE 17 /* Internal Routing Protocol */ | |
257 | #define AF_LINK 18 /* Link layer interface */ | |
258 | #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ | |
259 | #define AF_COIP 20 /* connection-oriented IP, aka ST II */ | |
260 | #define AF_CNT 21 /* Computer Network Technology */ | |
261 | #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ | |
262 | #define AF_IPX 23 /* Novell Internet Protocol */ | |
263 | #define AF_SIP 24 /* Simple Internet Protocol */ | |
264 | #define pseudo_AF_PIP 25 /* Help Identify PIP packets */ | |
9bccf70c A |
265 | #ifdef __APPLE__ |
266 | /*define pseudo_AF_BLUE 26 Identify packets for Blue Box - Not used */ | |
1c79356b | 267 | #define AF_NDRV 27 /* Network Driver 'raw' access */ |
9bccf70c | 268 | #endif |
1c79356b A |
269 | #define AF_ISDN 28 /* Integrated Services Digital Network*/ |
270 | #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ | |
271 | #define pseudo_AF_KEY 29 /* Internal key-management function */ | |
2d21ac55 | 272 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b | 273 | #define AF_INET6 30 /* IPv6 */ |
2d21ac55 | 274 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b | 275 | #define AF_NATM 31 /* native ATM access */ |
9bccf70c A |
276 | #ifdef __APPLE__ |
277 | #define AF_SYSTEM 32 /* Kernel event messages */ | |
1c79356b | 278 | #define AF_NETBIOS 33 /* NetBIOS */ |
0b4e3aa0 | 279 | #define AF_PPP 34 /* PPP communication protocol */ |
9bccf70c A |
280 | #else |
281 | #define AF_ATM 30 /* ATM */ | |
282 | #endif | |
283 | #define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers | |
284 | * in interface output routine | |
285 | */ | |
91447636 A |
286 | #ifdef PRIVATE |
287 | #define AF_AFP 36 /* Used by AFP */ | |
288 | #else | |
289 | #define AF_RESERVED_36 36 /* Reserved for internal usage */ | |
290 | #endif | |
291 | ||
9bccf70c A |
292 | #ifndef __APPLE__ |
293 | #define AF_NETGRAPH 32 /* Netgraph sockets */ | |
294 | #endif | |
91447636 | 295 | #define AF_MAX 37 |
2d21ac55 | 296 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b A |
297 | |
298 | /* | |
91447636 | 299 | * [XSI] Structure used by kernel to store most addresses. |
1c79356b A |
300 | */ |
301 | struct sockaddr { | |
91447636 A |
302 | __uint8_t sa_len; /* total length */ |
303 | sa_family_t sa_family; /* [XSI] address family */ | |
304 | char sa_data[14]; /* [XSI] addr value (actually larger) */ | |
1c79356b | 305 | }; |
91447636 | 306 | |
2d21ac55 | 307 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b A |
308 | #define SOCK_MAXADDRLEN 255 /* longest possible addresses */ |
309 | ||
310 | /* | |
311 | * Structure used by kernel to pass protocol | |
312 | * information in raw sockets. | |
313 | */ | |
314 | struct sockproto { | |
91447636 A |
315 | __uint16_t sp_family; /* address family */ |
316 | __uint16_t sp_protocol; /* protocol */ | |
1c79356b | 317 | }; |
2d21ac55 | 318 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE)*/ |
1c79356b | 319 | |
1c79356b | 320 | /* |
9bccf70c | 321 | * RFC 2553: protocol-independent placeholder for socket addresses |
1c79356b | 322 | */ |
9bccf70c | 323 | #define _SS_MAXSIZE 128 |
91447636 A |
324 | #define _SS_ALIGNSIZE (sizeof(__int64_t)) |
325 | #define _SS_PAD1SIZE \ | |
326 | (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t)) | |
327 | #define _SS_PAD2SIZE \ | |
328 | (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \ | |
1c79356b A |
329 | _SS_PAD1SIZE - _SS_ALIGNSIZE) |
330 | ||
91447636 A |
331 | /* |
332 | * [XSI] sockaddr_storage | |
333 | */ | |
1c79356b | 334 | struct sockaddr_storage { |
91447636 A |
335 | __uint8_t ss_len; /* address length */ |
336 | sa_family_t ss_family; /* [XSI] address family */ | |
9bccf70c | 337 | char __ss_pad1[_SS_PAD1SIZE]; |
91447636 | 338 | __int64_t __ss_align; /* force structure storage alignment */ |
9bccf70c | 339 | char __ss_pad2[_SS_PAD2SIZE]; |
1c79356b | 340 | }; |
1c79356b A |
341 | |
342 | /* | |
343 | * Protocol families, same as address families for now. | |
344 | */ | |
345 | #define PF_UNSPEC AF_UNSPEC | |
346 | #define PF_LOCAL AF_LOCAL | |
347 | #define PF_UNIX PF_LOCAL /* backward compatibility */ | |
348 | #define PF_INET AF_INET | |
1c79356b A |
349 | #define PF_IMPLINK AF_IMPLINK |
350 | #define PF_PUP AF_PUP | |
351 | #define PF_CHAOS AF_CHAOS | |
352 | #define PF_NS AF_NS | |
353 | #define PF_ISO AF_ISO | |
354 | #define PF_OSI AF_ISO | |
355 | #define PF_ECMA AF_ECMA | |
356 | #define PF_DATAKIT AF_DATAKIT | |
357 | #define PF_CCITT AF_CCITT | |
358 | #define PF_SNA AF_SNA | |
359 | #define PF_DECnet AF_DECnet | |
360 | #define PF_DLI AF_DLI | |
361 | #define PF_LAT AF_LAT | |
362 | #define PF_HYLINK AF_HYLINK | |
363 | #define PF_APPLETALK AF_APPLETALK | |
364 | #define PF_ROUTE AF_ROUTE | |
365 | #define PF_LINK AF_LINK | |
366 | #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ | |
367 | #define PF_COIP AF_COIP | |
368 | #define PF_CNT AF_CNT | |
369 | #define PF_SIP AF_SIP | |
370 | #define PF_IPX AF_IPX /* same format as AF_NS */ | |
371 | #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ | |
372 | #define PF_PIP pseudo_AF_PIP | |
9bccf70c | 373 | #ifdef __APPLE__ |
1c79356b | 374 | #define PF_NDRV AF_NDRV |
9bccf70c | 375 | #endif |
1c79356b A |
376 | #define PF_ISDN AF_ISDN |
377 | #define PF_KEY pseudo_AF_KEY | |
378 | #define PF_INET6 AF_INET6 | |
379 | #define PF_NATM AF_NATM | |
9bccf70c | 380 | #ifdef __APPLE__ |
1c79356b A |
381 | #define PF_SYSTEM AF_SYSTEM |
382 | #define PF_NETBIOS AF_NETBIOS | |
0b4e3aa0 | 383 | #define PF_PPP AF_PPP |
91447636 A |
384 | #ifdef PRIVATE |
385 | #define PF_AFP AF_AFP | |
386 | #else | |
387 | #define PF_RESERVED_36 AF_RESERVED_36 | |
388 | #endif | |
389 | ||
9bccf70c A |
390 | #else |
391 | #define PF_ATM AF_ATM | |
392 | #define PF_NETGRAPH AF_NETGRAPH | |
393 | #endif | |
1c79356b A |
394 | |
395 | #define PF_MAX AF_MAX | |
396 | ||
91447636 A |
397 | /* |
398 | * These do not have socket-layer support: | |
399 | */ | |
400 | #define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */ | |
401 | #define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */ | |
402 | ||
1c79356b A |
403 | /* |
404 | * Definitions for network related sysctl, CTL_NET. | |
405 | * | |
406 | * Second level is protocol family. | |
407 | * Third level is protocol number. | |
408 | * | |
409 | * Further levels are defined by the individual families below. | |
410 | */ | |
2d21ac55 | 411 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b | 412 | #define NET_MAXID AF_MAX |
2d21ac55 | 413 | #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ |
91447636 A |
414 | |
415 | #ifdef KERNEL_PRIVATE | |
1c79356b A |
416 | #define CTL_NET_NAMES { \ |
417 | { 0, 0 }, \ | |
418 | { "local", CTLTYPE_NODE }, \ | |
419 | { "inet", CTLTYPE_NODE }, \ | |
420 | { "implink", CTLTYPE_NODE }, \ | |
421 | { "pup", CTLTYPE_NODE }, \ | |
422 | { "chaos", CTLTYPE_NODE }, \ | |
423 | { "xerox_ns", CTLTYPE_NODE }, \ | |
424 | { "iso", CTLTYPE_NODE }, \ | |
425 | { "emca", CTLTYPE_NODE }, \ | |
426 | { "datakit", CTLTYPE_NODE }, \ | |
427 | { "ccitt", CTLTYPE_NODE }, \ | |
428 | { "ibm_sna", CTLTYPE_NODE }, \ | |
429 | { "decnet", CTLTYPE_NODE }, \ | |
430 | { "dec_dli", CTLTYPE_NODE }, \ | |
431 | { "lat", CTLTYPE_NODE }, \ | |
432 | { "hylink", CTLTYPE_NODE }, \ | |
433 | { "appletalk", CTLTYPE_NODE }, \ | |
434 | { "route", CTLTYPE_NODE }, \ | |
435 | { "link_layer", CTLTYPE_NODE }, \ | |
436 | { "xtp", CTLTYPE_NODE }, \ | |
437 | { "coip", CTLTYPE_NODE }, \ | |
438 | { "cnt", CTLTYPE_NODE }, \ | |
439 | { "rtip", CTLTYPE_NODE }, \ | |
440 | { "ipx", CTLTYPE_NODE }, \ | |
441 | { "sip", CTLTYPE_NODE }, \ | |
442 | { "pip", CTLTYPE_NODE }, \ | |
9bccf70c A |
443 | { 0, 0 }, \ |
444 | { "ndrv", CTLTYPE_NODE }, \ | |
1c79356b A |
445 | { "isdn", CTLTYPE_NODE }, \ |
446 | { "key", CTLTYPE_NODE }, \ | |
447 | { "inet6", CTLTYPE_NODE }, \ | |
448 | { "natm", CTLTYPE_NODE }, \ | |
9bccf70c A |
449 | { "sys", CTLTYPE_NODE }, \ |
450 | { "netbios", CTLTYPE_NODE }, \ | |
451 | { "ppp", CTLTYPE_NODE }, \ | |
452 | { "hdrcomplete", CTLTYPE_NODE }, \ | |
1c79356b | 453 | } |
2d21ac55 | 454 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 455 | |
2d21ac55 | 456 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b A |
457 | /* |
458 | * PF_ROUTE - Routing table | |
459 | * | |
460 | * Three additional levels are defined: | |
461 | * Fourth: address family, 0 is wildcard | |
462 | * Fifth: type of info, defined below | |
463 | * Sixth: flag(s) to mask with for NET_RT_FLAGS | |
464 | */ | |
91447636 A |
465 | #define NET_RT_DUMP 1 /* dump; may limit to a.f. */ |
466 | #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ | |
467 | #define NET_RT_IFLIST 3 /* survey interface list */ | |
468 | #define NET_RT_STAT 4 /* routing statistics */ | |
469 | #define NET_RT_TRASH 5 /* routes not in table but not freed */ | |
470 | #define NET_RT_IFLIST2 6 /* interface list with addresses */ | |
471 | #define NET_RT_DUMP2 7 /* dump; may limit to a.f. */ | |
472 | #define NET_RT_MAXID 8 | |
2d21ac55 | 473 | #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ |
91447636 A |
474 | |
475 | #ifdef KERNEL_PRIVATE | |
1c79356b A |
476 | #define CTL_NET_RT_NAMES { \ |
477 | { 0, 0 }, \ | |
478 | { "dump", CTLTYPE_STRUCT }, \ | |
479 | { "flags", CTLTYPE_STRUCT }, \ | |
480 | { "iflist", CTLTYPE_STRUCT }, \ | |
91447636 A |
481 | { "stat", CTLTYPE_STRUCT }, \ |
482 | { "trash", CTLTYPE_INT }, \ | |
483 | { "iflist2", CTLTYPE_STRUCT }, \ | |
484 | { "dump2", CTLTYPE_STRUCT }, \ | |
1c79356b A |
485 | } |
486 | ||
2d21ac55 | 487 | #endif /* KERNEL_PRIVATE */ |
91447636 | 488 | |
1c79356b A |
489 | /* |
490 | * Maximum queue length specifiable by listen. | |
491 | */ | |
492 | #define SOMAXCONN 128 | |
493 | ||
494 | /* | |
91447636 | 495 | * [XSI] Message header for recvmsg and sendmsg calls. |
1c79356b A |
496 | * Used value-result for recvmsg, value only for sendmsg. |
497 | */ | |
498 | struct msghdr { | |
91447636 A |
499 | void *msg_name; /* [XSI] optional address */ |
500 | socklen_t msg_namelen; /* [XSI] size of address */ | |
501 | struct iovec *msg_iov; /* [XSI] scatter/gather array */ | |
502 | int msg_iovlen; /* [XSI] # elements in msg_iov */ | |
503 | void *msg_control; /* [XSI] ancillary data, see below */ | |
504 | socklen_t msg_controllen; /* [XSI] ancillary data buffer len */ | |
505 | int msg_flags; /* [XSI] flags on received message */ | |
506 | }; | |
507 | ||
91447636 A |
508 | #ifdef KERNEL |
509 | /* LP64 version of struct msghdr. all pointers | |
510 | * grow when we're dealing with a 64-bit process. | |
511 | * WARNING - keep in sync with struct msghdr | |
512 | */ | |
91447636 A |
513 | |
514 | struct user_msghdr { | |
515 | user_addr_t msg_name; /* optional address */ | |
55e303ae | 516 | socklen_t msg_namelen; /* size of address */ |
0c530ab8 | 517 | user_addr_t msg_iov __attribute((aligned(8))); /* scatter/gather array */ |
91447636 | 518 | int msg_iovlen; /* # elements in msg_iov */ |
0c530ab8 | 519 | user_addr_t msg_control __attribute((aligned(8))); /* ancillary data, see below */ |
55e303ae A |
520 | socklen_t msg_controllen; /* ancillary data buffer len */ |
521 | int msg_flags; /* flags on received message */ | |
1c79356b A |
522 | }; |
523 | ||
91447636 A |
524 | #endif // KERNEL |
525 | ||
1c79356b A |
526 | #define MSG_OOB 0x1 /* process out-of-band data */ |
527 | #define MSG_PEEK 0x2 /* peek at incoming message */ | |
528 | #define MSG_DONTROUTE 0x4 /* send without using routing tables */ | |
529 | #define MSG_EOR 0x8 /* data completes record */ | |
530 | #define MSG_TRUNC 0x10 /* data discarded before delivery */ | |
531 | #define MSG_CTRUNC 0x20 /* control data lost before delivery */ | |
532 | #define MSG_WAITALL 0x40 /* wait for full request or error */ | |
2d21ac55 | 533 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b A |
534 | #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ |
535 | #define MSG_EOF 0x100 /* data completes connection */ | |
9bccf70c | 536 | #ifdef __APPLE__ |
55e303ae | 537 | #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */ |
1c79356b A |
538 | #define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp */ |
539 | #define MSG_HOLD 0x800 /* Hold frag in so_temp */ | |
540 | #define MSG_SEND 0x1000 /* Send the packet in so_temp */ | |
541 | #define MSG_HAVEMORE 0x2000 /* Data ready to be read */ | |
542 | #define MSG_RCVMORE 0x4000 /* Data remains in current pkt */ | |
9bccf70c | 543 | #endif |
2d21ac55 A |
544 | #ifdef KERNEL_PRIVATE |
545 | #define MSG_COMPAT 0x8000 /* deprecated */ | |
546 | #endif /* KERNEL_PRIVATE */ | |
4a249263 | 547 | #define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */ |
91447636 A |
548 | #ifdef KERNEL_PRIVATE |
549 | #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */ | |
550 | #endif | |
551 | #ifdef KERNEL | |
552 | #define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */ | |
553 | #endif | |
2d21ac55 | 554 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b A |
555 | |
556 | /* | |
557 | * Header for ancillary data objects in msg_control buffer. | |
558 | * Used for additional information with/about a datagram | |
559 | * not expressible by flags. The format is a sequence | |
560 | * of message elements headed by cmsghdr structures. | |
561 | */ | |
562 | struct cmsghdr { | |
91447636 A |
563 | socklen_t cmsg_len; /* [XSI] data byte count, including hdr */ |
564 | int cmsg_level; /* [XSI] originating protocol */ | |
565 | int cmsg_type; /* [XSI] protocol-specific type */ | |
566 | /* followed by unsigned char cmsg_data[]; */ | |
1c79356b A |
567 | }; |
568 | ||
2d21ac55 | 569 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
9bccf70c A |
570 | #ifndef __APPLE__ |
571 | /* | |
572 | * While we may have more groups than this, the cmsgcred struct must | |
573 | * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow | |
574 | * this. | |
575 | */ | |
576 | #define CMGROUP_MAX 16 | |
1c79356b | 577 | |
9bccf70c A |
578 | /* |
579 | * Credentials structure, used to verify the identity of a peer | |
580 | * process that has sent us a message. This is allocated by the | |
581 | * peer process but filled in by the kernel. This prevents the | |
582 | * peer from lying about its identity. (Note that cmcred_groups[0] | |
583 | * is the effective GID.) | |
1c79356b | 584 | */ |
9bccf70c A |
585 | struct cmsgcred { |
586 | pid_t cmcred_pid; /* PID of sending process */ | |
587 | uid_t cmcred_uid; /* real UID of sending process */ | |
588 | uid_t cmcred_euid; /* effective UID of sending process */ | |
589 | gid_t cmcred_gid; /* real GID of sending process */ | |
590 | short cmcred_ngroups; /* number or groups */ | |
591 | gid_t cmcred_groups[CMGROUP_MAX]; /* groups */ | |
592 | }; | |
593 | #endif | |
2d21ac55 | 594 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
9bccf70c A |
595 | |
596 | /* given pointer to struct cmsghdr, return pointer to data */ | |
91447636 | 597 | #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ |
2d21ac55 | 598 | __DARWIN_ALIGN(sizeof(struct cmsghdr))) |
1c79356b A |
599 | |
600 | /* given pointer to struct cmsghdr, return pointer to next cmsghdr */ | |
601 | #define CMSG_NXTHDR(mhdr, cmsg) \ | |
2d21ac55 A |
602 | (((unsigned char *)(cmsg) + __DARWIN_ALIGN((__darwin_intptr_t)(cmsg)->cmsg_len) + \ |
603 | __DARWIN_ALIGN(sizeof(struct cmsghdr)) > \ | |
91447636 | 604 | (unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \ |
2d21ac55 A |
605 | (struct cmsghdr *)0L /* NULL */ : \ |
606 | (struct cmsghdr *)((unsigned char *)(cmsg) + __DARWIN_ALIGN((__darwin_intptr_t)(cmsg)->cmsg_len))) | |
1c79356b A |
607 | |
608 | #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control) | |
609 | ||
2d21ac55 | 610 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
9bccf70c | 611 | /* RFC 2292 additions */ |
2d21ac55 A |
612 | #define CMSG_SPACE(l) (__DARWIN_ALIGN(sizeof(struct cmsghdr)) + __DARWIN_ALIGN(l)) |
613 | #define CMSG_LEN(l) (__DARWIN_ALIGN(sizeof(struct cmsghdr)) + (l)) | |
9bccf70c A |
614 | |
615 | #ifdef KERNEL | |
2d21ac55 | 616 | #define CMSG_ALIGN(n) __DARWIN_ALIGN(n) |
9bccf70c | 617 | #endif |
2d21ac55 | 618 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ |
1c79356b A |
619 | |
620 | /* "Socket"-level control message types: */ | |
621 | #define SCM_RIGHTS 0x01 /* access rights (array of int) */ | |
2d21ac55 | 622 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) |
1c79356b A |
623 | #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */ |
624 | #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */ | |
625 | ||
2d21ac55 | 626 | #ifdef KERNEL_PRIVATE |
1c79356b | 627 | /* |
2d21ac55 | 628 | * 4.3 compat sockaddr (deprecated) |
1c79356b A |
629 | */ |
630 | struct osockaddr { | |
91447636 | 631 | __uint16_t sa_family; /* address family */ |
1c79356b A |
632 | char sa_data[14]; /* up to 14 bytes of direct address */ |
633 | }; | |
634 | ||
635 | /* | |
2d21ac55 | 636 | * 4.3-compat message header (deprecated) |
1c79356b A |
637 | */ |
638 | struct omsghdr { | |
91447636 A |
639 | void *msg_name; /* optional address */ |
640 | socklen_t msg_namelen; /* size of address */ | |
641 | struct iovec *msg_iov; /* scatter/gather array */ | |
642 | int msg_iovlen; /* # elements in msg_iov */ | |
643 | void *msg_accrights; /* access rights sent/rcvd */ | |
644 | int msg_accrightslen; | |
1c79356b | 645 | }; |
2d21ac55 A |
646 | #endif /* KERNEL_PRIVATE */ |
647 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ | |
1c79356b A |
648 | |
649 | /* | |
650 | * howto arguments for shutdown(2), specified by Posix.1g. | |
651 | */ | |
652 | #define SHUT_RD 0 /* shut down the reading side */ | |
653 | #define SHUT_WR 1 /* shut down the writing side */ | |
654 | #define SHUT_RDWR 2 /* shut down both sides */ | |
655 | ||
2d21ac55 | 656 | #if !defined(_POSIX_C_SOURCE) |
1c79356b A |
657 | /* |
658 | * sendfile(2) header/trailer struct | |
659 | */ | |
660 | struct sf_hdtr { | |
661 | struct iovec *headers; /* pointer to an array of header struct iovec's */ | |
662 | int hdr_cnt; /* number of header iovec's */ | |
663 | struct iovec *trailers; /* pointer to an array of trailer struct iovec's */ | |
664 | int trl_cnt; /* number of trailer iovec's */ | |
665 | }; | |
2d21ac55 A |
666 | |
667 | #ifdef KERNEL | |
668 | ||
669 | struct user_sf_hdtr { | |
670 | user_addr_t headers __attribute((aligned(8))); /* pointer to an array of header struct iovec's */ | |
671 | int hdr_cnt; /* number of header iovec's */ | |
672 | user_addr_t trailers __attribute((aligned(8))); /* pointer to an array of trailer struct iovec's */ | |
673 | int trl_cnt; /* number of trailer iovec's */ | |
674 | }; | |
675 | ||
676 | ||
677 | #endif /* KERNEL */ | |
678 | ||
91447636 | 679 | #endif /* !_POSIX_C_SOURCE */ |
1c79356b A |
680 | |
681 | #ifndef KERNEL | |
1c79356b | 682 | __BEGIN_DECLS |
91447636 | 683 | int accept(int, struct sockaddr * __restrict, socklen_t * __restrict) |
2d21ac55 | 684 | __DARWIN_ALIAS_C(accept); |
91447636 | 685 | int bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind); |
2d21ac55 | 686 | int connect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C( connect); |
91447636 A |
687 | int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict) |
688 | __DARWIN_ALIAS(getpeername); | |
689 | int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict) | |
690 | __DARWIN_ALIAS(getsockname); | |
691 | int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict); | |
692 | int listen(int, int) __DARWIN_ALIAS(listen); | |
2d21ac55 | 693 | ssize_t recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv); |
91447636 | 694 | ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict, |
2d21ac55 A |
695 | socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom); |
696 | ssize_t recvmsg(int, struct msghdr *, int) __DARWIN_ALIAS_C(recvmsg); | |
697 | ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send); | |
698 | ssize_t sendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS_C(sendmsg); | |
91447636 | 699 | ssize_t sendto(int, const void *, size_t, |
2d21ac55 | 700 | int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(sendto); |
91447636 A |
701 | int setsockopt(int, int, int, const void *, socklen_t); |
702 | int shutdown(int, int); | |
2d21ac55 | 703 | int sockatmark(int); |
91447636 A |
704 | int socket(int, int, int); |
705 | int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair); | |
91447636 | 706 | |
2d21ac55 A |
707 | #if !defined(_POSIX_C_SOURCE) |
708 | int sendfile(int, int, off_t, off_t *, struct sf_hdtr *, int); | |
91447636 | 709 | #endif /* !_POSIX_C_SOURCE */ |
2d21ac55 A |
710 | |
711 | #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) | |
712 | void pfctlinput(int, struct sockaddr *); | |
713 | #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ | |
1c79356b A |
714 | __END_DECLS |
715 | ||
716 | #endif /* !KERNEL */ | |
9bccf70c | 717 | |
91447636 A |
718 | #ifdef KERNEL |
719 | #include <sys/kpi_socket.h> | |
720 | #endif | |
721 | ||
1c79356b | 722 | #endif /* !_SYS_SOCKET_H_ */ |