2 * Copyright (c) 2000-2016 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>
78 #include <net/net_kev.h>
81 #include <sys/param.h>
82 #include <uuid/uuid.h>
86 #include <Availability.h>
90 * Definitions related to sockets: types, address families, options.
97 #include <sys/_types/_gid_t.h>
98 #include <sys/_types/_off_t.h>
99 #include <sys/_types/_pid_t.h>
100 #include <sys/_types/_sa_family_t.h>
101 #include <sys/_types/_socklen_t.h>
103 /* XXX Not explicitly defined by POSIX, but function return types are */
104 #include <sys/_types/_size_t.h>
106 /* XXX Not explicitly defined by POSIX, but function return types are */
107 #include <sys/_types/_ssize_t.h>
110 * [XSI] The iovec structure shall be defined as described in <sys/uio.h>.
112 #include <sys/_types/_iovec_t.h>
117 #define SOCK_STREAM 1 /* stream socket */
118 #define SOCK_DGRAM 2 /* datagram socket */
119 #define SOCK_RAW 3 /* raw-protocol interface */
120 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
121 #define SOCK_RDM 4 /* reliably-delivered message */
122 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
123 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
126 * Option flags per-socket.
128 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
129 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
130 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
131 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
132 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
133 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
134 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
135 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
136 #define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */
138 #define SO_LINGER 0x1080 /* linger on close if data present (in seconds) */
139 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
140 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
141 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
142 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
143 #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
144 #define SO_TIMESTAMP_MONOTONIC 0x0800 /* Monotonically increasing timestamp on rcvd dgram */
146 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
148 #define SO_DONTTRUNC 0x2000 /* APPLE: Retain unread data */
150 #define SO_WANTMORE 0x4000 /* APPLE: Give hint when more data ready */
151 #define SO_WANTOOBFLAG 0x8000 /* APPLE: Want OOB in MSG_FLAG on receive */
154 #define SO_NOWAKEFROMSLEEP 0x10000 /* Don't wake for traffic to this socket */
155 #define SO_NOAPNFALLBK 0x20000 /* Don't attempt APN fallback for the socket */
158 #endif /* (!__APPLE__) */
159 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
162 * Additional options, not kept in so_options.
164 #define SO_SNDBUF 0x1001 /* send buffer size */
165 #define SO_RCVBUF 0x1002 /* receive buffer size */
166 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
167 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
168 #define SO_SNDTIMEO 0x1005 /* send timeout */
169 #define SO_RCVTIMEO 0x1006 /* receive timeout */
170 #define SO_ERROR 0x1007 /* get error status and clear */
171 #define SO_TYPE 0x1008 /* get socket type */
172 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
173 #define SO_LABEL 0x1010 /* socket's MAC label */
174 #define SO_PEERLABEL 0x1011 /* socket's peer MAC label */
176 #define SO_NREAD 0x1020 /* APPLE: get 1st-packet byte count */
177 #define SO_NKE 0x1021 /* APPLE: Install socket-level NKE */
178 #define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */
179 #define SO_NOADDRERR 0x1023 /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
180 #define SO_NWRITE 0x1024 /* APPLE: Get number of bytes currently in send socket buffer */
181 #define SO_REUSESHAREUID 0x1025 /* APPLE: Allow reuse of port/socket by different userids */
182 #ifdef __APPLE_API_PRIVATE
183 #define SO_NOTIFYCONFLICT 0x1026 /* APPLE: send notification if there is a bind on a port which is already in use */
184 #define SO_UPCALLCLOSEWAIT 0x1027 /* APPLE: block on close until an upcall returns */
186 #define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */
188 #define SO_RESTRICTIONS 0x1081 /* APPLE: deny flag set */
189 #define SO_RESTRICT_DENY_IN 0x1 /* deny inbound (trapdoor) */
190 #define SO_RESTRICT_DENY_OUT 0x2 /* deny outbound (trapdoor) */
191 #define SO_RESTRICT_DENY_CELLULAR 0x4 /* deny use of cellular (trapdoor) */
192 #define SO_RESTRICT_DENY_EXPENSIVE 0x8 /* deny use of expensive if (trapdoor) */
194 #define SO_RANDOMPORT 0x1082 /* APPLE: request local port randomization */
195 #define SO_NP_EXTENSIONS 0x1083 /* To turn off some POSIX behavior */
199 #define SO_EXECPATH 0x1085 /* Application Firewall Socket option */
202 * Traffic service class definitions (lowest to highest):
205 * "Background System-Initiated", high delay tolerant, high loss
206 * tolerant, elastic flow, variable size & long-lived. E.g: system-
207 * initiated iCloud synching or Time Capsule backup, for which there
208 * is no progress feedbacks.
211 * "Background", user-initiated, high delay tolerant, high loss tolerant,
212 * elastic flow, variable size. E.g. user-initiated iCloud synching or
213 * Time Capsule backup; or traffics of background applications, for which
214 * there is some progress feedbacks.
217 * "Best Effort", unclassified/standard. This is the default service
218 * class; pretty much a mix of everything.
221 * "Responsive Data", a notch higher than "Best Effort", medium delay
222 * tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email,
223 * instant messaging, for which there is a sense of interactivity and
224 * urgency (user waiting for output).
227 * "Operations, Administration, and Management", medium delay tolerant,
228 * low-medium loss tolerant, elastic & inelastic flows, variable size.
232 * "Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
233 * loss tolerant, elastic flow, constant packet interval, variable rate &
234 * size. E.g. AirPlay playback (both video and audio).
237 * "Responsive Multimedia Audio/Video", low delay tolerant, low-medium
238 * loss tolerant, elastic flow, variable packet interval, rate and size.
239 * E.g. AirPlay mirroring, screen sharing.
242 * "Interactive Video", low delay tolerant, low-medium loss tolerant,
243 * elastic flow, constant packet interval, variable rate & size. E.g.
247 * "Interactive Voice", low delay tolerant, low loss tolerant, inelastic
248 * flow, constant packet rate, somewhat fixed size. E.g. VoIP including
252 * "Network Control", low delay tolerant, low loss tolerant, inelastic
253 * flow, rate is bursty but short, variable size. E.g. DNS queries;
254 * certain types of locally-originated ICMP, ICMPv6; IGMP/MLD join/leave,
257 #define SO_TRAFFIC_CLASS 0x1086 /* Traffic service class (int) */
258 #define SO_TC_BK_SYS 100 /* lowest class */
262 #define SO_TC_OAM 400
267 #define SO_TC_CTL 900 /* highest class */
268 #define SO_TC_MAX 10 /* Total # of traffic classes */
269 #ifdef XNU_KERNEL_PRIVATE
270 #define _SO_TC_BK 1 /* deprecated */
271 #define _SO_TC_VI 2 /* deprecated */
272 #define _SO_TC_VO 3 /* deprecated */
273 #define _SO_TC_MAX 4 /* deprecated */
275 #define SO_VALID_TC(c) \
276 (c == SO_TC_BK_SYS || c == SO_TC_BK || c == SO_TC_BE || \
277 c == SO_TC_RD || c == SO_TC_OAM || c == SO_TC_AV || \
278 c == SO_TC_RV || c == SO_TC_VI || c == SO_TC_VO || \
281 #define SO_TC_UNSPEC ((int)-1) /* Traffic class not specified */
283 #define SO_TC_SIG SO_TC_VI /* to be removed XXX */
285 #define SOTCIX_BK_SYS 0
295 #endif /* XNU_KERNEL_PRIVATE */
297 /* Background socket configuration flags */
298 #define TRAFFIC_MGT_SO_BACKGROUND 0x0001 /* background socket */
299 #define TRAFFIC_MGT_TCP_RECVBG 0x0002 /* Only TCP sockets, receiver throttling */
301 #define SO_RECV_TRAFFIC_CLASS 0x1087 /* Receive traffic class (bool) */
302 #define SO_TRAFFIC_CLASS_DBG 0x1088 /* Debug traffic class (struct so_tcdbg) */
303 #define SO_TRAFFIC_CLASS_STATS 0x1089 /* Traffic class statistics */
304 #define SO_PRIVILEGED_TRAFFIC_CLASS 0x1090 /* Privileged traffic class (bool) */
305 #define SO_DEFUNCTIT 0x1091 /* Defunct a socket (only in internal builds) */
306 #define SO_DEFUNCTOK 0x1100 /* can be defunct'd */
307 #define SO_ISDEFUNCT 0x1101 /* get defunct status */
309 #define SO_OPPORTUNISTIC 0x1102 /* deprecated; use SO_TRAFFIC_CLASS */
312 * SO_FLUSH flushes any unsent data generated by a given socket. It takes
313 * an integer parameter, which can be any of the SO_TC traffic class values,
314 * or the special SO_TC_ALL value.
316 #define SO_FLUSH 0x1103 /* flush unsent data (int) */
317 #define SO_TC_ALL (-1)
319 #define SO_RECV_ANYIF 0x1104 /* unrestricted inbound processing */
320 #define SO_TRAFFIC_MGT_BACKGROUND 0x1105 /* Background traffic management */
322 #define SO_FLOW_DIVERT_TOKEN 0x1106 /* flow divert token */
324 #define SO_DELEGATED 0x1107 /* set socket as delegate (pid_t) */
325 #define SO_DELEGATED_UUID 0x1108 /* set socket as delegate (uuid_t) */
326 #define SO_NECP_ATTRIBUTES 0x1109 /* NECP socket attributes (domain, account, etc.) */
327 #define SO_CFIL_SOCK_ID 0x1110 /* get content filter socket ID (cfil_sock_id_t) */
328 #define SO_NECP_CLIENTUUID 0x1111 /* NECP Client uuid */
330 #define SO_NUMRCVPKT 0x1112 /* number of datagrams in receive socket buffer */
332 #define SO_AWDL_UNRESTRICTED 0x1113 /* try to use AWDL in restricted mode */
333 #define SO_EXTENDED_BK_IDLE 0x1114 /* extended time to keep socket idle after app is suspended (int) */
334 #define SO_MARK_CELLFALLBACK 0x1115 /* Mark as initiated by cell fallback */
338 * Network Service Type for option SO_NET_SERVICE_TYPE
340 * The vast majority of sockets should use Best Effort that is the default
341 * Network Service Type. Other Network Service Types have to be used only if
342 * the traffic actually matches the description of the Network Service Type.
344 * Network Service Types do not represent priorities but rather describe
345 * different categories of delay, jitter and loss parameters.
346 * Those parameters may influence protocols from layer 4 protocols like TCP
347 * to layer 2 protocols like Wi-Fi. The Network Service Type can determine
348 * how the traffic is queued and scheduled by the host networking stack and
349 * by other entities on the network like switches and routers. For example
350 * for Wi-Fi, the Network Service Type can select the marking of the
351 * layer 2 packet with the appropriate WMM Access Category.
353 * There is no point in attempting to game the system and use
354 * a Network Service Type that does not correspond to the actual
355 * traffic characteristic but one that seems to have a higher precedence.
356 * The reason is that for service classes that have lower tolerance
357 * for delay and jitter, the queues size is lower than for service
358 * classes that are more tolerant to delay and jitter.
360 * For example using a voice service type for bulk data transfer will lead
361 * to disastrous results as soon as congestion happens because the voice
362 * queue overflows and packets get dropped. This is not only bad for the bulk
363 * data transfer but it is also bad for VoIP apps that legitimately are using
364 * the voice service type.
366 * The characteristics of the Network Service Types are based on the service
367 * classes defined in RFC 4594 "Configuration Guidelines for DiffServ Service
370 * When system detects the outgoing interface belongs to a DiffServ domain
371 * that follows the recommendation of the IETF draft "Guidelines for DiffServ to
372 * IEEE 802.11 Mapping", the packet will marked at layer 3 with a DSCP value
373 * that corresponds to Network Service Type.
375 * NET_SERVICE_TYPE_BE
376 * "Best Effort", unclassified/standard. This is the default service
377 * class and cover the majority of the traffic.
379 * NET_SERVICE_TYPE_BK
380 * "Background", high delay tolerant, loss tolerant. elastic flow,
381 * variable size & long-lived. E.g: non-interactive network bulk transfer
382 * like synching or backup.
384 * NET_SERVICE_TYPE_RD
385 * "Responsive Data", a notch higher than "Best Effort", medium delay
386 * tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email,
387 * instant messaging, for which there is a sense of interactivity and
388 * urgency (user waiting for output).
390 * NET_SERVICE_TYPE_OAM
391 * "Operations, Administration, and Management", medium delay tolerant,
392 * low-medium loss tolerant, elastic & inelastic flows, variable size.
395 * NET_SERVICE_TYPE_AV
396 * "Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
397 * loss tolerant, elastic flow, constant packet interval, variable rate
398 * and size. E.g. video and audio playback with buffering.
400 * NET_SERVICE_TYPE_RV
401 * "Responsive Multimedia Audio/Video", low delay tolerant, low-medium
402 * loss tolerant, elastic flow, variable packet interval, rate and size.
403 * E.g. screen sharing.
405 * NET_SERVICE_TYPE_VI
406 * "Interactive Video", low delay tolerant, low-medium loss tolerant,
407 * elastic flow, constant packet interval, variable rate & size. E.g.
410 * NET_SERVICE_TYPE_SIG
411 * "Signaling", low delay tolerant, low loss tolerant, inelastic flow,
412 * jitter tolerant, rate is bursty but short, variable size. E.g. SIP.
414 * NET_SERVICE_TYPE_VO
415 * "Interactive Voice", very low delay tolerant, very low loss tolerant,
416 * inelastic flow, constant packet rate, somewhat fixed size.
419 #define SO_NET_SERVICE_TYPE 0x1116 /* Network service type */
421 #define NET_SERVICE_TYPE_BE 0 /* Best effort */
422 #define NET_SERVICE_TYPE_BK 1 /* Background system initiated */
423 #define NET_SERVICE_TYPE_SIG 2 /* Signaling */
424 #define NET_SERVICE_TYPE_VI 3 /* Interactive Video */
425 #define NET_SERVICE_TYPE_VO 4 /* Interactive Voice */
426 #define NET_SERVICE_TYPE_RV 5 /* Responsive Multimedia Audio/Video */
427 #define NET_SERVICE_TYPE_AV 6 /* Multimedia Audio/Video Streaming */
428 #define NET_SERVICE_TYPE_OAM 7 /* Operations, Administration, and Management */
429 #define NET_SERVICE_TYPE_RD 8 /* Responsive Data */
432 #define SO_QOSMARKING_POLICY_OVERRIDE 0x1117 /* int */
433 #define SO_INTCOPROC_ALLOW 0x1118 /* Try to use internal co-processor interfaces. */
435 #define _NET_SERVICE_TYPE_COUNT 9
436 #define _NET_SERVICE_TYPE_UNSPEC ((int)-1)
438 #define IS_VALID_NET_SERVICE_TYPE(c) \
439 (c >= NET_SERVICE_TYPE_BE && c <= NET_SERVICE_TYPE_RD)
441 extern const int sotc_by_netservicetype
[_NET_SERVICE_TYPE_COUNT
];
444 * Facility to pass Network Service Type values using SO_TRAFFIC_CLASS
445 * Mostly useful to simplify implementation of frameworks to adopt the new
446 * Network Service Type values for Signaling.
448 #define SO_TC_NET_SERVICE_OFFSET 10000
449 #define SO_TC_NETSVC_SIG (SO_TC_NET_SERVICE_OFFSET + NET_SERVICE_TYPE_SIG)
452 #define SO_NETSVC_MARKING_LEVEL 0x1119 /* Get QoS marking in effect for socket */
454 #define NETSVC_MRKNG_UNKNOWN 0 /* The outgoing network interface is not known */
455 #define NETSVC_MRKNG_LVL_L2 1 /* Default marking at layer 2 (for example Wi-Fi WMM) */
456 #define NETSVC_MRKNG_LVL_L3L2_ALL 2 /* Layer 3 DSCP marking and layer 2 marking for all Network Service Types */
457 #define NETSVC_MRKNG_LVL_L3L2_BK 3 /* The system policy limits layer 3 DSCP marking and layer 2 marking
458 * to background Network Service Types */
460 typedef __uint32_t sae_associd_t
;
461 #define SAE_ASSOCID_ANY 0
462 #define SAE_ASSOCID_ALL ((sae_associd_t)(-1ULL))
464 typedef __uint32_t sae_connid_t
;
465 #define SAE_CONNID_ANY 0
466 #define SAE_CONNID_ALL ((sae_connid_t)(-1ULL))
468 /* connectx() flag parameters */
469 #define CONNECT_RESUME_ON_READ_WRITE 0x1 /* resume connect() on read/write */
470 #define CONNECT_DATA_IDEMPOTENT 0x2 /* data is idempotent */
471 #define CONNECT_DATA_AUTHENTICATED 0x4 /* data includes security that replaces the TFO-cookie */
473 /* sockaddr endpoints */
474 typedef struct sa_endpoints
{
475 unsigned int sae_srcif
; /* optional source interface */
476 const struct sockaddr
*sae_srcaddr
; /* optional source address */
477 socklen_t sae_srcaddrlen
; /* size of source address */
478 const struct sockaddr
*sae_dstaddr
; /* destination address */
479 socklen_t sae_dstaddrlen
; /* size of destination address */
481 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
484 * Structure used for manipulating linger option.
487 int l_onoff
; /* option on/off */
488 int l_linger
; /* linger time */
492 struct accept_filter_arg
{
498 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
502 * Structure to control non-portable Sockets extension to POSIX
504 struct so_np_extensions
{
509 #define SONPX_SETOPTSHUT 0x000000001 /* flag for allowing setsockopt after shutdown */
512 #ifdef KERNEL_PRIVATE
513 #define SONPX_MASK_VALID (SONPX_SETOPTSHUT)
514 #define IS_SO_TC_BACKGROUND(_tc_) ((_tc_) == SO_TC_BK || (_tc_) == SO_TC_BK_SYS)
515 #define IS_SO_TC_BACKGROUNDSYSTEM(_tc_) ((_tc_) == SO_TC_BK_SYS)
516 #endif /* KERNEL_PRIVATE */
522 * Level number for (get/set)sockopt() to apply to socket itself.
524 #define SOL_SOCKET 0xffff /* options for socket level */
530 #define AF_UNSPEC 0 /* unspecified */
531 #define AF_UNIX 1 /* local to host (pipes) */
532 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
533 #define AF_LOCAL AF_UNIX /* backward compatibility */
534 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
535 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
536 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
537 #define AF_IMPLINK 3 /* arpanet imp addresses */
538 #define AF_PUP 4 /* pup protocols: e.g. BSP */
539 #define AF_CHAOS 5 /* mit CHAOS protocols */
540 #define AF_NS 6 /* XEROX NS protocols */
541 #define AF_ISO 7 /* ISO protocols */
542 #define AF_OSI AF_ISO
543 #define AF_ECMA 8 /* European computer manufacturers */
544 #define AF_DATAKIT 9 /* datakit protocols */
545 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
546 #define AF_SNA 11 /* IBM SNA */
547 #define AF_DECnet 12 /* DECnet */
548 #define AF_DLI 13 /* DEC Direct data link interface */
549 #define AF_LAT 14 /* LAT */
550 #define AF_HYLINK 15 /* NSC Hyperchannel */
551 #define AF_APPLETALK 16 /* Apple Talk */
552 #define AF_ROUTE 17 /* Internal Routing Protocol */
553 #define AF_LINK 18 /* Link layer interface */
554 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
555 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
556 #define AF_CNT 21 /* Computer Network Technology */
557 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
558 #define AF_IPX 23 /* Novell Internet Protocol */
559 #define AF_SIP 24 /* Simple Internet Protocol */
560 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
561 #define AF_NDRV 27 /* Network Driver 'raw' access */
562 #define AF_ISDN 28 /* Integrated Services Digital Network */
563 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
564 #define pseudo_AF_KEY 29 /* Internal key-management function */
565 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
566 #define AF_INET6 30 /* IPv6 */
567 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
568 #define AF_NATM 31 /* native ATM access */
569 #define AF_SYSTEM 32 /* Kernel event messages */
570 #define AF_NETBIOS 33 /* NetBIOS */
571 #define AF_PPP 34 /* PPP communication protocol */
572 #define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers
573 in interface output routine */
575 #define AF_AFP 36 /* Used by AFP */
577 #define AF_RESERVED_36 36 /* Reserved for internal usage */
579 #define AF_IEEE80211 37 /* IEEE 802.11 protocol */
582 #define AF_MULTIPATH 39
585 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
588 * [XSI] Structure used by kernel to store most addresses.
591 __uint8_t sa_len
; /* total length */
592 sa_family_t sa_family
; /* [XSI] address family */
593 char sa_data
[14]; /* [XSI] addr value (actually larger) */
596 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
597 #define SOCK_MAXADDRLEN 255 /* longest possible addresses */
600 * Structure used by kernel to pass protocol
601 * information in raw sockets.
604 __uint16_t sp_family
; /* address family */
605 __uint16_t sp_protocol
; /* protocol */
607 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
610 * RFC 2553: protocol-independent placeholder for socket addresses
612 #define _SS_MAXSIZE 128
613 #define _SS_ALIGNSIZE (sizeof(__int64_t))
614 #define _SS_PAD1SIZE \
615 (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
616 #define _SS_PAD2SIZE \
617 (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
618 _SS_PAD1SIZE - _SS_ALIGNSIZE)
621 * [XSI] sockaddr_storage
623 struct sockaddr_storage
{
624 __uint8_t ss_len
; /* address length */
625 sa_family_t ss_family
; /* [XSI] address family */
626 char __ss_pad1
[_SS_PAD1SIZE
];
627 __int64_t __ss_align
; /* force structure storage alignment */
628 char __ss_pad2
[_SS_PAD2SIZE
];
632 * Protocol families, same as address families for now.
634 #define PF_UNSPEC AF_UNSPEC
635 #define PF_LOCAL AF_LOCAL
636 #define PF_UNIX PF_LOCAL /* backward compatibility */
637 #define PF_INET AF_INET
638 #define PF_IMPLINK AF_IMPLINK
639 #define PF_PUP AF_PUP
640 #define PF_CHAOS AF_CHAOS
642 #define PF_ISO AF_ISO
643 #define PF_OSI AF_ISO
644 #define PF_ECMA AF_ECMA
645 #define PF_DATAKIT AF_DATAKIT
646 #define PF_CCITT AF_CCITT
647 #define PF_SNA AF_SNA
648 #define PF_DECnet AF_DECnet
649 #define PF_DLI AF_DLI
650 #define PF_LAT AF_LAT
651 #define PF_HYLINK AF_HYLINK
652 #define PF_APPLETALK AF_APPLETALK
653 #define PF_ROUTE AF_ROUTE
654 #define PF_LINK AF_LINK
655 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
656 #define PF_COIP AF_COIP
657 #define PF_CNT AF_CNT
658 #define PF_SIP AF_SIP
659 #define PF_IPX AF_IPX /* same format as AF_NS */
660 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
661 #define PF_PIP pseudo_AF_PIP
662 #define PF_NDRV AF_NDRV
663 #define PF_ISDN AF_ISDN
664 #define PF_KEY pseudo_AF_KEY
665 #define PF_INET6 AF_INET6
666 #define PF_NATM AF_NATM
667 #define PF_SYSTEM AF_SYSTEM
668 #define PF_NETBIOS AF_NETBIOS
669 #define PF_PPP AF_PPP
671 #define PF_AFP AF_AFP
673 #define PF_RESERVED_36 AF_RESERVED_36
675 #define PF_UTUN AF_UTUN
677 #define PF_MULTIPATH AF_MULTIPATH
679 #define PF_MAX AF_MAX
682 * These do not have socket-layer support:
684 #define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */
685 #define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */
686 #ifdef KERNEL_PRIVATE
687 #define PF_BRIDGE ((uint32_t)0x62726467) /* 'brdg' */
688 #endif /* KERNEL_PRIVATE */
691 * Definitions for network related sysctl, CTL_NET.
693 * Second level is protocol family.
694 * Third level is protocol number.
696 * Further levels are defined by the individual families below.
698 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
699 #define NET_MAXID AF_MAX
700 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
702 #ifdef KERNEL_PRIVATE
703 #define CTL_NET_NAMES { \
705 { "local", CTLTYPE_NODE }, \
706 { "inet", CTLTYPE_NODE }, \
707 { "implink", CTLTYPE_NODE }, \
708 { "pup", CTLTYPE_NODE }, \
709 { "chaos", CTLTYPE_NODE }, \
710 { "xerox_ns", CTLTYPE_NODE }, \
711 { "iso", CTLTYPE_NODE }, \
712 { "emca", CTLTYPE_NODE }, \
713 { "datakit", CTLTYPE_NODE }, \
714 { "ccitt", CTLTYPE_NODE }, \
715 { "ibm_sna", CTLTYPE_NODE }, \
716 { "decnet", CTLTYPE_NODE }, \
717 { "dec_dli", CTLTYPE_NODE }, \
718 { "lat", CTLTYPE_NODE }, \
719 { "hylink", CTLTYPE_NODE }, \
720 { "appletalk", CTLTYPE_NODE }, \
721 { "route", CTLTYPE_NODE }, \
722 { "link_layer", CTLTYPE_NODE }, \
723 { "xtp", CTLTYPE_NODE }, \
724 { "coip", CTLTYPE_NODE }, \
725 { "cnt", CTLTYPE_NODE }, \
726 { "rtip", CTLTYPE_NODE }, \
727 { "ipx", CTLTYPE_NODE }, \
728 { "sip", CTLTYPE_NODE }, \
729 { "pip", CTLTYPE_NODE }, \
731 { "ndrv", CTLTYPE_NODE }, \
732 { "isdn", CTLTYPE_NODE }, \
733 { "key", CTLTYPE_NODE }, \
734 { "inet6", CTLTYPE_NODE }, \
735 { "natm", CTLTYPE_NODE }, \
736 { "sys", CTLTYPE_NODE }, \
737 { "netbios", CTLTYPE_NODE }, \
738 { "ppp", CTLTYPE_NODE }, \
739 { "hdrcomplete", CTLTYPE_NODE }, \
741 #endif /* KERNEL_PRIVATE */
743 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
745 * PF_ROUTE - Routing table
747 * Three additional levels are defined:
748 * Fourth: address family, 0 is wildcard
749 * Fifth: type of info, defined below
750 * Sixth: flag(s) to mask with for NET_RT_FLAGS
752 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
753 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
754 #define NET_RT_IFLIST 3 /* survey interface list */
755 #define NET_RT_STAT 4 /* routing statistics */
756 #define NET_RT_TRASH 5 /* routes not in table but not freed */
757 #define NET_RT_IFLIST2 6 /* interface list with addresses */
758 #define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
760 #define NET_RT_DUMPX 8 /* private */
761 #define NET_RT_DUMPX_FLAGS 9 /* private */
763 #define NET_RT_MAXID 10
764 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
766 #ifdef KERNEL_PRIVATE
767 #define CTL_NET_RT_NAMES { \
769 { "dump", CTLTYPE_STRUCT }, \
770 { "flags", CTLTYPE_STRUCT }, \
771 { "iflist", CTLTYPE_STRUCT }, \
772 { "stat", CTLTYPE_STRUCT }, \
773 { "trash", CTLTYPE_INT }, \
774 { "iflist2", CTLTYPE_STRUCT }, \
775 { "dump2", CTLTYPE_STRUCT }, \
776 { "dumpx", CTLTYPE_STRUCT }, \
777 { "dumpx_flags", CTLTYPE_STRUCT }, \
780 #endif /* KERNEL_PRIVATE */
783 * Maximum queue length specifiable by listen.
785 #define SOMAXCONN 128
788 * [XSI] Message header for recvmsg and sendmsg calls.
789 * Used value-result for recvmsg, value only for sendmsg.
792 void *msg_name
; /* [XSI] optional address */
793 socklen_t msg_namelen
; /* [XSI] size of address */
794 struct iovec
*msg_iov
; /* [XSI] scatter/gather array */
795 int msg_iovlen
; /* [XSI] # elements in msg_iov */
796 void *msg_control
; /* [XSI] ancillary data, see below */
797 socklen_t msg_controllen
; /* [XSI] ancillary data buffer len */
798 int msg_flags
; /* [XSI] flags on received message */
803 * Extended version for sendmsg_x() and recvmsg_x() calls
805 * For recvmsg_x(), the size of the data received is given by the field
808 * For sendmsg_x(), the size of the data to send is given by the length of
809 * the iovec array -- like sendmsg(). The field msg_datalen is ignored.
812 void *msg_name
; /* optional address */
813 socklen_t msg_namelen
; /* size of address */
814 struct iovec
*msg_iov
; /* scatter/gather array */
815 int msg_iovlen
; /* # elements in msg_iov */
816 void *msg_control
; /* ancillary data, see below */
817 socklen_t msg_controllen
; /* ancillary data buffer len */
818 int msg_flags
; /* flags on received message */
819 size_t msg_datalen
; /* byte length of buffer in msg_iov */
823 #ifdef XNU_KERNEL_PRIVATE
825 * In-kernel representation of "struct msghdr" from
826 * userspace. Has enough precision for 32-bit or
827 * 64-bit clients, but does not need to be packed.
831 user_addr_t msg_name
; /* optional address */
832 socklen_t msg_namelen
; /* size of address */
833 user_addr_t msg_iov
; /* scatter/gather array */
834 int msg_iovlen
; /* # elements in msg_iov */
835 user_addr_t msg_control
; /* ancillary data, see below */
836 socklen_t msg_controllen
; /* ancillary data buffer len */
837 int msg_flags
; /* flags on received message */
841 * LP64 user version of struct msghdr.
842 * WARNING - keep in sync with struct msghdr
845 struct user64_msghdr
{
846 user64_addr_t msg_name
; /* optional address */
847 socklen_t msg_namelen
; /* size of address */
848 user64_addr_t msg_iov
; /* scatter/gather array */
849 int msg_iovlen
; /* # elements in msg_iov */
850 user64_addr_t msg_control
; /* ancillary data, see below */
851 socklen_t msg_controllen
; /* ancillary data buffer len */
852 int msg_flags
; /* flags on received message */
856 * ILP32 user version of struct msghdr.
857 * WARNING - keep in sync with struct msghdr
860 struct user32_msghdr
{
861 user32_addr_t msg_name
; /* optional address */
862 socklen_t msg_namelen
; /* size of address */
863 user32_addr_t msg_iov
; /* scatter/gather array */
864 int msg_iovlen
; /* # elements in msg_iov */
865 user32_addr_t msg_control
; /* ancillary data, see below */
866 socklen_t msg_controllen
; /* ancillary data buffer len */
867 int msg_flags
; /* flags on received message */
871 * In-kernel representation of "struct msghdr_x" from
872 * userspace. Has enough precision for 32-bit or
873 * 64-bit clients, but does not need to be packed.
876 struct user_msghdr_x
{
877 user_addr_t msg_name
; /* optional address */
878 socklen_t msg_namelen
; /* size of address */
879 user_addr_t msg_iov
; /* scatter/gather array */
880 int msg_iovlen
; /* # elements in msg_iov */
881 user_addr_t msg_control
; /* ancillary data, see below */
882 socklen_t msg_controllen
; /* ancillary data buffer len */
883 int msg_flags
; /* flags on received message */
884 size_t msg_datalen
; /* byte length of buffer in msg_iov */
888 * LP64 user version of struct msghdr_x
889 * WARNING - keep in sync with struct msghdr_x
892 struct user64_msghdr_x
{
893 user64_addr_t msg_name
; /* optional address */
894 socklen_t msg_namelen
; /* size of address */
895 user64_addr_t msg_iov
; /* scatter/gather array */
896 int msg_iovlen
; /* # elements in msg_iov */
897 user64_addr_t msg_control
; /* ancillary data, see below */
898 socklen_t msg_controllen
; /* ancillary data buffer len */
899 int msg_flags
; /* flags on received message */
900 user64_size_t msg_datalen
; /* byte length of buffer in msg_iov */
904 * ILP32 user version of struct msghdr_x
905 * WARNING - keep in sync with struct msghdr_x
908 struct user32_msghdr_x
{
909 user32_addr_t msg_name
; /* optional address */
910 socklen_t msg_namelen
; /* size of address */
911 user32_addr_t msg_iov
; /* scatter/gather array */
912 int msg_iovlen
; /* # elements in msg_iov */
913 user32_addr_t msg_control
; /* ancillary data, see below */
914 socklen_t msg_controllen
; /* ancillary data buffer len */
915 int msg_flags
; /* flags on received message */
916 user32_size_t msg_datalen
; /* byte length of buffer in msg_iov */
920 * In-kernel representation of "struct sa_endpoints" from
921 * userspace. Has enough precision for 32-bit or
922 * 64-bit clients, but does not need to be packed.
925 struct user_sa_endpoints
{
926 unsigned int sae_srcif
; /* optional source interface */
927 user_addr_t sae_srcaddr
; /* optional source address */
928 socklen_t sae_srcaddrlen
; /* size of source address */
929 user_addr_t sae_dstaddr
; /* destination address */
930 socklen_t sae_dstaddrlen
; /* size of destination address */
934 * LP64 user version of struct sa_endpoints
935 * WARNING - keep in sync with struct sa_endpoints
938 struct user64_sa_endpoints
{
939 unsigned int sae_srcif
; /* optional source interface */
940 user64_addr_t sae_srcaddr
; /* optional source address */
941 socklen_t sae_srcaddrlen
; /* size of source address */
942 user64_addr_t sae_dstaddr
; /* destination address */
943 socklen_t sae_dstaddrlen
; /* size of destination address */
947 * ILP32 user version of struct sa_endpoints
948 * WARNING - keep in sync with struct sa_endpoints
951 struct user32_sa_endpoints
{
952 unsigned int sae_srcif
; /* optional source interface */
953 user32_addr_t sae_srcaddr
; /* optional source address */
954 socklen_t sae_srcaddrlen
; /* size of source address */
955 user32_addr_t sae_dstaddr
; /* destination address */
956 socklen_t sae_dstaddrlen
; /* size of destination address */
959 #endif /* XNU_KERNEL_PRIVATE */
961 #define MSG_OOB 0x1 /* process out-of-band data */
962 #define MSG_PEEK 0x2 /* peek at incoming message */
963 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
964 #define MSG_EOR 0x8 /* data completes record */
965 #define MSG_TRUNC 0x10 /* data discarded before delivery */
966 #define MSG_CTRUNC 0x20 /* control data lost before delivery */
967 #define MSG_WAITALL 0x40 /* wait for full request or error */
968 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
969 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
970 #define MSG_EOF 0x100 /* data completes connection */
973 #ifdef __APPLE_API_OBSOLETE
974 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
977 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
979 #define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp */
980 #define MSG_HOLD 0x800 /* Hold frag in so_temp */
981 #define MSG_SEND 0x1000 /* Send the packet in so_temp */
982 #define MSG_HAVEMORE 0x2000 /* Data ready to be read */
983 #define MSG_RCVMORE 0x4000 /* Data remains in current pkt */
985 #ifdef KERNEL_PRIVATE
986 #define MSG_COMPAT 0x8000 /* deprecated */
987 #endif /* KERNEL_PRIVATE */
988 #define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */
989 #ifdef KERNEL_PRIVATE
990 #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */
991 #define MSG_SKIPCFIL 0x40000 /* skip pass content filter */
994 #define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */
996 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
999 * Header for ancillary data objects in msg_control buffer.
1000 * Used for additional information with/about a datagram
1001 * not expressible by flags. The format is a sequence
1002 * of message elements headed by cmsghdr structures.
1005 socklen_t cmsg_len
; /* [XSI] data byte count, including hdr */
1006 int cmsg_level
; /* [XSI] originating protocol */
1007 int cmsg_type
; /* [XSI] protocol-specific type */
1008 /* followed by unsigned char cmsg_data[]; */
1011 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1014 * While we may have more groups than this, the cmsgcred struct must
1015 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
1018 #define CMGROUP_MAX 16
1021 * Credentials structure, used to verify the identity of a peer
1022 * process that has sent us a message. This is allocated by the
1023 * peer process but filled in by the kernel. This prevents the
1024 * peer from lying about its identity. (Note that cmcred_groups[0]
1025 * is the effective GID.)
1028 pid_t cmcred_pid
; /* PID of sending process */
1029 uid_t cmcred_uid
; /* real UID of sending process */
1030 uid_t cmcred_euid
; /* effective UID of sending process */
1031 gid_t cmcred_gid
; /* real GID of sending process */
1032 short cmcred_ngroups
; /* number or groups */
1033 gid_t cmcred_groups
[CMGROUP_MAX
]; /* groups */
1036 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1038 /* given pointer to struct cmsghdr, return pointer to data */
1039 #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
1040 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
1043 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
1044 * an empty list for some reasons.
1046 #define CMSG_FIRSTHDR(mhdr) \
1047 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
1048 (struct cmsghdr *)(mhdr)->msg_control : \
1049 (struct cmsghdr *)0L)
1053 * Given pointer to struct cmsghdr, return pointer to next cmsghdr
1054 * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
1056 #define CMSG_NXTHDR(mhdr, cmsg) \
1057 ((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) : \
1058 ((((unsigned char *)(cmsg) + \
1059 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \
1060 __DARWIN_ALIGN32(sizeof(struct cmsghdr))) > \
1061 ((unsigned char *)(mhdr)->msg_control + \
1062 (mhdr)->msg_controllen)) ? \
1063 (struct cmsghdr *)0L /* NULL */ : \
1064 (struct cmsghdr *)(void *)((unsigned char *)(cmsg) + \
1065 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
1067 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1068 /* RFC 2292 additions */
1069 #define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
1070 #define CMSG_LEN(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
1073 #define CMSG_ALIGN(n) __DARWIN_ALIGN32(n)
1075 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1077 /* "Socket"-level control message types: */
1078 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
1079 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1080 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
1081 #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
1082 #define SCM_TIMESTAMP_MONOTONIC 0x04 /* timestamp (uint64_t) */
1085 #define SCM_SEQNUM 0x05 /* TCP unordered recv seq no */
1086 #define SCM_MSG_PRIORITY 0x06 /* TCP unordered snd priority */
1087 #endif /* PRIVATE */
1089 #ifdef KERNEL_PRIVATE
1091 * 4.3 compat sockaddr (deprecated)
1094 __uint16_t sa_family
; /* address family */
1095 char sa_data
[14]; /* up to 14 bytes of direct address */
1099 * 4.3-compat message header (deprecated)
1102 void *msg_name
; /* optional address */
1103 socklen_t msg_namelen
; /* size of address */
1104 struct iovec
*msg_iov
; /* scatter/gather array */
1105 int msg_iovlen
; /* # elements in msg_iov */
1106 void *msg_accrights
; /* access rights sent/rcvd */
1107 int msg_accrightslen
;
1110 #define SA(s) ((struct sockaddr *)(void *)(s))
1111 #endif /* KERNEL_PRIVATE */
1112 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1115 * howto arguments for shutdown(2), specified by Posix.1g.
1117 #define SHUT_RD 0 /* shut down the reading side */
1118 #define SHUT_WR 1 /* shut down the writing side */
1119 #define SHUT_RDWR 2 /* shut down both sides */
1121 #if !defined(_POSIX_C_SOURCE)
1123 * sendfile(2) header/trailer struct
1126 struct iovec
*headers
; /* pointer to an array of header struct iovec's */
1127 int hdr_cnt
; /* number of header iovec's */
1128 struct iovec
*trailers
; /* pointer to an array of trailer struct iovec's */
1129 int trl_cnt
; /* number of trailer iovec's */
1134 /* In-kernel representation */
1135 struct user_sf_hdtr
{
1136 user_addr_t headers
; /* pointer to an array of header struct iovec's */
1137 int hdr_cnt
; /* number of header iovec's */
1138 user_addr_t trailers
; /* pointer to an array of trailer struct iovec's */
1139 int trl_cnt
; /* number of trailer iovec's */
1142 /* LP64 user version of struct sf_hdtr */
1143 struct user64_sf_hdtr
{
1144 user64_addr_t headers
; /* pointer to an array of header struct iovec's */
1145 int hdr_cnt
; /* number of header iovec's */
1146 user64_addr_t trailers
; /* pointer to an array of trailer struct iovec's */
1147 int trl_cnt
; /* number of trailer iovec's */
1150 /* ILP32 user version of struct sf_hdtr */
1151 struct user32_sf_hdtr
{
1152 user32_addr_t headers
; /* pointer to an array of header struct iovec's */
1153 int hdr_cnt
; /* number of header iovec's */
1154 user32_addr_t trailers
; /* pointer to an array of trailer struct iovec's */
1155 int trl_cnt
; /* number of trailer iovec's */
1160 #endif /* !_POSIX_C_SOURCE */
1163 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1166 * Structure for SIOCGASSOCIDS
1169 __uint32_t sar_cnt
; /* number of associations */
1170 sae_associd_t
*sar_aidp
; /* array of association IDs */
1173 #ifdef BSD_KERNEL_PRIVATE
1174 struct so_aidreq32
{
1176 user32_addr_t sar_aidp
;
1179 struct so_aidreq64
{
1181 user64_addr_t sar_aidp
__attribute__((aligned(8)));
1183 #endif /* BSD_KERNEL_PRIVATE */
1186 * Structure for SIOCGCONNIDS
1189 sae_associd_t scr_aid
; /* association ID */
1190 __uint32_t scr_cnt
; /* number of connections */
1191 sae_connid_t
*scr_cidp
; /* array of connection IDs */
1194 #ifdef BSD_KERNEL_PRIVATE
1195 struct so_cidreq32
{
1196 sae_associd_t scr_aid
;
1198 user32_addr_t scr_cidp
;
1201 struct so_cidreq64
{
1202 sae_associd_t scr_aid
;
1204 user64_addr_t scr_cidp
__attribute__((aligned(8)));
1206 #endif /* BSD_KERNEL_PRIVATE */
1209 * Structure for SIOCGCONNINFO
1211 struct so_cinforeq
{
1212 sae_connid_t scir_cid
; /* connection ID */
1213 __uint32_t scir_flags
; /* see flags below */
1214 __uint32_t scir_ifindex
; /* (last) outbound interface */
1215 __int32_t scir_error
; /* most recent error */
1216 struct sockaddr
*scir_src
; /* source address */
1217 socklen_t scir_src_len
; /* source address len */
1218 struct sockaddr
*scir_dst
; /* destination address */
1219 socklen_t scir_dst_len
; /* destination address len */
1220 __uint32_t scir_aux_type
; /* aux data type (CIAUX) */
1221 void *scir_aux_data
; /* aux data */
1222 __uint32_t scir_aux_len
; /* aux data len */
1225 #ifdef BSD_KERNEL_PRIVATE
1226 struct so_cinforeq32
{
1227 sae_connid_t scir_cid
;
1228 __uint32_t scir_flags
;
1229 __uint32_t scir_ifindex
;
1230 __int32_t scir_error
;
1231 user32_addr_t scir_src
;
1232 socklen_t scir_src_len
;
1233 user32_addr_t scir_dst
;
1234 socklen_t scir_dst_len
;
1235 __uint32_t scir_aux_type
;
1236 user32_addr_t scir_aux_data
;
1237 __uint32_t scir_aux_len
;
1240 struct so_cinforeq64
{
1241 sae_connid_t scir_cid
;
1242 __uint32_t scir_flags
;
1243 __uint32_t scir_ifindex
;
1244 __int32_t scir_error
;
1245 user64_addr_t scir_src
__attribute__((aligned(8)));
1246 socklen_t scir_src_len
;
1247 user64_addr_t scir_dst
__attribute__((aligned(8)));
1248 socklen_t scir_dst_len
;
1249 __uint32_t scir_aux_type
;
1250 user64_addr_t scir_aux_data
__attribute__((aligned(8)));
1251 __uint32_t scir_aux_len
;
1253 #endif /* BSD_KERNEL_PRIVATE */
1255 /* valid connection info flags */
1256 #define CIF_CONNECTING 0x1 /* connection was attempted */
1257 #define CIF_CONNECTED 0x2 /* connection is established */
1258 #define CIF_DISCONNECTING 0x4 /* disconnection was attempted */
1259 #define CIF_DISCONNECTED 0x8 /* has been disconnected */
1260 #define CIF_BOUND_IF 0x10 /* bound to an interface */
1261 #define CIF_BOUND_IP 0x20 /* bound to a src address */
1262 #define CIF_BOUND_PORT 0x40 /* bound to a src port */
1263 #define CIF_PREFERRED 0x80 /* connection is primary/preferred */
1264 #define CIF_MP_CAPABLE 0x100 /* supports multipath protocol */
1265 #define CIF_MP_READY 0x200 /* multipath protocol confirmed */
1266 #define CIF_MP_DEGRADED 0x400 /* has lost its multipath capability */
1267 #define CIF_MP_ACTIVE 0x800 /* this is the active subflow */
1269 /* valid connection info auxiliary data types */
1270 #define CIAUX_TCP 0x1 /* TCP auxiliary data (conninfo_tcp_t) */
1271 #define CIAUX_MPTCP 0x2 /* MPTCP auxiliary data (conninfo_mptcp_t) */
1274 * Structure for SIOC{S,G}CONNORDER
1277 sae_connid_t sco_cid
; /* connection ID */
1278 __uint32_t sco_rank
; /* rank (0 means unspecified) */
1282 * Common structure for KEV_NETPOLICY_SUBCLASS
1284 struct netpolicy_event_data
{
1285 __uint64_t eupid
; /* effective unique PID */
1286 pid_t epid
; /* effective PID */
1287 #if !defined(__LP64__)
1289 #endif /* __LP64__ */
1290 uuid_t euuid
; /* effective UUID */
1294 * NETPOLICY_IFDENIED event structure
1296 struct kev_netpolicy_ifdenied
{
1297 struct netpolicy_event_data ev_data
;
1298 __uint32_t ev_if_functional_type
;
1302 * Common structure for KEV_SOCKET_SUBCLASS
1304 struct kev_socket_event_data
{
1305 struct sockaddr_storage kev_sockname
;
1306 struct sockaddr_storage kev_peername
;
1309 struct kev_socket_closed
{
1310 struct kev_socket_event_data ev_data
;
1314 * Network Service Type to DiffServ Code Point mapping
1316 struct netsvctype_dscp_map
{
1318 u_int8_t dscp
; /* 6 bits diffserv code point */
1324 extern int peeloff(int s
, sae_associd_t
);
1325 extern int socket_delegate(int, int, int, pid_t
);
1328 * recvmsg_x() is a system call similar to recvmsg(2) to receive
1329 * several datagrams at once in the array of message headers "msgp".
1331 * recvmsg_x() can be used only with protocols handlers that have been specially
1332 * modified to support sending and receiving several datagrams at once.
1334 * The size of the array "msgp" is given by the argument "cnt".
1336 * The "flags" arguments supports only the value MSG_DONTWAIT.
1338 * Each member of "msgp" array is of type "struct msghdr_x".
1340 * The "msg_iov" and "msg_iovlen" are input parameters that describe where to
1341 * store a datagram in a scatter gather locations of buffers -- see recvmsg(2).
1342 * On output the field "msg_datalen" gives the length of the received datagram.
1344 * The field "msg_flags" must be set to zero on input. On output, "msg_flags"
1345 * may have MSG_TRUNC set to indicate the trailing portion of the datagram was
1346 * discarded because the datagram was larger than the buffer supplied.
1347 * recvmsg_x() returns as soon as a datagram is truncated.
1349 * recvmsg_x() may return with less than "cnt" datagrams received based on
1350 * the low water mark and the amount of data pending in the socket buffer.
1352 * recvmsg_x() returns the number of datagrams that have been received,
1353 * or -1 if an error occurred.
1355 * NOTE: This a private system call, the API is subject to change.
1357 ssize_t
recvmsg_x(int s
, const struct msghdr_x
*msgp
, u_int cnt
, int flags
);
1360 * sendmsg_x() is a system call similar to send(2) to send
1361 * several datagrams at once in the array of message headers "msgp".
1363 * sendmsg_x() can be used only with protocols handlers that have been specially
1364 * modified to support sending and receiving several datagrams at once.
1366 * The size of the array "msgp" is given by the argument "cnt".
1368 * The "flags" arguments supports only the value MSG_DONTWAIT.
1370 * Each member of "msgp" array is of type "struct msghdr_x".
1372 * The "msg_iov" and "msg_iovlen" are input parameters that specify the
1373 * data to be sent in a scatter gather locations of buffers -- see sendmsg(2).
1375 * sendmsg_x() fails with EMSGSIZE if the sum of the length of the datagrams
1376 * is greater than the high water mark.
1378 * Address and ancillary data are not supported so the following fields
1379 * must be set to zero on input:
1380 * "msg_name", "msg_namelen", "msg_control" and "msg_controllen".
1382 * The field "msg_flags" and "msg_datalen" must be set to zero on input.
1384 * sendmsg_x() returns the number of datagrams that have been sent,
1385 * or -1 if an error occurred.
1387 * NOTE: This a private system call, the API is subject to change.
1389 ssize_t
sendmsg_x(int s
, const struct msghdr_x
*msgp
, u_int cnt
, int flags
);
1391 #endif /* !KERNEL */
1392 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1393 #endif /* PRIVATE */
1398 int accept(int, struct sockaddr
* __restrict
, socklen_t
* __restrict
)
1399 __DARWIN_ALIAS_C(accept
);
1400 int bind(int, const struct sockaddr
*, socklen_t
) __DARWIN_ALIAS(bind
);
1401 int connect(int, const struct sockaddr
*, socklen_t
) __DARWIN_ALIAS_C(connect
);
1402 int getpeername(int, struct sockaddr
* __restrict
, socklen_t
* __restrict
)
1403 __DARWIN_ALIAS(getpeername
);
1404 int getsockname(int, struct sockaddr
* __restrict
, socklen_t
* __restrict
)
1405 __DARWIN_ALIAS(getsockname
);
1406 int getsockopt(int, int, int, void * __restrict
, socklen_t
* __restrict
);
1407 int listen(int, int) __DARWIN_ALIAS(listen
);
1408 ssize_t
recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv
);
1409 ssize_t
recvfrom(int, void *, size_t, int, struct sockaddr
* __restrict
,
1410 socklen_t
* __restrict
) __DARWIN_ALIAS_C(recvfrom
);
1411 ssize_t
recvmsg(int, struct msghdr
*, int) __DARWIN_ALIAS_C(recvmsg
);
1412 ssize_t
send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send
);
1413 ssize_t
sendmsg(int, const struct msghdr
*, int) __DARWIN_ALIAS_C(sendmsg
);
1414 ssize_t
sendto(int, const void *, size_t,
1415 int, const struct sockaddr
*, socklen_t
) __DARWIN_ALIAS_C(sendto
);
1416 int setsockopt(int, int, int, const void *, socklen_t
);
1417 int shutdown(int, int);
1418 int sockatmark(int) __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
);
1419 int socket(int, int, int);
1420 int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair
);
1422 #if !defined(_POSIX_C_SOURCE)
1423 int sendfile(int, int, off_t
, off_t
*, struct sf_hdtr
*, int);
1424 #endif /* !_POSIX_C_SOURCE */
1426 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1427 void pfctlinput(int, struct sockaddr
*);
1429 __API_AVAILABLE(macosx(10.11), ios(9.0), tvos(9.0), watchos(2.0))
1430 int connectx(int, const sa_endpoints_t
*, sae_associd_t
, unsigned int,
1431 const struct iovec
*, unsigned int, size_t *, sae_connid_t
*);
1433 __API_AVAILABLE(macosx(10.11), ios(9.0), tvos(9.0), watchos(2.0))
1434 int disconnectx(int, sae_associd_t
, sae_connid_t
);
1435 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1437 #endif /* !KERNEL */
1440 #include <sys/kpi_socket.h>
1443 #endif /* !_SYS_SOCKET_H_ */