]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/socket.h
xnu-1699.24.8.tar.gz
[apple/xnu.git] / bsd / sys / socket.h
1 /*
2 * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
63 * $FreeBSD: src/sys/sys/socket.h,v 1.39.2.7 2001/07/03 11:02:01 ume Exp $
64 */
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 */
71
72 #ifndef _SYS_SOCKET_H_
73 #define _SYS_SOCKET_H_
74
75 #include <sys/types.h>
76 #include <sys/cdefs.h>
77 #include <machine/_param.h>
78
79 #ifdef PRIVATE
80 #include <sys/param.h>
81 #endif /* PRIVATE */
82
83 #ifndef KERNEL
84 #include <Availability.h>
85 #endif
86
87 /*
88 * Definitions related to sockets: types, address families, options.
89 */
90
91 /*
92 * Data types.
93 */
94 #ifndef _GID_T
95 typedef __darwin_gid_t gid_t;
96 #define _GID_T
97 #endif
98
99 #ifndef _OFF_T
100 typedef __darwin_off_t off_t;
101 #define _OFF_T
102 #endif
103
104 #ifndef _PID_T
105 typedef __darwin_pid_t pid_t;
106 #define _PID_T
107 #endif
108
109 #ifndef _SA_FAMILY_T
110 #define _SA_FAMILY_T
111 typedef __uint8_t sa_family_t;
112 #endif
113
114 #ifndef _SOCKLEN_T
115 #define _SOCKLEN_T
116 typedef __darwin_socklen_t socklen_t;
117 #endif
118
119 /* XXX Not explicitly defined by POSIX, but function return types are */
120 #ifndef _SIZE_T
121 #define _SIZE_T
122 typedef __darwin_size_t size_t;
123 #endif
124
125 /* XXX Not explicitly defined by POSIX, but function return types are */
126 #ifndef _SSIZE_T
127 #define _SSIZE_T
128 typedef __darwin_ssize_t ssize_t;
129 #endif
130
131 /*
132 * [XSI] The iovec structure shall be defined as described in <sys/uio.h>.
133 */
134 #ifndef _STRUCT_IOVEC
135 #define _STRUCT_IOVEC
136 struct iovec {
137 void * iov_base; /* [XSI] Base address of I/O memory region */
138 size_t iov_len; /* [XSI] Size of region iov_base points to */
139 };
140 #endif
141
142 #ifdef PRIVATE
143 #define SO_TCDBG_PID 0x01 /* Set/get traffic class for PID */
144 #define SO_TCDBG_PNAME 0x02 /* Set/get traffic class for processes of that name */
145 #define SO_TCDBG_PURGE 0x04 /* Purge entries for unused PIDs */
146 #define SO_TCDBG_FLUSH 0x08 /* Flush all entries */
147 #define SO_TCDBG_COUNT 0x10 /* Get count of entries */
148 #define SO_TCDBG_LIST 0x20 /* List entries */
149
150 struct so_tcdbg {
151 u_int32_t so_tcdbg_cmd;
152 int32_t so_tcdbg_tclass;
153 u_int32_t so_tcdbg_count;
154 pid_t so_tcdbg_pid;
155 char so_tcdbg_pname[MAXCOMLEN + 1];
156 };
157 #endif /* PRIVATE */
158
159 /*
160 * Types
161 */
162 #define SOCK_STREAM 1 /* stream socket */
163 #define SOCK_DGRAM 2 /* datagram socket */
164 #define SOCK_RAW 3 /* raw-protocol interface */
165 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
166 #define SOCK_RDM 4 /* reliably-delivered message */
167 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
168 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
169
170 /*
171 * Option flags per-socket.
172 */
173 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
174 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
175 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
176 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
177 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
178 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
179 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
180 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
181 #define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */
182 #else
183 #define SO_LINGER 0x1080 /* linger on close if data present (in seconds) */
184 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
185 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
186 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
187 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
188 #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
189 #define SO_TIMESTAMP_MONOTONIC 0x0800 /* Monotonically increasing timestamp on rcvd dgram */
190 #ifndef __APPLE__
191 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
192 #else
193 #define SO_DONTTRUNC 0x2000 /* APPLE: Retain unread data */
194 /* (ATOMIC proto) */
195 #define SO_WANTMORE 0x4000 /* APPLE: Give hint when more data ready */
196 #define SO_WANTOOBFLAG 0x8000 /* APPLE: Want OOB in MSG_FLAG on receive */
197 #endif
198 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
199
200 /*
201 * Additional options, not kept in so_options.
202 */
203 #define SO_SNDBUF 0x1001 /* send buffer size */
204 #define SO_RCVBUF 0x1002 /* receive buffer size */
205 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
206 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
207 #define SO_SNDTIMEO 0x1005 /* send timeout */
208 #define SO_RCVTIMEO 0x1006 /* receive timeout */
209 #define SO_ERROR 0x1007 /* get error status and clear */
210 #define SO_TYPE 0x1008 /* get socket type */
211 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
212 /*efine SO_PRIVSTATE 0x1009 get/deny privileged state */
213 #define SO_LABEL 0x1010 /* socket's MAC label */
214 #define SO_PEERLABEL 0x1011 /* socket's peer MAC label */
215 #ifdef __APPLE__
216 #define SO_NREAD 0x1020 /* APPLE: get 1st-packet byte count */
217 #define SO_NKE 0x1021 /* APPLE: Install socket-level NKE */
218 #define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */
219 #define SO_NOADDRERR 0x1023 /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
220 #define SO_NWRITE 0x1024 /* APPLE: Get number of bytes currently in send socket buffer */
221 #define SO_REUSESHAREUID 0x1025 /* APPLE: Allow reuse of port/socket by different userids */
222 #ifdef __APPLE_API_PRIVATE
223 #define SO_NOTIFYCONFLICT 0x1026 /* APPLE: send notification if there is a bind on a port which is already in use */
224 #define SO_UPCALLCLOSEWAIT 0x1027 /* APPLE: block on close until an upcall returns */
225 #endif
226 #define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */
227 #define SO_RESTRICTIONS 0x1081 /* APPLE: deny inbound/outbound/both/flag set */
228 #define SO_RESTRICT_DENYIN 0x00000001 /* flag for SO_RESTRICTIONS - deny inbound */
229 #define SO_RESTRICT_DENYOUT 0x00000002 /* flag for SO_RESTRICTIONS - deny outbound */
230 #define SO_RESTRICT_DENYSET 0x80000000 /* flag for SO_RESTRICTIONS - deny has been set */
231 #define SO_RANDOMPORT 0x1082 /* APPLE: request local port randomization */
232 #define SO_NP_EXTENSIONS 0x1083 /* To turn off some POSIX behavior */
233 #endif
234
235 #ifdef PRIVATE
236 #define SO_EXECPATH 0x1085 /* Application Firewall Socket option */
237 #define SO_TRAFFIC_CLASS 0x1086 /* Traffic class (int)*/
238 #define SO_TC_BE 0 /* Best effort, normal */
239 #define SO_TC_BK 1 /* Background, low priority or bulk traffic */
240 #define SO_TC_VI 2 /* Interactive video, constant bit rate, low latency */
241 #define SO_TC_VO 3 /* Interactive voice, constant bit rate, lowest latency */
242 #define SO_TC_MAX 4 /* Max traffic class value */
243
244 /* Background socket configuration flags */
245 #define TRAFFIC_MGT_SO_BACKGROUND 0x0001 /* background socket */
246 #define TRAFFIC_MGT_TCP_RECVBG 0x0002 /* Only TCP sockets, receiver throttling */
247
248 #define SO_RECV_TRAFFIC_CLASS 0x1087 /* Receive traffic class (bool)*/
249 #define SO_TRAFFIC_CLASS_DBG 0x1088 /* Debug traffic class (struct so_tcdbg) */
250 #define SO_TRAFFIC_CLASS_STATS 0x1089 /* Traffic class statistics */
251 #define SO_DEFUNCTOK 0x1100 /* can be defunct'd */
252 #define SO_ISDEFUNCT 0x1101 /* get defunct status */
253 #endif /* PRIVATE */
254 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
255
256 /*
257 * Structure used for manipulating linger option.
258 */
259 struct linger {
260 int l_onoff; /* option on/off */
261 int l_linger; /* linger time */
262 };
263
264 #ifndef __APPLE__
265 struct accept_filter_arg {
266 char af_name[16];
267 char af_arg[256-16];
268 };
269 #endif
270
271 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
272 #ifdef __APPLE__
273
274 /*
275 * Structure to control non-portable Sockets extension to POSIX
276 */
277 struct so_np_extensions {
278 u_int32_t npx_flags;
279 u_int32_t npx_mask;
280 };
281
282 #define SONPX_SETOPTSHUT 0x000000001 /* flag for allowing setsockopt after shutdown */
283
284
285 #ifdef KERNEL_PRIVATE
286 #define SONPX_MASK_VALID (SONPX_SETOPTSHUT)
287 #endif
288
289 #endif
290 #endif
291
292 /*
293 * Level number for (get/set)sockopt() to apply to socket itself.
294 */
295 #define SOL_SOCKET 0xffff /* options for socket level */
296
297
298 /*
299 * Address families.
300 */
301 #define AF_UNSPEC 0 /* unspecified */
302 #define AF_UNIX 1 /* local to host (pipes) */
303 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
304 #define AF_LOCAL AF_UNIX /* backward compatibility */
305 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
306 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
307 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
308 #define AF_IMPLINK 3 /* arpanet imp addresses */
309 #define AF_PUP 4 /* pup protocols: e.g. BSP */
310 #define AF_CHAOS 5 /* mit CHAOS protocols */
311 #define AF_NS 6 /* XEROX NS protocols */
312 #define AF_ISO 7 /* ISO protocols */
313 #define AF_OSI AF_ISO
314 #define AF_ECMA 8 /* European computer manufacturers */
315 #define AF_DATAKIT 9 /* datakit protocols */
316 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
317 #define AF_SNA 11 /* IBM SNA */
318 #define AF_DECnet 12 /* DECnet */
319 #define AF_DLI 13 /* DEC Direct data link interface */
320 #define AF_LAT 14 /* LAT */
321 #define AF_HYLINK 15 /* NSC Hyperchannel */
322 #define AF_APPLETALK 16 /* Apple Talk */
323 #define AF_ROUTE 17 /* Internal Routing Protocol */
324 #define AF_LINK 18 /* Link layer interface */
325 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
326 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
327 #define AF_CNT 21 /* Computer Network Technology */
328 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
329 #define AF_IPX 23 /* Novell Internet Protocol */
330 #define AF_SIP 24 /* Simple Internet Protocol */
331 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
332 #ifdef __APPLE__
333 /*define pseudo_AF_BLUE 26 Identify packets for Blue Box - Not used */
334 #define AF_NDRV 27 /* Network Driver 'raw' access */
335 #endif
336 #define AF_ISDN 28 /* Integrated Services Digital Network*/
337 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
338 #define pseudo_AF_KEY 29 /* Internal key-management function */
339 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
340 #define AF_INET6 30 /* IPv6 */
341 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
342 #define AF_NATM 31 /* native ATM access */
343 #ifdef __APPLE__
344 #define AF_SYSTEM 32 /* Kernel event messages */
345 #define AF_NETBIOS 33 /* NetBIOS */
346 #define AF_PPP 34 /* PPP communication protocol */
347 #else
348 #define AF_ATM 30 /* ATM */
349 #endif
350 #define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers
351 * in interface output routine
352 */
353 #ifdef PRIVATE
354 #define AF_AFP 36 /* Used by AFP */
355 #else
356 #define AF_RESERVED_36 36 /* Reserved for internal usage */
357 #endif
358
359 #ifndef __APPLE__
360 #define AF_NETGRAPH 32 /* Netgraph sockets */
361 #endif
362 #define AF_IEEE80211 37 /* IEEE 802.11 protocol */
363 #define AF_MAX 38
364 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
365
366 /*
367 * [XSI] Structure used by kernel to store most addresses.
368 */
369 struct sockaddr {
370 __uint8_t sa_len; /* total length */
371 sa_family_t sa_family; /* [XSI] address family */
372 char sa_data[14]; /* [XSI] addr value (actually larger) */
373 };
374
375 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
376 #define SOCK_MAXADDRLEN 255 /* longest possible addresses */
377
378 /*
379 * Structure used by kernel to pass protocol
380 * information in raw sockets.
381 */
382 struct sockproto {
383 __uint16_t sp_family; /* address family */
384 __uint16_t sp_protocol; /* protocol */
385 };
386 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE)*/
387
388 /*
389 * RFC 2553: protocol-independent placeholder for socket addresses
390 */
391 #define _SS_MAXSIZE 128
392 #define _SS_ALIGNSIZE (sizeof(__int64_t))
393 #define _SS_PAD1SIZE \
394 (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
395 #define _SS_PAD2SIZE \
396 (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
397 _SS_PAD1SIZE - _SS_ALIGNSIZE)
398
399 /*
400 * [XSI] sockaddr_storage
401 */
402 struct sockaddr_storage {
403 __uint8_t ss_len; /* address length */
404 sa_family_t ss_family; /* [XSI] address family */
405 char __ss_pad1[_SS_PAD1SIZE];
406 __int64_t __ss_align; /* force structure storage alignment */
407 char __ss_pad2[_SS_PAD2SIZE];
408 };
409
410 /*
411 * Protocol families, same as address families for now.
412 */
413 #define PF_UNSPEC AF_UNSPEC
414 #define PF_LOCAL AF_LOCAL
415 #define PF_UNIX PF_LOCAL /* backward compatibility */
416 #define PF_INET AF_INET
417 #define PF_IMPLINK AF_IMPLINK
418 #define PF_PUP AF_PUP
419 #define PF_CHAOS AF_CHAOS
420 #define PF_NS AF_NS
421 #define PF_ISO AF_ISO
422 #define PF_OSI AF_ISO
423 #define PF_ECMA AF_ECMA
424 #define PF_DATAKIT AF_DATAKIT
425 #define PF_CCITT AF_CCITT
426 #define PF_SNA AF_SNA
427 #define PF_DECnet AF_DECnet
428 #define PF_DLI AF_DLI
429 #define PF_LAT AF_LAT
430 #define PF_HYLINK AF_HYLINK
431 #define PF_APPLETALK AF_APPLETALK
432 #define PF_ROUTE AF_ROUTE
433 #define PF_LINK AF_LINK
434 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
435 #define PF_COIP AF_COIP
436 #define PF_CNT AF_CNT
437 #define PF_SIP AF_SIP
438 #define PF_IPX AF_IPX /* same format as AF_NS */
439 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
440 #define PF_PIP pseudo_AF_PIP
441 #ifdef __APPLE__
442 #define PF_NDRV AF_NDRV
443 #endif
444 #define PF_ISDN AF_ISDN
445 #define PF_KEY pseudo_AF_KEY
446 #define PF_INET6 AF_INET6
447 #define PF_NATM AF_NATM
448 #ifdef __APPLE__
449 #define PF_SYSTEM AF_SYSTEM
450 #define PF_NETBIOS AF_NETBIOS
451 #define PF_PPP AF_PPP
452 #ifdef PRIVATE
453 #define PF_AFP AF_AFP
454 #else
455 #define PF_RESERVED_36 AF_RESERVED_36
456 #endif
457
458 #else
459 #define PF_ATM AF_ATM
460 #define PF_NETGRAPH AF_NETGRAPH
461 #endif
462
463 #define PF_MAX AF_MAX
464
465 /*
466 * These do not have socket-layer support:
467 */
468 #define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */
469 #define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */
470 #ifdef KERNEL_PRIVATE
471 #define PF_BRIDGE ((uint32_t)0x62726467) /* 'brdg' */
472 #endif /* KERNEL_PRIVATE */
473
474 /*
475 * Definitions for network related sysctl, CTL_NET.
476 *
477 * Second level is protocol family.
478 * Third level is protocol number.
479 *
480 * Further levels are defined by the individual families below.
481 */
482 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
483 #define NET_MAXID AF_MAX
484 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
485
486 #ifdef KERNEL_PRIVATE
487 #define CTL_NET_NAMES { \
488 { 0, 0 }, \
489 { "local", CTLTYPE_NODE }, \
490 { "inet", CTLTYPE_NODE }, \
491 { "implink", CTLTYPE_NODE }, \
492 { "pup", CTLTYPE_NODE }, \
493 { "chaos", CTLTYPE_NODE }, \
494 { "xerox_ns", CTLTYPE_NODE }, \
495 { "iso", CTLTYPE_NODE }, \
496 { "emca", CTLTYPE_NODE }, \
497 { "datakit", CTLTYPE_NODE }, \
498 { "ccitt", CTLTYPE_NODE }, \
499 { "ibm_sna", CTLTYPE_NODE }, \
500 { "decnet", CTLTYPE_NODE }, \
501 { "dec_dli", CTLTYPE_NODE }, \
502 { "lat", CTLTYPE_NODE }, \
503 { "hylink", CTLTYPE_NODE }, \
504 { "appletalk", CTLTYPE_NODE }, \
505 { "route", CTLTYPE_NODE }, \
506 { "link_layer", CTLTYPE_NODE }, \
507 { "xtp", CTLTYPE_NODE }, \
508 { "coip", CTLTYPE_NODE }, \
509 { "cnt", CTLTYPE_NODE }, \
510 { "rtip", CTLTYPE_NODE }, \
511 { "ipx", CTLTYPE_NODE }, \
512 { "sip", CTLTYPE_NODE }, \
513 { "pip", CTLTYPE_NODE }, \
514 { 0, 0 }, \
515 { "ndrv", CTLTYPE_NODE }, \
516 { "isdn", CTLTYPE_NODE }, \
517 { "key", CTLTYPE_NODE }, \
518 { "inet6", CTLTYPE_NODE }, \
519 { "natm", CTLTYPE_NODE }, \
520 { "sys", CTLTYPE_NODE }, \
521 { "netbios", CTLTYPE_NODE }, \
522 { "ppp", CTLTYPE_NODE }, \
523 { "hdrcomplete", CTLTYPE_NODE }, \
524 }
525 #endif /* KERNEL_PRIVATE */
526
527 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
528 /*
529 * PF_ROUTE - Routing table
530 *
531 * Three additional levels are defined:
532 * Fourth: address family, 0 is wildcard
533 * Fifth: type of info, defined below
534 * Sixth: flag(s) to mask with for NET_RT_FLAGS
535 */
536 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
537 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
538 #define NET_RT_IFLIST 3 /* survey interface list */
539 #define NET_RT_STAT 4 /* routing statistics */
540 #define NET_RT_TRASH 5 /* routes not in table but not freed */
541 #define NET_RT_IFLIST2 6 /* interface list with addresses */
542 #define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
543 #ifdef PRIVATE
544 #define NET_RT_DUMPX 8 /* private */
545 #define NET_RT_DUMPX_FLAGS 9 /* private */
546 #endif /* PRIVATE */
547 #define NET_RT_MAXID 10
548 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
549
550 #ifdef KERNEL_PRIVATE
551 #define CTL_NET_RT_NAMES { \
552 { 0, 0 }, \
553 { "dump", CTLTYPE_STRUCT }, \
554 { "flags", CTLTYPE_STRUCT }, \
555 { "iflist", CTLTYPE_STRUCT }, \
556 { "stat", CTLTYPE_STRUCT }, \
557 { "trash", CTLTYPE_INT }, \
558 { "iflist2", CTLTYPE_STRUCT }, \
559 { "dump2", CTLTYPE_STRUCT }, \
560 { "dumpx", CTLTYPE_STRUCT }, \
561 { "dumpx_flags", CTLTYPE_STRUCT }, \
562 }
563
564 #endif /* KERNEL_PRIVATE */
565
566 /*
567 * Maximum queue length specifiable by listen.
568 */
569 #define SOMAXCONN 128
570
571 /*
572 * [XSI] Message header for recvmsg and sendmsg calls.
573 * Used value-result for recvmsg, value only for sendmsg.
574 */
575 struct msghdr {
576 void *msg_name; /* [XSI] optional address */
577 socklen_t msg_namelen; /* [XSI] size of address */
578 struct iovec *msg_iov; /* [XSI] scatter/gather array */
579 int msg_iovlen; /* [XSI] # elements in msg_iov */
580 void *msg_control; /* [XSI] ancillary data, see below */
581 socklen_t msg_controllen; /* [XSI] ancillary data buffer len */
582 int msg_flags; /* [XSI] flags on received message */
583 };
584
585 #ifdef KERNEL
586 /*
587 * In-kernel representation of "struct msghdr" from
588 * userspace. Has enough precision for 32-bit or
589 * 64-bit clients, but does not need to be packed.
590 */
591
592 struct user_msghdr {
593 user_addr_t msg_name; /* optional address */
594 socklen_t msg_namelen; /* size of address */
595 user_addr_t msg_iov; /* scatter/gather array */
596 int msg_iovlen; /* # elements in msg_iov */
597 user_addr_t msg_control; /* ancillary data, see below */
598 socklen_t msg_controllen; /* ancillary data buffer len */
599 int msg_flags; /* flags on received message */
600 };
601
602 /*
603 * LP64 user version of struct msghdr.
604 * WARNING - keep in sync with struct msghdr
605 */
606
607 struct user64_msghdr {
608 user64_addr_t msg_name; /* optional address */
609 socklen_t msg_namelen; /* size of address */
610 user64_addr_t msg_iov; /* scatter/gather array */
611 int msg_iovlen; /* # elements in msg_iov */
612 user64_addr_t msg_control; /* ancillary data, see below */
613 socklen_t msg_controllen; /* ancillary data buffer len */
614 int msg_flags; /* flags on received message */
615 };
616
617 /*
618 * ILP32 user version of struct msghdr.
619 * WARNING - keep in sync with struct msghdr
620 */
621
622 struct user32_msghdr {
623 user32_addr_t msg_name; /* optional address */
624 socklen_t msg_namelen; /* size of address */
625 user32_addr_t msg_iov; /* scatter/gather array */
626 int msg_iovlen; /* # elements in msg_iov */
627 user32_addr_t msg_control; /* ancillary data, see below */
628 socklen_t msg_controllen; /* ancillary data buffer len */
629 int msg_flags; /* flags on received message */
630 };
631
632 #endif // KERNEL
633
634 #define MSG_OOB 0x1 /* process out-of-band data */
635 #define MSG_PEEK 0x2 /* peek at incoming message */
636 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
637 #define MSG_EOR 0x8 /* data completes record */
638 #define MSG_TRUNC 0x10 /* data discarded before delivery */
639 #define MSG_CTRUNC 0x20 /* control data lost before delivery */
640 #define MSG_WAITALL 0x40 /* wait for full request or error */
641 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
642 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
643 #define MSG_EOF 0x100 /* data completes connection */
644 #ifdef __APPLE__
645 #ifndef PRIVATE
646 #ifdef __APPLE_API_OBSOLETE
647 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
648 #endif
649 #else
650 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
651 #endif
652 #define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp */
653 #define MSG_HOLD 0x800 /* Hold frag in so_temp */
654 #define MSG_SEND 0x1000 /* Send the packet in so_temp */
655 #define MSG_HAVEMORE 0x2000 /* Data ready to be read */
656 #define MSG_RCVMORE 0x4000 /* Data remains in current pkt */
657 #endif
658 #ifdef KERNEL_PRIVATE
659 #define MSG_COMPAT 0x8000 /* deprecated */
660 #endif /* KERNEL_PRIVATE */
661 #define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */
662 #ifdef KERNEL_PRIVATE
663 #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */
664 #endif
665 #ifdef KERNEL
666 #define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */
667 #endif
668 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
669
670 /*
671 * Header for ancillary data objects in msg_control buffer.
672 * Used for additional information with/about a datagram
673 * not expressible by flags. The format is a sequence
674 * of message elements headed by cmsghdr structures.
675 */
676 struct cmsghdr {
677 socklen_t cmsg_len; /* [XSI] data byte count, including hdr */
678 int cmsg_level; /* [XSI] originating protocol */
679 int cmsg_type; /* [XSI] protocol-specific type */
680 /* followed by unsigned char cmsg_data[]; */
681 };
682
683 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
684 #ifndef __APPLE__
685 /*
686 * While we may have more groups than this, the cmsgcred struct must
687 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
688 * this.
689 */
690 #define CMGROUP_MAX 16
691
692 /*
693 * Credentials structure, used to verify the identity of a peer
694 * process that has sent us a message. This is allocated by the
695 * peer process but filled in by the kernel. This prevents the
696 * peer from lying about its identity. (Note that cmcred_groups[0]
697 * is the effective GID.)
698 */
699 struct cmsgcred {
700 pid_t cmcred_pid; /* PID of sending process */
701 uid_t cmcred_uid; /* real UID of sending process */
702 uid_t cmcred_euid; /* effective UID of sending process */
703 gid_t cmcred_gid; /* real GID of sending process */
704 short cmcred_ngroups; /* number or groups */
705 gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
706 };
707 #endif
708 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
709
710 /* given pointer to struct cmsghdr, return pointer to data */
711 #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
712 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
713
714 /*
715 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
716 * an empty list for some reasons.
717 */
718 #define CMSG_FIRSTHDR(mhdr) \
719 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
720 (struct cmsghdr *)(mhdr)->msg_control : \
721 (struct cmsghdr *)0L)
722
723
724 /*
725 * Given pointer to struct cmsghdr, return pointer to next cmsghdr
726 * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
727 */
728 #define CMSG_NXTHDR(mhdr, cmsg) \
729 ((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) : \
730 ((((unsigned char *)(cmsg) + \
731 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \
732 __DARWIN_ALIGN32(sizeof(struct cmsghdr))) > \
733 ((unsigned char *)(mhdr)->msg_control + \
734 (mhdr)->msg_controllen)) ? \
735 (struct cmsghdr *)0L /* NULL */ : \
736 (struct cmsghdr *)(void *)((unsigned char *)(cmsg) + \
737 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
738
739 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
740 /* RFC 2292 additions */
741 #define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
742 #define CMSG_LEN(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
743
744 #ifdef KERNEL
745 #define CMSG_ALIGN(n) __DARWIN_ALIGN32(n)
746 #endif
747 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
748
749 /* "Socket"-level control message types: */
750 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
751 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
752 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
753 #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
754 #define SCM_TIMESTAMP_MONOTONIC 0x04 /* timestamp (uint64_t) */
755
756 #ifdef KERNEL_PRIVATE
757 /*
758 * 4.3 compat sockaddr (deprecated)
759 */
760 struct osockaddr {
761 __uint16_t sa_family; /* address family */
762 char sa_data[14]; /* up to 14 bytes of direct address */
763 };
764
765 /*
766 * 4.3-compat message header (deprecated)
767 */
768 struct omsghdr {
769 void *msg_name; /* optional address */
770 socklen_t msg_namelen; /* size of address */
771 struct iovec *msg_iov; /* scatter/gather array */
772 int msg_iovlen; /* # elements in msg_iov */
773 void *msg_accrights; /* access rights sent/rcvd */
774 int msg_accrightslen;
775 };
776 #endif /* KERNEL_PRIVATE */
777 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
778
779 /*
780 * howto arguments for shutdown(2), specified by Posix.1g.
781 */
782 #define SHUT_RD 0 /* shut down the reading side */
783 #define SHUT_WR 1 /* shut down the writing side */
784 #define SHUT_RDWR 2 /* shut down both sides */
785
786 #if !defined(_POSIX_C_SOURCE)
787 /*
788 * sendfile(2) header/trailer struct
789 */
790 struct sf_hdtr {
791 struct iovec *headers; /* pointer to an array of header struct iovec's */
792 int hdr_cnt; /* number of header iovec's */
793 struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
794 int trl_cnt; /* number of trailer iovec's */
795 };
796
797 #ifdef KERNEL
798
799 /* In-kernel representation */
800 struct user_sf_hdtr {
801 user_addr_t headers; /* pointer to an array of header struct iovec's */
802 int hdr_cnt; /* number of header iovec's */
803 user_addr_t trailers; /* pointer to an array of trailer struct iovec's */
804 int trl_cnt; /* number of trailer iovec's */
805 };
806
807 /* LP64 user version of struct sf_hdtr */
808 struct user64_sf_hdtr {
809 user64_addr_t headers; /* pointer to an array of header struct iovec's */
810 int hdr_cnt; /* number of header iovec's */
811 user64_addr_t trailers; /* pointer to an array of trailer struct iovec's */
812 int trl_cnt; /* number of trailer iovec's */
813 };
814
815 /* ILP32 user version of struct sf_hdtr */
816 struct user32_sf_hdtr {
817 user32_addr_t headers; /* pointer to an array of header struct iovec's */
818 int hdr_cnt; /* number of header iovec's */
819 user32_addr_t trailers; /* pointer to an array of trailer struct iovec's */
820 int trl_cnt; /* number of trailer iovec's */
821 };
822
823 #endif /* KERNEL */
824
825 #endif /* !_POSIX_C_SOURCE */
826
827 #ifndef KERNEL
828 __BEGIN_DECLS
829 int accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
830 __DARWIN_ALIAS_C(accept);
831 int bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
832 int connect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C( connect);
833 int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
834 __DARWIN_ALIAS(getpeername);
835 int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
836 __DARWIN_ALIAS(getsockname);
837 int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
838 int listen(int, int) __DARWIN_ALIAS(listen);
839 ssize_t recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv);
840 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict,
841 socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
842 ssize_t recvmsg(int, struct msghdr *, int) __DARWIN_ALIAS_C(recvmsg);
843 ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);
844 ssize_t sendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS_C(sendmsg);
845 ssize_t sendto(int, const void *, size_t,
846 int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(sendto);
847 int setsockopt(int, int, int, const void *, socklen_t);
848 int shutdown(int, int);
849 int sockatmark(int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
850 int socket(int, int, int);
851 int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair);
852
853 #if !defined(_POSIX_C_SOURCE)
854 int sendfile(int, int, off_t, off_t *, struct sf_hdtr *, int);
855 #endif /* !_POSIX_C_SOURCE */
856
857 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
858 void pfctlinput(int, struct sockaddr *);
859 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
860 __END_DECLS
861 #endif /* !KERNEL */
862
863 #ifdef KERNEL
864 #include <sys/kpi_socket.h>
865 #endif
866
867 #endif /* !_SYS_SOCKET_H_ */