2 * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
31 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
32 * The Regents of the University of California. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
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.
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
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 $
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,
72 #ifndef _SYS_SOCKET_H_
73 #define _SYS_SOCKET_H_
75 #include <sys/types.h>
76 #include <sys/cdefs.h>
77 #include <machine/_param.h>
80 #include <sys/param.h>
81 #include <uuid/uuid.h>
85 #include <Availability.h>
89 * Definitions related to sockets: types, address families, options.
96 #include <sys/_types/_gid_t.h>
97 #include <sys/_types/_off_t.h>
98 #include <sys/_types/_pid_t.h>
99 #include <sys/_types/_sa_family_t.h>
100 #include <sys/_types/_socklen_t.h>
102 /* XXX Not explicitly defined by POSIX, but function return types are */
103 #include <sys/_types/_size_t.h>
105 /* XXX Not explicitly defined by POSIX, but function return types are */
106 #include <sys/_types/_ssize_t.h>
109 * [XSI] The iovec structure shall be defined as described in <sys/uio.h>.
111 #include <sys/_types/_iovec_t.h>
114 #define SO_TCDBG_PID 0x01 /* Set/get traffic class for PID */
115 #define SO_TCDBG_PNAME 0x02 /* Set/get traffic class for processes of that name */
116 #define SO_TCDBG_PURGE 0x04 /* Purge entries for unused PIDs */
117 #define SO_TCDBG_FLUSH 0x08 /* Flush all entries */
118 #define SO_TCDBG_COUNT 0x10 /* Get count of entries */
119 #define SO_TCDBG_LIST 0x20 /* List entries */
120 #define SO_TCDBG_DELETE 0x40 /* Delete a process entry */
121 #define SO_TCDBG_TCFLUSH_PID 0x80 /* Flush traffic class for PID */
124 u_int32_t so_tcdbg_cmd
;
125 int32_t so_tcdbg_tclass
;
126 u_int32_t so_tcdbg_count
;
128 char so_tcdbg_pname
[MAXCOMLEN
+ 1];
129 int32_t so_tcdbg_opportunistic
; /* -1: unspecified, 0: off, 1: on, other: errors */
136 #define SOCK_STREAM 1 /* stream socket */
137 #define SOCK_DGRAM 2 /* datagram socket */
138 #define SOCK_RAW 3 /* raw-protocol interface */
139 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
140 #define SOCK_RDM 4 /* reliably-delivered message */
141 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
142 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
145 * Option flags per-socket.
147 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
148 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
149 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
150 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
151 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
152 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
153 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
154 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
155 #define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */
157 #define SO_LINGER 0x1080 /* linger on close if data present (in seconds) */
158 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
159 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
160 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
161 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
162 #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
163 #define SO_TIMESTAMP_MONOTONIC 0x0800 /* Monotonically increasing timestamp on rcvd dgram */
165 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
167 #define SO_DONTTRUNC 0x2000 /* APPLE: Retain unread data */
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 */
172 #endif /* (!__APPLE__) */
173 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
176 * Additional options, not kept in so_options.
178 #define SO_SNDBUF 0x1001 /* send buffer size */
179 #define SO_RCVBUF 0x1002 /* receive buffer size */
180 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
181 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
182 #define SO_SNDTIMEO 0x1005 /* send timeout */
183 #define SO_RCVTIMEO 0x1006 /* receive timeout */
184 #define SO_ERROR 0x1007 /* get error status and clear */
185 #define SO_TYPE 0x1008 /* get socket type */
186 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
187 /*efine SO_PRIVSTATE 0x1009 get/deny privileged state */
188 #define SO_LABEL 0x1010 /* socket's MAC label */
189 #define SO_PEERLABEL 0x1011 /* socket's peer MAC label */
191 #define SO_NREAD 0x1020 /* APPLE: get 1st-packet byte count */
192 #define SO_NKE 0x1021 /* APPLE: Install socket-level NKE */
193 #define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */
194 #define SO_NOADDRERR 0x1023 /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
195 #define SO_NWRITE 0x1024 /* APPLE: Get number of bytes currently in send socket buffer */
196 #define SO_REUSESHAREUID 0x1025 /* APPLE: Allow reuse of port/socket by different userids */
197 #ifdef __APPLE_API_PRIVATE
198 #define SO_NOTIFYCONFLICT 0x1026 /* APPLE: send notification if there is a bind on a port which is already in use */
199 #define SO_UPCALLCLOSEWAIT 0x1027 /* APPLE: block on close until an upcall returns */
201 #define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */
203 #define SO_RESTRICTIONS 0x1081 /* APPLE: deny flag set */
204 #define SO_RESTRICT_DENY_IN 0x1 /* deny inbound (trapdoor) */
205 #define SO_RESTRICT_DENY_OUT 0x2 /* deny outbound (trapdoor) */
206 #define SO_RESTRICT_DENY_CELLULAR 0x4 /* deny use of cellular (trapdoor) */
208 #define SO_RANDOMPORT 0x1082 /* APPLE: request local port randomization */
209 #define SO_NP_EXTENSIONS 0x1083 /* To turn off some POSIX behavior */
213 #define SO_EXECPATH 0x1085 /* Application Firewall Socket option */
215 * Traffic service class definitions (lowest to highest):
218 * "Background System-Initiated", high delay tolerant, high loss
219 * tolerant, elastic flow, variable size & long-lived. E.g: system-
220 * initiated iCloud synching or Time Capsule backup, for which there
221 * is no progress feedbacks.
224 * "Background", user-initiated, high delay tolerant, high loss tolerant,
225 * elastic flow, variable size. E.g. user-initiated iCloud synching or
226 * Time Capsule backup; or traffics of background applications, for which
227 * there is some progress feedbacks.
230 * "Best Effort", unclassified/standard. This is the default service
231 * class; pretty much a mix of everything.
234 * "Responsive Data", a notch higher than "Best Effort", medium delay
235 * tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email,
236 * instant messaging, for which there is a sense of interactivity and
237 * urgency (user waiting for output).
240 * "Operations, Administration, and Management", medium delay tolerant,
241 * low-medium loss tolerant, elastic & inelastic flows, variable size.
245 * "Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
246 * loss tolerant, elastic flow, constant packet interval, variable rate &
247 * size. E.g. AirPlay playback (both video and audio).
250 * "Responsive Multimedia Audio/Video", low delay tolerant, low-medium
251 * loss tolerant, elastic flow, variable packet interval, rate and size.
252 * E.g. AirPlay mirroring, screen sharing.
255 * "Interactive Video", low delay tolerant, low-medium loss tolerant,
256 * elastic flow, constant packet interval, variable rate & size. E.g.
260 * "Interactive Voice", low delay tolerant, low loss tolerant, inelastic
261 * flow, constant packet rate, somewhat fixed size. E.g. VoIP including
265 * "Network Control", low delay tolerant, low loss tolerant, inelastic
266 * flow, rate is bursty but short, variable size. E.g. DNS queries;
267 * certain types of locally-originated ICMP, ICMPv6; IGMP/MLD join/leave,
270 #define SO_TRAFFIC_CLASS 0x1086 /* Traffic service class (int) */
271 #define SO_TC_BK_SYS 100 /* lowest class */
275 #define SO_TC_OAM 400
280 #define SO_TC_CTL 900 /* highest class */
281 #define SO_TC_MAX 10 /* Total # of traffic classes */
282 #ifdef XNU_KERNEL_PRIVATE
283 #define _SO_TC_BK 1 /* deprecated */
284 #define _SO_TC_VI 2 /* deprecated */
285 #define _SO_TC_VO 3 /* deprecated */
286 #define _SO_TC_MAX 4 /* deprecated */
288 #define SO_VALID_TC(c) \
289 (c == SO_TC_BK_SYS || c == SO_TC_BK || c == SO_TC_BE || \
290 c == SO_TC_RD || c == SO_TC_OAM || c == SO_TC_AV || \
291 c == SO_TC_RV || c == SO_TC_VI || c == SO_TC_VO || c == SO_TC_CTL)
292 #endif /* XNU_KERNEL_PRIVATE */
294 /* Background socket configuration flags */
295 #define TRAFFIC_MGT_SO_BACKGROUND 0x0001 /* background socket */
296 #define TRAFFIC_MGT_TCP_RECVBG 0x0002 /* Only TCP sockets, receiver throttling */
298 #define SO_RECV_TRAFFIC_CLASS 0x1087 /* Receive traffic class (bool)*/
299 #define SO_TRAFFIC_CLASS_DBG 0x1088 /* Debug traffic class (struct so_tcdbg) */
300 #define SO_TRAFFIC_CLASS_STATS 0x1089 /* Traffic class statistics */
301 #define SO_PRIVILEGED_TRAFFIC_CLASS 0x1090 /* Privileged traffic class (bool) */
302 #define SO_DEFUNCTOK 0x1100 /* can be defunct'd */
303 #define SO_ISDEFUNCT 0x1101 /* get defunct status */
305 #define SO_OPPORTUNISTIC 0x1102 /* deprecated; use SO_TRAFFIC_CLASS */
308 * SO_FLUSH flushes any unsent data generated by a given socket. It takes
309 * an integer parameter, which can be any of the SO_TC traffic class values,
310 * or the special SO_TC_ALL value.
312 #define SO_FLUSH 0x1103 /* flush unsent data (int) */
313 #define SO_TC_ALL (-1)
315 #define SO_RECV_ANYIF 0x1104 /* unrestricted inbound processing */
316 #define SO_TRAFFIC_MGT_BACKGROUND 0x1105 /* Background traffic management */
318 #define SO_FLOW_DIVERT_TOKEN 0x1106 /* flow divert token */
320 #define SO_DELEGATED 0x1107 /* set socket as delegate (pid_t) */
321 #define SO_DELEGATED_UUID 0x1108 /* set socket as delegate (uuid_t) */
324 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
327 * Structure used for manipulating linger option.
330 int l_onoff
; /* option on/off */
331 int l_linger
; /* linger time */
335 struct accept_filter_arg
{
341 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
345 * Structure to control non-portable Sockets extension to POSIX
347 struct so_np_extensions
{
352 #define SONPX_SETOPTSHUT 0x000000001 /* flag for allowing setsockopt after shutdown */
355 #ifdef KERNEL_PRIVATE
356 #define SONPX_MASK_VALID (SONPX_SETOPTSHUT)
357 #define IS_SO_TC_BACKGROUND(_tc_) ((_tc_) == SO_TC_BK || (_tc_) == SO_TC_BK_SYS)
358 #endif /* KERNEL_PRIVATE */
364 * Level number for (get/set)sockopt() to apply to socket itself.
366 #define SOL_SOCKET 0xffff /* options for socket level */
372 #define AF_UNSPEC 0 /* unspecified */
373 #define AF_UNIX 1 /* local to host (pipes) */
374 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
375 #define AF_LOCAL AF_UNIX /* backward compatibility */
376 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
377 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
378 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
379 #define AF_IMPLINK 3 /* arpanet imp addresses */
380 #define AF_PUP 4 /* pup protocols: e.g. BSP */
381 #define AF_CHAOS 5 /* mit CHAOS protocols */
382 #define AF_NS 6 /* XEROX NS protocols */
383 #define AF_ISO 7 /* ISO protocols */
384 #define AF_OSI AF_ISO
385 #define AF_ECMA 8 /* European computer manufacturers */
386 #define AF_DATAKIT 9 /* datakit protocols */
387 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
388 #define AF_SNA 11 /* IBM SNA */
389 #define AF_DECnet 12 /* DECnet */
390 #define AF_DLI 13 /* DEC Direct data link interface */
391 #define AF_LAT 14 /* LAT */
392 #define AF_HYLINK 15 /* NSC Hyperchannel */
393 #define AF_APPLETALK 16 /* Apple Talk */
394 #define AF_ROUTE 17 /* Internal Routing Protocol */
395 #define AF_LINK 18 /* Link layer interface */
396 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
397 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
398 #define AF_CNT 21 /* Computer Network Technology */
399 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
400 #define AF_IPX 23 /* Novell Internet Protocol */
401 #define AF_SIP 24 /* Simple Internet Protocol */
402 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
403 /*define pseudo_AF_BLUE 26 Identify packets for Blue Box - Not used */
404 #define AF_NDRV 27 /* Network Driver 'raw' access */
405 #define AF_ISDN 28 /* Integrated Services Digital Network*/
406 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
407 #define pseudo_AF_KEY 29 /* Internal key-management function */
408 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
409 #define AF_INET6 30 /* IPv6 */
410 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
411 #define AF_NATM 31 /* native ATM access */
412 #define AF_SYSTEM 32 /* Kernel event messages */
413 #define AF_NETBIOS 33 /* NetBIOS */
414 #define AF_PPP 34 /* PPP communication protocol */
415 #define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers
416 * in interface output routine */
418 #define AF_AFP 36 /* Used by AFP */
420 #define AF_RESERVED_36 36 /* Reserved for internal usage */
422 #define AF_IEEE80211 37 /* IEEE 802.11 protocol */
425 #define AF_MULTIPATH 39
428 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
431 * [XSI] Structure used by kernel to store most addresses.
434 __uint8_t sa_len
; /* total length */
435 sa_family_t sa_family
; /* [XSI] address family */
436 char sa_data
[14]; /* [XSI] addr value (actually larger) */
439 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
440 #define SOCK_MAXADDRLEN 255 /* longest possible addresses */
443 * Structure used by kernel to pass protocol
444 * information in raw sockets.
447 __uint16_t sp_family
; /* address family */
448 __uint16_t sp_protocol
; /* protocol */
450 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE)*/
453 * RFC 2553: protocol-independent placeholder for socket addresses
455 #define _SS_MAXSIZE 128
456 #define _SS_ALIGNSIZE (sizeof(__int64_t))
457 #define _SS_PAD1SIZE \
458 (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
459 #define _SS_PAD2SIZE \
460 (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
461 _SS_PAD1SIZE - _SS_ALIGNSIZE)
464 * [XSI] sockaddr_storage
466 struct sockaddr_storage
{
467 __uint8_t ss_len
; /* address length */
468 sa_family_t ss_family
; /* [XSI] address family */
469 char __ss_pad1
[_SS_PAD1SIZE
];
470 __int64_t __ss_align
; /* force structure storage alignment */
471 char __ss_pad2
[_SS_PAD2SIZE
];
474 #ifdef BSD_KERNEL_PRIVATE
475 #include <sys/queue.h>
477 struct sockaddr_entry
{
478 TAILQ_ENTRY(sockaddr_entry
) se_link
;
479 struct sockaddr
*se_addr
;
483 #define SEF_ATTACHED 1 /* attached to sockaddr_list */
485 struct sockaddr_list
{
486 TAILQ_HEAD(, sockaddr_entry
) sl_head
;
490 #endif /* BSD_KERNEL_PRIVATE */
493 * Protocol families, same as address families for now.
495 #define PF_UNSPEC AF_UNSPEC
496 #define PF_LOCAL AF_LOCAL
497 #define PF_UNIX PF_LOCAL /* backward compatibility */
498 #define PF_INET AF_INET
499 #define PF_IMPLINK AF_IMPLINK
500 #define PF_PUP AF_PUP
501 #define PF_CHAOS AF_CHAOS
503 #define PF_ISO AF_ISO
504 #define PF_OSI AF_ISO
505 #define PF_ECMA AF_ECMA
506 #define PF_DATAKIT AF_DATAKIT
507 #define PF_CCITT AF_CCITT
508 #define PF_SNA AF_SNA
509 #define PF_DECnet AF_DECnet
510 #define PF_DLI AF_DLI
511 #define PF_LAT AF_LAT
512 #define PF_HYLINK AF_HYLINK
513 #define PF_APPLETALK AF_APPLETALK
514 #define PF_ROUTE AF_ROUTE
515 #define PF_LINK AF_LINK
516 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
517 #define PF_COIP AF_COIP
518 #define PF_CNT AF_CNT
519 #define PF_SIP AF_SIP
520 #define PF_IPX AF_IPX /* same format as AF_NS */
521 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
522 #define PF_PIP pseudo_AF_PIP
523 #define PF_NDRV AF_NDRV
524 #define PF_ISDN AF_ISDN
525 #define PF_KEY pseudo_AF_KEY
526 #define PF_INET6 AF_INET6
527 #define PF_NATM AF_NATM
528 #define PF_SYSTEM AF_SYSTEM
529 #define PF_NETBIOS AF_NETBIOS
530 #define PF_PPP AF_PPP
532 #define PF_AFP AF_AFP
534 #define PF_RESERVED_36 AF_RESERVED_36
536 #define PF_UTUN AF_UTUN
538 #define PF_MULTIPATH AF_MULTIPATH
540 #define PF_MAX AF_MAX
543 * These do not have socket-layer support:
545 #define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */
546 #define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */
547 #ifdef KERNEL_PRIVATE
548 #define PF_BRIDGE ((uint32_t)0x62726467) /* 'brdg' */
549 #endif /* KERNEL_PRIVATE */
552 * Definitions for network related sysctl, CTL_NET.
554 * Second level is protocol family.
555 * Third level is protocol number.
557 * Further levels are defined by the individual families below.
559 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
560 #define NET_MAXID AF_MAX
561 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
563 #ifdef KERNEL_PRIVATE
564 #define CTL_NET_NAMES { \
566 { "local", CTLTYPE_NODE }, \
567 { "inet", CTLTYPE_NODE }, \
568 { "implink", CTLTYPE_NODE }, \
569 { "pup", CTLTYPE_NODE }, \
570 { "chaos", CTLTYPE_NODE }, \
571 { "xerox_ns", CTLTYPE_NODE }, \
572 { "iso", CTLTYPE_NODE }, \
573 { "emca", CTLTYPE_NODE }, \
574 { "datakit", CTLTYPE_NODE }, \
575 { "ccitt", CTLTYPE_NODE }, \
576 { "ibm_sna", CTLTYPE_NODE }, \
577 { "decnet", CTLTYPE_NODE }, \
578 { "dec_dli", CTLTYPE_NODE }, \
579 { "lat", CTLTYPE_NODE }, \
580 { "hylink", CTLTYPE_NODE }, \
581 { "appletalk", CTLTYPE_NODE }, \
582 { "route", CTLTYPE_NODE }, \
583 { "link_layer", CTLTYPE_NODE }, \
584 { "xtp", CTLTYPE_NODE }, \
585 { "coip", CTLTYPE_NODE }, \
586 { "cnt", CTLTYPE_NODE }, \
587 { "rtip", CTLTYPE_NODE }, \
588 { "ipx", CTLTYPE_NODE }, \
589 { "sip", CTLTYPE_NODE }, \
590 { "pip", CTLTYPE_NODE }, \
592 { "ndrv", CTLTYPE_NODE }, \
593 { "isdn", CTLTYPE_NODE }, \
594 { "key", CTLTYPE_NODE }, \
595 { "inet6", CTLTYPE_NODE }, \
596 { "natm", CTLTYPE_NODE }, \
597 { "sys", CTLTYPE_NODE }, \
598 { "netbios", CTLTYPE_NODE }, \
599 { "ppp", CTLTYPE_NODE }, \
600 { "hdrcomplete", CTLTYPE_NODE }, \
602 #endif /* KERNEL_PRIVATE */
604 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
606 * PF_ROUTE - Routing table
608 * Three additional levels are defined:
609 * Fourth: address family, 0 is wildcard
610 * Fifth: type of info, defined below
611 * Sixth: flag(s) to mask with for NET_RT_FLAGS
613 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
614 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
615 #define NET_RT_IFLIST 3 /* survey interface list */
616 #define NET_RT_STAT 4 /* routing statistics */
617 #define NET_RT_TRASH 5 /* routes not in table but not freed */
618 #define NET_RT_IFLIST2 6 /* interface list with addresses */
619 #define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
621 #define NET_RT_DUMPX 8 /* private */
622 #define NET_RT_DUMPX_FLAGS 9 /* private */
624 #define NET_RT_MAXID 10
625 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
627 #ifdef KERNEL_PRIVATE
628 #define CTL_NET_RT_NAMES { \
630 { "dump", CTLTYPE_STRUCT }, \
631 { "flags", CTLTYPE_STRUCT }, \
632 { "iflist", CTLTYPE_STRUCT }, \
633 { "stat", CTLTYPE_STRUCT }, \
634 { "trash", CTLTYPE_INT }, \
635 { "iflist2", CTLTYPE_STRUCT }, \
636 { "dump2", CTLTYPE_STRUCT }, \
637 { "dumpx", CTLTYPE_STRUCT }, \
638 { "dumpx_flags", CTLTYPE_STRUCT }, \
641 #endif /* KERNEL_PRIVATE */
644 * Maximum queue length specifiable by listen.
646 #define SOMAXCONN 128
649 * [XSI] Message header for recvmsg and sendmsg calls.
650 * Used value-result for recvmsg, value only for sendmsg.
653 void *msg_name
; /* [XSI] optional address */
654 socklen_t msg_namelen
; /* [XSI] size of address */
655 struct iovec
*msg_iov
; /* [XSI] scatter/gather array */
656 int msg_iovlen
; /* [XSI] # elements in msg_iov */
657 void *msg_control
; /* [XSI] ancillary data, see below */
658 socklen_t msg_controllen
; /* [XSI] ancillary data buffer len */
659 int msg_flags
; /* [XSI] flags on received message */
664 * In-kernel representation of "struct msghdr" from
665 * userspace. Has enough precision for 32-bit or
666 * 64-bit clients, but does not need to be packed.
670 user_addr_t msg_name
; /* optional address */
671 socklen_t msg_namelen
; /* size of address */
672 user_addr_t msg_iov
; /* scatter/gather array */
673 int msg_iovlen
; /* # elements in msg_iov */
674 user_addr_t msg_control
; /* ancillary data, see below */
675 socklen_t msg_controllen
; /* ancillary data buffer len */
676 int msg_flags
; /* flags on received message */
680 * LP64 user version of struct msghdr.
681 * WARNING - keep in sync with struct msghdr
684 struct user64_msghdr
{
685 user64_addr_t msg_name
; /* optional address */
686 socklen_t msg_namelen
; /* size of address */
687 user64_addr_t msg_iov
; /* scatter/gather array */
688 int msg_iovlen
; /* # elements in msg_iov */
689 user64_addr_t msg_control
; /* ancillary data, see below */
690 socklen_t msg_controllen
; /* ancillary data buffer len */
691 int msg_flags
; /* flags on received message */
695 * ILP32 user version of struct msghdr.
696 * WARNING - keep in sync with struct msghdr
699 struct user32_msghdr
{
700 user32_addr_t msg_name
; /* optional address */
701 socklen_t msg_namelen
; /* size of address */
702 user32_addr_t msg_iov
; /* scatter/gather array */
703 int msg_iovlen
; /* # elements in msg_iov */
704 user32_addr_t msg_control
; /* ancillary data, see below */
705 socklen_t msg_controllen
; /* ancillary data buffer len */
706 int msg_flags
; /* flags on received message */
711 #define MSG_OOB 0x1 /* process out-of-band data */
712 #define MSG_PEEK 0x2 /* peek at incoming message */
713 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
714 #define MSG_EOR 0x8 /* data completes record */
715 #define MSG_TRUNC 0x10 /* data discarded before delivery */
716 #define MSG_CTRUNC 0x20 /* control data lost before delivery */
717 #define MSG_WAITALL 0x40 /* wait for full request or error */
718 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
719 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
720 #define MSG_EOF 0x100 /* data completes connection */
723 #ifdef __APPLE_API_OBSOLETE
724 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
727 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
729 #define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp */
730 #define MSG_HOLD 0x800 /* Hold frag in so_temp */
731 #define MSG_SEND 0x1000 /* Send the packet in so_temp */
732 #define MSG_HAVEMORE 0x2000 /* Data ready to be read */
733 #define MSG_RCVMORE 0x4000 /* Data remains in current pkt */
735 #ifdef KERNEL_PRIVATE
736 #define MSG_COMPAT 0x8000 /* deprecated */
737 #endif /* KERNEL_PRIVATE */
738 #define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */
739 #ifdef KERNEL_PRIVATE
740 #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */
743 #define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */
745 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
748 * Header for ancillary data objects in msg_control buffer.
749 * Used for additional information with/about a datagram
750 * not expressible by flags. The format is a sequence
751 * of message elements headed by cmsghdr structures.
754 socklen_t cmsg_len
; /* [XSI] data byte count, including hdr */
755 int cmsg_level
; /* [XSI] originating protocol */
756 int cmsg_type
; /* [XSI] protocol-specific type */
757 /* followed by unsigned char cmsg_data[]; */
760 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
763 * While we may have more groups than this, the cmsgcred struct must
764 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
767 #define CMGROUP_MAX 16
770 * Credentials structure, used to verify the identity of a peer
771 * process that has sent us a message. This is allocated by the
772 * peer process but filled in by the kernel. This prevents the
773 * peer from lying about its identity. (Note that cmcred_groups[0]
774 * is the effective GID.)
777 pid_t cmcred_pid
; /* PID of sending process */
778 uid_t cmcred_uid
; /* real UID of sending process */
779 uid_t cmcred_euid
; /* effective UID of sending process */
780 gid_t cmcred_gid
; /* real GID of sending process */
781 short cmcred_ngroups
; /* number or groups */
782 gid_t cmcred_groups
[CMGROUP_MAX
]; /* groups */
785 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
787 /* given pointer to struct cmsghdr, return pointer to data */
788 #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
789 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
792 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
793 * an empty list for some reasons.
795 #define CMSG_FIRSTHDR(mhdr) \
796 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
797 (struct cmsghdr *)(mhdr)->msg_control : \
798 (struct cmsghdr *)0L)
802 * Given pointer to struct cmsghdr, return pointer to next cmsghdr
803 * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
805 #define CMSG_NXTHDR(mhdr, cmsg) \
806 ((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) : \
807 ((((unsigned char *)(cmsg) + \
808 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \
809 __DARWIN_ALIGN32(sizeof(struct cmsghdr))) > \
810 ((unsigned char *)(mhdr)->msg_control + \
811 (mhdr)->msg_controllen)) ? \
812 (struct cmsghdr *)0L /* NULL */ : \
813 (struct cmsghdr *)(void *)((unsigned char *)(cmsg) + \
814 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
816 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
817 /* RFC 2292 additions */
818 #define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
819 #define CMSG_LEN(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
822 #define CMSG_ALIGN(n) __DARWIN_ALIGN32(n)
824 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
826 /* "Socket"-level control message types: */
827 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
828 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
829 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
830 #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
831 #define SCM_TIMESTAMP_MONOTONIC 0x04 /* timestamp (uint64_t) */
834 #define SCM_SEQNUM 0x05 /* TCP unordered recv seq no */
835 #define SCM_MSG_PRIORITY 0x06 /* TCP unordered snd priority */
838 #ifdef KERNEL_PRIVATE
840 * 4.3 compat sockaddr (deprecated)
843 __uint16_t sa_family
; /* address family */
844 char sa_data
[14]; /* up to 14 bytes of direct address */
848 * 4.3-compat message header (deprecated)
851 void *msg_name
; /* optional address */
852 socklen_t msg_namelen
; /* size of address */
853 struct iovec
*msg_iov
; /* scatter/gather array */
854 int msg_iovlen
; /* # elements in msg_iov */
855 void *msg_accrights
; /* access rights sent/rcvd */
856 int msg_accrightslen
;
859 #define SA(s) ((struct sockaddr *)(void *)(s))
860 #endif /* KERNEL_PRIVATE */
861 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
864 * howto arguments for shutdown(2), specified by Posix.1g.
866 #define SHUT_RD 0 /* shut down the reading side */
867 #define SHUT_WR 1 /* shut down the writing side */
868 #define SHUT_RDWR 2 /* shut down both sides */
870 #if !defined(_POSIX_C_SOURCE)
872 * sendfile(2) header/trailer struct
875 struct iovec
*headers
; /* pointer to an array of header struct iovec's */
876 int hdr_cnt
; /* number of header iovec's */
877 struct iovec
*trailers
; /* pointer to an array of trailer struct iovec's */
878 int trl_cnt
; /* number of trailer iovec's */
883 /* In-kernel representation */
884 struct user_sf_hdtr
{
885 user_addr_t headers
; /* pointer to an array of header struct iovec's */
886 int hdr_cnt
; /* number of header iovec's */
887 user_addr_t trailers
; /* pointer to an array of trailer struct iovec's */
888 int trl_cnt
; /* number of trailer iovec's */
891 /* LP64 user version of struct sf_hdtr */
892 struct user64_sf_hdtr
{
893 user64_addr_t headers
; /* pointer to an array of header struct iovec's */
894 int hdr_cnt
; /* number of header iovec's */
895 user64_addr_t trailers
; /* pointer to an array of trailer struct iovec's */
896 int trl_cnt
; /* number of trailer iovec's */
899 /* ILP32 user version of struct sf_hdtr */
900 struct user32_sf_hdtr
{
901 user32_addr_t headers
; /* pointer to an array of header struct iovec's */
902 int hdr_cnt
; /* number of header iovec's */
903 user32_addr_t trailers
; /* pointer to an array of trailer struct iovec's */
904 int trl_cnt
; /* number of trailer iovec's */
909 #endif /* !_POSIX_C_SOURCE */
912 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
913 typedef __uint32_t associd_t
;
914 #define ASSOCID_ANY 0
915 #define ASSOCID_ALL ((associd_t)(-1ULL))
917 typedef __uint32_t connid_t
;
919 #define CONNID_ALL ((connid_t)(-1ULL))
922 * Structure for SIOCGASSOCIDS
925 __uint32_t sar_cnt
; /* number of associations */
926 associd_t
*sar_aidp
; /* array of association IDs */
929 #ifdef BSD_KERNEL_PRIVATE
932 user32_addr_t sar_aidp
;
937 user64_addr_t sar_aidp
__attribute__((aligned(8)));
939 #endif /* BSD_KERNEL_PRIVATE */
942 * Structure for SIOCGCONNIDS
945 associd_t scr_aid
; /* association ID */
946 __uint32_t scr_cnt
; /* number of connections */
947 connid_t
*scr_cidp
; /* array of connection IDs */
950 #ifdef BSD_KERNEL_PRIVATE
954 user32_addr_t scr_cidp
;
960 user64_addr_t scr_cidp
__attribute__((aligned(8)));
962 #endif /* BSD_KERNEL_PRIVATE */
965 * Structure for SIOCGCONNINFO
968 connid_t scir_cid
; /* connection ID */
969 __uint32_t scir_flags
; /* see flags below */
970 __uint32_t scir_ifindex
; /* (last) outbound interface */
971 __int32_t scir_error
; /* most recent error */
972 struct sockaddr
*scir_src
; /* source address */
973 socklen_t scir_src_len
; /* source address len */
974 struct sockaddr
*scir_dst
; /* destination address */
975 socklen_t scir_dst_len
; /* destination address len */
976 __uint32_t scir_aux_type
; /* aux data type (CIAUX) */
977 void *scir_aux_data
; /* aux data */
978 __uint32_t scir_aux_len
; /* aux data len */
981 #ifdef BSD_KERNEL_PRIVATE
982 struct so_cinforeq32
{
984 __uint32_t scir_flags
;
985 __uint32_t scir_ifindex
;
986 __int32_t scir_error
;
987 user32_addr_t scir_src
;
988 socklen_t scir_src_len
;
989 user32_addr_t scir_dst
;
990 socklen_t scir_dst_len
;
991 __uint32_t scir_aux_type
;
992 user32_addr_t scir_aux_data
;
993 __uint32_t scir_aux_len
;
996 struct so_cinforeq64
{
998 __uint32_t scir_flags
;
999 __uint32_t scir_ifindex
;
1000 __int32_t scir_error
;
1001 user64_addr_t scir_src
__attribute__((aligned(8)));
1002 socklen_t scir_src_len
;
1003 user64_addr_t scir_dst
__attribute__((aligned(8)));
1004 socklen_t scir_dst_len
;
1005 __uint32_t scir_aux_type
;
1006 user64_addr_t scir_aux_data
__attribute__((aligned(8)));
1007 __uint32_t scir_aux_len
;
1009 #endif /* BSD_KERNEL_PRIVATE */
1011 /* valid connection info flags */
1012 #define CIF_CONNECTING 0x1 /* connection was attempted */
1013 #define CIF_CONNECTED 0x2 /* connection is established */
1014 #define CIF_DISCONNECTING 0x4 /* disconnection was attempted */
1015 #define CIF_DISCONNECTED 0x8 /* has been disconnected */
1016 #define CIF_BOUND_IF 0x10 /* bound to an interface */
1017 #define CIF_BOUND_IP 0x20 /* bound to a src address */
1018 #define CIF_BOUND_PORT 0x40 /* bound to a src port */
1019 #define CIF_PREFERRED 0x80 /* connection is primary/preferred */
1020 #define CIF_MP_CAPABLE 0x100 /* supports multipath protocol */
1021 #define CIF_MP_READY 0x200 /* multipath protocol confirmed */
1022 #define CIF_MP_DEGRADED 0x400 /* has lost its multipath capability */
1023 #define CIF_MP_ACTIVE 0x800 /* this is the active subflow */
1025 /* valid connection info auxiliary data types */
1026 #define CIAUX_TCP 0x1 /* TCP auxiliary data (conninfo_tcp_t) */
1029 * Structure for SIOC{S,G}CONNORDER
1032 connid_t sco_cid
; /* connection ID */
1033 __uint32_t sco_rank
; /* rank (0 means unspecified) */
1037 * Network policy subclass (of KEV_NETWORK_CLASS)
1039 #define KEV_NETPOLICY_SUBCLASS 3
1041 #define KEV_NETPOLICY_IFDENIED 1 /* denied access to interface */
1044 * Common structure for KEV_NETPOLICY_SUBCLASS
1046 struct netpolicy_event_data
{
1047 __uint64_t eupid
; /* effective unique PID */
1048 pid_t epid
; /* effective PID */
1049 #if !defined(__LP64__)
1051 #endif /* __LP64__ */
1052 uuid_t euuid
; /* effective UUID */
1056 * NETPOLICY_IFDENIED event structure
1058 struct kev_netpolicy_ifdenied
{
1059 struct netpolicy_event_data ev_data
;
1064 extern int connectx(int s
, struct sockaddr
*, socklen_t
, struct sockaddr
*,
1065 socklen_t
, __uint32_t
, associd_t
, connid_t
*);
1066 extern int disconnectx(int s
, associd_t
, connid_t
);
1067 extern int peeloff(int s
, associd_t
);
1068 extern int socket_delegate(int, int, int, pid_t
);
1070 #endif /* !KERNEL */
1071 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1072 #endif /* PRIVATE */
1076 int accept(int, struct sockaddr
* __restrict
, socklen_t
* __restrict
)
1077 __DARWIN_ALIAS_C(accept
);
1078 int bind(int, const struct sockaddr
*, socklen_t
) __DARWIN_ALIAS(bind
);
1079 int connect(int, const struct sockaddr
*, socklen_t
) __DARWIN_ALIAS_C( connect
);
1080 int getpeername(int, struct sockaddr
* __restrict
, socklen_t
* __restrict
)
1081 __DARWIN_ALIAS(getpeername
);
1082 int getsockname(int, struct sockaddr
* __restrict
, socklen_t
* __restrict
)
1083 __DARWIN_ALIAS(getsockname
);
1084 int getsockopt(int, int, int, void * __restrict
, socklen_t
* __restrict
);
1085 int listen(int, int) __DARWIN_ALIAS(listen
);
1086 ssize_t
recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv
);
1087 ssize_t
recvfrom(int, void *, size_t, int, struct sockaddr
* __restrict
,
1088 socklen_t
* __restrict
) __DARWIN_ALIAS_C(recvfrom
);
1089 ssize_t
recvmsg(int, struct msghdr
*, int) __DARWIN_ALIAS_C(recvmsg
);
1090 ssize_t
send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send
);
1091 ssize_t
sendmsg(int, const struct msghdr
*, int) __DARWIN_ALIAS_C(sendmsg
);
1092 ssize_t
sendto(int, const void *, size_t,
1093 int, const struct sockaddr
*, socklen_t
) __DARWIN_ALIAS_C(sendto
);
1094 int setsockopt(int, int, int, const void *, socklen_t
);
1095 int shutdown(int, int);
1096 int sockatmark(int) __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
1097 int socket(int, int, int);
1098 int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair
);
1100 #if !defined(_POSIX_C_SOURCE)
1101 int sendfile(int, int, off_t
, off_t
*, struct sf_hdtr
*, int);
1102 #endif /* !_POSIX_C_SOURCE */
1104 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1105 void pfctlinput(int, struct sockaddr
*);
1106 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1108 #endif /* !KERNEL */
1111 #include <sys/kpi_socket.h>
1114 #endif /* !_SYS_SOCKET_H_ */