]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/socket.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / socket.h
CommitLineData
1c79356b 1/*
cb323159 2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
39037602 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
39037602 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
39037602 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
39037602 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30/*
31 * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
32 * The Regents of the University of California. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)socket.h 8.4 (Berkeley) 2/21/94
9bccf70c 63 * $FreeBSD: src/sys/sys/socket.h,v 1.39.2.7 2001/07/03 11:02:01 ume Exp $
1c79356b 64 */
2d21ac55
A
65/*
66 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
67 * support for mandatory and extensible security protections. This notice
68 * is included in support of clause 2.2 (b) of the Apple Public License,
69 * Version 2.0.
70 */
1c79356b
A
71
72#ifndef _SYS_SOCKET_H_
0a7de745 73#define _SYS_SOCKET_H_
1c79356b 74
b0d623f7 75#include <sys/types.h>
91447636 76#include <sys/cdefs.h>
2d21ac55 77#include <machine/_param.h>
39037602 78#include <net/net_kev.h>
1c79356b 79
6d2010ae
A
80#ifdef PRIVATE
81#include <sys/param.h>
39236c6e 82#include <uuid/uuid.h>
6d2010ae
A
83#endif /* PRIVATE */
84
39236c6e 85#ifndef KERNEL
6d2010ae
A
86#include <Availability.h>
87#endif
88
1c79356b
A
89/*
90 * Definitions related to sockets: types, address families, options.
91 */
92
9bccf70c
A
93/*
94 * Data types.
95 */
91447636 96
39236c6e
A
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>
91447636
A
102
103/* XXX Not explicitly defined by POSIX, but function return types are */
39236c6e 104#include <sys/_types/_size_t.h>
39037602 105
91447636 106/* XXX Not explicitly defined by POSIX, but function return types are */
39236c6e 107#include <sys/_types/_ssize_t.h>
91447636
A
108
109/*
110 * [XSI] The iovec structure shall be defined as described in <sys/uio.h>.
111 */
39236c6e 112#include <sys/_types/_iovec_t.h>
6d2010ae 113
1c79356b
A
114/*
115 * Types
116 */
0a7de745
A
117#define SOCK_STREAM 1 /* stream socket */
118#define SOCK_DGRAM 2 /* datagram socket */
119#define SOCK_RAW 3 /* raw-protocol interface */
2d21ac55 120#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
121#define SOCK_RDM 4 /* reliably-delivered message */
122#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
123#define SOCK_SEQPACKET 5 /* sequenced packet stream */
1c79356b
A
124
125/*
126 * Option flags per-socket.
127 */
0a7de745
A
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 */
2d21ac55 134#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
135#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
136#define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */
91447636 137#else
0a7de745
A
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 */
2d21ac55 141#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
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 */
9bccf70c 145#ifndef __APPLE__
0a7de745 146#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
9bccf70c 147#else
0a7de745
A
148#define SO_DONTTRUNC 0x2000 /* APPLE: Retain unread data */
149 /* (ATOMIC proto) */
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 */
316670eb 152
fe8ab488 153#ifdef PRIVATE
0a7de745
A
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 */
156#define SO_TIMESTAMP_CONTINUOUS 0x40000 /* Continuous monotonic timestamp on rcvd dgram */
fe8ab488
A
157#endif
158
316670eb 159#endif /* (!__APPLE__) */
0a7de745 160#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b
A
161
162/*
163 * Additional options, not kept in so_options.
164 */
0a7de745
A
165#define SO_SNDBUF 0x1001 /* send buffer size */
166#define SO_RCVBUF 0x1002 /* receive buffer size */
167#define SO_SNDLOWAT 0x1003 /* send low-water mark */
168#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
169#define SO_SNDTIMEO 0x1005 /* send timeout */
170#define SO_RCVTIMEO 0x1006 /* receive timeout */
171#define SO_ERROR 0x1007 /* get error status and clear */
172#define SO_TYPE 0x1008 /* get socket type */
2d21ac55 173#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
f427ee49
A
174#define SO_LABEL 0x1010 /* deprecated */
175#define SO_PEERLABEL 0x1011 /* deprecated */
9bccf70c 176#ifdef __APPLE__
0a7de745
A
177#define SO_NREAD 0x1020 /* APPLE: get 1st-packet byte count */
178#define SO_NKE 0x1021 /* APPLE: Install socket-level NKE */
179#define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */
180#define SO_NOADDRERR 0x1023 /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
181#define SO_NWRITE 0x1024 /* APPLE: Get number of bytes currently in send socket buffer */
182#define SO_REUSESHAREUID 0x1025 /* APPLE: Allow reuse of port/socket by different userids */
2d21ac55 183#ifdef __APPLE_API_PRIVATE
0a7de745
A
184#define SO_NOTIFYCONFLICT 0x1026 /* APPLE: send notification if there is a bind on a port which is already in use */
185#define SO_UPCALLCLOSEWAIT 0x1027 /* APPLE: block on close until an upcall returns */
2d21ac55 186#endif
0a7de745 187#define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */
39236c6e 188#ifdef PRIVATE
0a7de745
A
189#define SO_RESTRICTIONS 0x1081 /* APPLE: deny flag set */
190#define SO_RESTRICT_DENY_IN 0x1 /* deny inbound (trapdoor) */
191#define SO_RESTRICT_DENY_OUT 0x2 /* deny outbound (trapdoor) */
192#define SO_RESTRICT_DENY_CELLULAR 0x4 /* deny use of cellular (trapdoor) */
193#define SO_RESTRICT_DENY_EXPENSIVE 0x8 /* deny use of expensive if (trapdoor) */
cb323159 194#define SO_RESTRICT_DENY_CONSTRAINED 0x10 /* deny use of expensive if (trapdoor) */
39236c6e 195#endif /* PRIVATE */
0a7de745
A
196#define SO_RANDOMPORT 0x1082 /* APPLE: request local port randomization */
197#define SO_NP_EXTENSIONS 0x1083 /* To turn off some POSIX behavior */
9bccf70c 198#endif
6d2010ae 199
2d21ac55 200#ifdef PRIVATE
0a7de745 201#define SO_EXECPATH 0x1085 /* Application Firewall Socket option */
39037602 202
316670eb
A
203/*
204 * Traffic service class definitions (lowest to highest):
205 *
206 * SO_TC_BK_SYS
207 * "Background System-Initiated", high delay tolerant, high loss
208 * tolerant, elastic flow, variable size & long-lived. E.g: system-
209 * initiated iCloud synching or Time Capsule backup, for which there
210 * is no progress feedbacks.
211 *
212 * SO_TC_BK
213 * "Background", user-initiated, high delay tolerant, high loss tolerant,
214 * elastic flow, variable size. E.g. user-initiated iCloud synching or
215 * Time Capsule backup; or traffics of background applications, for which
216 * there is some progress feedbacks.
217 *
218 * SO_TC_BE
219 * "Best Effort", unclassified/standard. This is the default service
220 * class; pretty much a mix of everything.
221 *
222 * SO_TC_RD
223 * "Responsive Data", a notch higher than "Best Effort", medium delay
224 * tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email,
225 * instant messaging, for which there is a sense of interactivity and
226 * urgency (user waiting for output).
227 *
228 * SO_TC_OAM
229 * "Operations, Administration, and Management", medium delay tolerant,
230 * low-medium loss tolerant, elastic & inelastic flows, variable size.
231 * E.g. VPN tunnels.
232 *
233 * SO_TC_AV
234 * "Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
235 * loss tolerant, elastic flow, constant packet interval, variable rate &
236 * size. E.g. AirPlay playback (both video and audio).
237 *
238 * SO_TC_RV
239 * "Responsive Multimedia Audio/Video", low delay tolerant, low-medium
240 * loss tolerant, elastic flow, variable packet interval, rate and size.
241 * E.g. AirPlay mirroring, screen sharing.
242 *
243 * SO_TC_VI
244 * "Interactive Video", low delay tolerant, low-medium loss tolerant,
245 * elastic flow, constant packet interval, variable rate & size. E.g.
246 * FaceTime video.
247 *
248 * SO_TC_VO
249 * "Interactive Voice", low delay tolerant, low loss tolerant, inelastic
250 * flow, constant packet rate, somewhat fixed size. E.g. VoIP including
251 * FaceTime audio.
252 *
253 * SO_TC_CTL
254 * "Network Control", low delay tolerant, low loss tolerant, inelastic
255 * flow, rate is bursty but short, variable size. E.g. DNS queries;
256 * certain types of locally-originated ICMP, ICMPv6; IGMP/MLD join/leave,
257 * ARP.
258 */
0a7de745
A
259#define SO_TRAFFIC_CLASS 0x1086 /* Traffic service class (int) */
260#define SO_TC_BK_SYS 100 /* lowest class */
261#define SO_TC_BK 200
262#define SO_TC_BE 0
263#define SO_TC_RD 300
264#define SO_TC_OAM 400
265#define SO_TC_AV 500
266#define SO_TC_RV 600
267#define SO_TC_VI 700
268#define SO_TC_VO 800
269#define SO_TC_CTL 900 /* highest class */
270#define SO_TC_MAX 10 /* Total # of traffic classes */
316670eb 271#ifdef XNU_KERNEL_PRIVATE
0a7de745
A
272#define _SO_TC_BK 1 /* deprecated */
273#define _SO_TC_VI 2 /* deprecated */
274#define _SO_TC_VO 3 /* deprecated */
275#define _SO_TC_MAX 4 /* deprecated */
276
277#define SO_VALID_TC(c) \
278 (c == SO_TC_BK_SYS || c == SO_TC_BK || c == SO_TC_BE || \
279 c == SO_TC_RD || c == SO_TC_OAM || c == SO_TC_AV || \
280 c == SO_TC_RV || c == SO_TC_VI || c == SO_TC_VO || \
d9a64523 281 c == SO_TC_CTL || c == SO_TC_NETSVC_SIG)
39037602 282
0a7de745 283#define SO_TC_UNSPEC ((int)-1) /* Traffic class not specified */
39037602 284
0a7de745 285#define SO_TC_SIG SO_TC_VI /* to be removed XXX */
39037602 286
0a7de745
A
287#define SOTCIX_BK_SYS 0
288#define SOTCIX_BK 1
289#define SOTCIX_BE 2
290#define SOTCIX_RD 3
291#define SOTCIX_OAM 4
292#define SOTCIX_AV 5
293#define SOTCIX_RV 6
294#define SOTCIX_VI 7
295#define SOTCIX_VO 8
296#define SOTCIX_CTL 9
316670eb 297#endif /* XNU_KERNEL_PRIVATE */
6d2010ae 298
39037602 299/* Background socket configuration flags */
0a7de745
A
300#define TRAFFIC_MGT_SO_BACKGROUND 0x0001 /* background socket */
301#define TRAFFIC_MGT_TCP_RECVBG 0x0002 /* Only TCP sockets, receiver throttling */
6d2010ae 302
0a7de745
A
303#define SO_RECV_TRAFFIC_CLASS 0x1087 /* Receive traffic class (bool) */
304#define SO_TRAFFIC_CLASS_DBG 0x1088 /* Debug traffic class (struct so_tcdbg) */
f427ee49 305#define SO_OPTION_UNUSED_0 0x1089 /* Traffic class statistics */
0a7de745
A
306#define SO_PRIVILEGED_TRAFFIC_CLASS 0x1090 /* Privileged traffic class (bool) */
307#define SO_DEFUNCTIT 0x1091 /* Defunct a socket (only in internal builds) */
308#define SO_DEFUNCTOK 0x1100 /* can be defunct'd */
309#define SO_ISDEFUNCT 0x1101 /* get defunct status */
316670eb 310
0a7de745 311#define SO_OPPORTUNISTIC 0x1102 /* deprecated; use SO_TRAFFIC_CLASS */
316670eb
A
312
313/*
314 * SO_FLUSH flushes any unsent data generated by a given socket. It takes
315 * an integer parameter, which can be any of the SO_TC traffic class values,
316 * or the special SO_TC_ALL value.
317 */
0a7de745
A
318#define SO_FLUSH 0x1103 /* flush unsent data (int) */
319#define SO_TC_ALL (-1)
316670eb 320
0a7de745
A
321#define SO_RECV_ANYIF 0x1104 /* unrestricted inbound processing */
322#define SO_TRAFFIC_MGT_BACKGROUND 0x1105 /* Background traffic management */
39037602 323
0a7de745 324#define SO_FLOW_DIVERT_TOKEN 0x1106 /* flow divert token */
39236c6e 325
0a7de745
A
326#define SO_DELEGATED 0x1107 /* set socket as delegate (pid_t) */
327#define SO_DELEGATED_UUID 0x1108 /* set socket as delegate (uuid_t) */
328#define SO_NECP_ATTRIBUTES 0x1109 /* NECP socket attributes (domain, account, etc.) */
329#define SO_CFIL_SOCK_ID 0x1110 /* get content filter socket ID (cfil_sock_id_t) */
330#define SO_NECP_CLIENTUUID 0x1111 /* NECP Client uuid */
6d2010ae 331#endif /* PRIVATE */
0a7de745 332#define SO_NUMRCVPKT 0x1112 /* number of datagrams in receive socket buffer */
3e170ce0 333#ifdef PRIVATE
0a7de745
A
334#define SO_AWDL_UNRESTRICTED 0x1113 /* try to use AWDL in restricted mode */
335#define SO_EXTENDED_BK_IDLE 0x1114 /* extended time to keep socket idle after app is suspended (int) */
336#define SO_MARK_CELLFALLBACK 0x1115 /* Mark as initiated by cell fallback */
3e170ce0 337#endif /* PRIVATE */
cb323159 338#define SO_NET_SERVICE_TYPE 0x1116 /* Network service type */
fe8ab488 339
cb323159
A
340#ifdef PRIVATE
341#define SO_QOSMARKING_POLICY_OVERRIDE 0x1117 /* int */
342#define SO_INTCOPROC_ALLOW 0x1118 /* Try to use internal co-processor interfaces. */
343#endif /* PRIVATE */
344
f427ee49 345#define SO_NETSVC_MARKING_LEVEL 0x1119 /* Get QoS marking in effect for socket */
cb323159
A
346
347#ifdef PRIVATE
f427ee49
A
348#define SO_NECP_LISTENUUID 0x1120 /* NECP client UUID for listener */
349#define SO_MPKL_SEND_INFO 0x1122 /* (struct so_mpkl_send_info) */
350#define SO_STATISTICS_EVENT 0x1123 /* int64 argument, an event in statistics collection */
351#define SO_WANT_KEV_SOCKET_CLOSED 0x1124 /* want delivery of KEV_SOCKET_CLOSED (int) */
cb323159 352#endif /* PRIVATE */
39037602
A
353/*
354 * Network Service Type for option SO_NET_SERVICE_TYPE
355 *
356 * The vast majority of sockets should use Best Effort that is the default
357 * Network Service Type. Other Network Service Types have to be used only if
358 * the traffic actually matches the description of the Network Service Type.
359 *
360 * Network Service Types do not represent priorities but rather describe
361 * different categories of delay, jitter and loss parameters.
362 * Those parameters may influence protocols from layer 4 protocols like TCP
363 * to layer 2 protocols like Wi-Fi. The Network Service Type can determine
364 * how the traffic is queued and scheduled by the host networking stack and
365 * by other entities on the network like switches and routers. For example
366 * for Wi-Fi, the Network Service Type can select the marking of the
367 * layer 2 packet with the appropriate WMM Access Category.
368 *
369 * There is no point in attempting to game the system and use
370 * a Network Service Type that does not correspond to the actual
371 * traffic characteristic but one that seems to have a higher precedence.
372 * The reason is that for service classes that have lower tolerance
373 * for delay and jitter, the queues size is lower than for service
374 * classes that are more tolerant to delay and jitter.
375 *
376 * For example using a voice service type for bulk data transfer will lead
377 * to disastrous results as soon as congestion happens because the voice
378 * queue overflows and packets get dropped. This is not only bad for the bulk
379 * data transfer but it is also bad for VoIP apps that legitimately are using
380 * the voice service type.
381 *
382 * The characteristics of the Network Service Types are based on the service
383 * classes defined in RFC 4594 "Configuration Guidelines for DiffServ Service
384 * Classes"
385 *
386 * When system detects the outgoing interface belongs to a DiffServ domain
387 * that follows the recommendation of the IETF draft "Guidelines for DiffServ to
388 * IEEE 802.11 Mapping", the packet will marked at layer 3 with a DSCP value
389 * that corresponds to Network Service Type.
390 *
391 * NET_SERVICE_TYPE_BE
392 * "Best Effort", unclassified/standard. This is the default service
393 * class and cover the majority of the traffic.
394 *
395 * NET_SERVICE_TYPE_BK
396 * "Background", high delay tolerant, loss tolerant. elastic flow,
397 * variable size & long-lived. E.g: non-interactive network bulk transfer
398 * like synching or backup.
399 *
400 * NET_SERVICE_TYPE_RD
401 * "Responsive Data", a notch higher than "Best Effort", medium delay
402 * tolerant, elastic & inelastic flow, bursty, long-lived. E.g. email,
403 * instant messaging, for which there is a sense of interactivity and
404 * urgency (user waiting for output).
405 *
406 * NET_SERVICE_TYPE_OAM
407 * "Operations, Administration, and Management", medium delay tolerant,
408 * low-medium loss tolerant, elastic & inelastic flows, variable size.
409 * E.g. VPN tunnels.
410 *
411 * NET_SERVICE_TYPE_AV
412 * "Multimedia Audio/Video Streaming", medium delay tolerant, low-medium
413 * loss tolerant, elastic flow, constant packet interval, variable rate
414 * and size. E.g. video and audio playback with buffering.
415 *
416 * NET_SERVICE_TYPE_RV
417 * "Responsive Multimedia Audio/Video", low delay tolerant, low-medium
418 * loss tolerant, elastic flow, variable packet interval, rate and size.
419 * E.g. screen sharing.
420 *
421 * NET_SERVICE_TYPE_VI
422 * "Interactive Video", low delay tolerant, low-medium loss tolerant,
423 * elastic flow, constant packet interval, variable rate & size. E.g.
424 * video telephony.
425 *
426 * NET_SERVICE_TYPE_SIG
427 * "Signaling", low delay tolerant, low loss tolerant, inelastic flow,
428 * jitter tolerant, rate is bursty but short, variable size. E.g. SIP.
429 *
430 * NET_SERVICE_TYPE_VO
431 * "Interactive Voice", very low delay tolerant, very low loss tolerant,
432 * inelastic flow, constant packet rate, somewhat fixed size.
433 * E.g. VoIP.
434 */
0a7de745
A
435
436#define NET_SERVICE_TYPE_BE 0 /* Best effort */
437#define NET_SERVICE_TYPE_BK 1 /* Background system initiated */
438#define NET_SERVICE_TYPE_SIG 2 /* Signaling */
439#define NET_SERVICE_TYPE_VI 3 /* Interactive Video */
440#define NET_SERVICE_TYPE_VO 4 /* Interactive Voice */
441#define NET_SERVICE_TYPE_RV 5 /* Responsive Multimedia Audio/Video */
442#define NET_SERVICE_TYPE_AV 6 /* Multimedia Audio/Video Streaming */
443#define NET_SERVICE_TYPE_OAM 7 /* Operations, Administration, and Management */
444#define NET_SERVICE_TYPE_RD 8 /* Responsive Data */
39037602
A
445
446#if PRIVATE
0a7de745
A
447#define _NET_SERVICE_TYPE_COUNT 9
448#define _NET_SERVICE_TYPE_UNSPEC ((int)-1)
39037602 449
0a7de745 450#define IS_VALID_NET_SERVICE_TYPE(c) \
39037602
A
451 (c >= NET_SERVICE_TYPE_BE && c <= NET_SERVICE_TYPE_RD)
452
453extern const int sotc_by_netservicetype[_NET_SERVICE_TYPE_COUNT];
454
455/*
456 * Facility to pass Network Service Type values using SO_TRAFFIC_CLASS
457 * Mostly useful to simplify implementation of frameworks to adopt the new
458 * Network Service Type values for Signaling.
459 */
0a7de745
A
460#define SO_TC_NET_SERVICE_OFFSET 10000
461#define SO_TC_NETSVC_SIG (SO_TC_NET_SERVICE_OFFSET + NET_SERVICE_TYPE_SIG)
39037602
A
462#endif /* PRIVATE */
463
cb323159 464/* These are supported values for SO_NETSVC_MARKING_LEVEL */
0a7de745
A
465#define NETSVC_MRKNG_UNKNOWN 0 /* The outgoing network interface is not known */
466#define NETSVC_MRKNG_LVL_L2 1 /* Default marking at layer 2 (for example Wi-Fi WMM) */
467#define NETSVC_MRKNG_LVL_L3L2_ALL 2 /* Layer 3 DSCP marking and layer 2 marking for all Network Service Types */
468#define NETSVC_MRKNG_LVL_L3L2_BK 3 /* The system policy limits layer 3 DSCP marking and layer 2 marking
469 * to background Network Service Types */
39037602 470
cb323159 471
3e170ce0 472typedef __uint32_t sae_associd_t;
0a7de745
A
473#define SAE_ASSOCID_ANY 0
474#define SAE_ASSOCID_ALL ((sae_associd_t)(-1ULL))
3e170ce0
A
475
476typedef __uint32_t sae_connid_t;
0a7de745
A
477#define SAE_CONNID_ANY 0
478#define SAE_CONNID_ALL ((sae_connid_t)(-1ULL))
3e170ce0
A
479
480/* connectx() flag parameters */
0a7de745
A
481#define CONNECT_RESUME_ON_READ_WRITE 0x1 /* resume connect() on read/write */
482#define CONNECT_DATA_IDEMPOTENT 0x2 /* data is idempotent */
483#define CONNECT_DATA_AUTHENTICATED 0x4 /* data includes security that replaces the TFO-cookie */
3e170ce0
A
484
485/* sockaddr endpoints */
486typedef struct sa_endpoints {
0a7de745
A
487 unsigned int sae_srcif; /* optional source interface */
488 const struct sockaddr *sae_srcaddr; /* optional source address */
489 socklen_t sae_srcaddrlen; /* size of source address */
490 const struct sockaddr *sae_dstaddr; /* destination address */
491 socklen_t sae_dstaddrlen; /* size of destination address */
3e170ce0 492} sa_endpoints_t;
0a7de745 493#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
91447636 494
1c79356b
A
495/*
496 * Structure used for manipulating linger option.
497 */
0a7de745
A
498struct linger {
499 int l_onoff; /* option on/off */
500 int l_linger; /* linger time */
1c79356b
A
501};
502
9bccf70c 503#ifndef __APPLE__
0a7de745
A
504struct accept_filter_arg {
505 char af_name[16];
506 char af_arg[256 - 16];
9bccf70c
A
507};
508#endif
509
b0d623f7
A
510#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
511#ifdef __APPLE__
512
513/*
39037602 514 * Structure to control non-portable Sockets extension to POSIX
b0d623f7
A
515 */
516struct so_np_extensions {
0a7de745
A
517 u_int32_t npx_flags;
518 u_int32_t npx_mask;
b0d623f7
A
519};
520
0a7de745 521#define SONPX_SETOPTSHUT 0x000000001 /* flag for allowing setsockopt after shutdown */
b0d623f7
A
522
523
524#ifdef KERNEL_PRIVATE
0a7de745
A
525#define SONPX_MASK_VALID (SONPX_SETOPTSHUT)
526#define IS_SO_TC_BACKGROUND(_tc_) ((_tc_) == SO_TC_BK || (_tc_) == SO_TC_BK_SYS)
527#define IS_SO_TC_BACKGROUNDSYSTEM(_tc_) ((_tc_) == SO_TC_BK_SYS)
316670eb 528#endif /* KERNEL_PRIVATE */
b0d623f7
A
529
530#endif
531#endif
532
1c79356b
A
533/*
534 * Level number for (get/set)sockopt() to apply to socket itself.
535 */
0a7de745 536#define SOL_SOCKET 0xffff /* options for socket level */
1c79356b 537
2d21ac55 538
1c79356b
A
539/*
540 * Address families.
541 */
0a7de745
A
542#define AF_UNSPEC 0 /* unspecified */
543#define AF_UNIX 1 /* local to host (pipes) */
2d21ac55 544#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
545#define AF_LOCAL AF_UNIX /* backward compatibility */
546#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
547#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
2d21ac55 548#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
549#define AF_IMPLINK 3 /* arpanet imp addresses */
550#define AF_PUP 4 /* pup protocols: e.g. BSP */
551#define AF_CHAOS 5 /* mit CHAOS protocols */
552#define AF_NS 6 /* XEROX NS protocols */
553#define AF_ISO 7 /* ISO protocols */
554#define AF_OSI AF_ISO
555#define AF_ECMA 8 /* European computer manufacturers */
556#define AF_DATAKIT 9 /* datakit protocols */
557#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
558#define AF_SNA 11 /* IBM SNA */
559#define AF_DECnet 12 /* DECnet */
560#define AF_DLI 13 /* DEC Direct data link interface */
561#define AF_LAT 14 /* LAT */
562#define AF_HYLINK 15 /* NSC Hyperchannel */
563#define AF_APPLETALK 16 /* Apple Talk */
564#define AF_ROUTE 17 /* Internal Routing Protocol */
565#define AF_LINK 18 /* Link layer interface */
566#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
567#define AF_COIP 20 /* connection-oriented IP, aka ST II */
568#define AF_CNT 21 /* Computer Network Technology */
569#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
570#define AF_IPX 23 /* Novell Internet Protocol */
571#define AF_SIP 24 /* Simple Internet Protocol */
572#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
573#define AF_NDRV 27 /* Network Driver 'raw' access */
574#define AF_ISDN 28 /* Integrated Services Digital Network */
575#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
576#define pseudo_AF_KEY 29 /* Internal key-management function */
577#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
578#define AF_INET6 30 /* IPv6 */
2d21ac55 579#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
580#define AF_NATM 31 /* native ATM access */
581#define AF_SYSTEM 32 /* Kernel event messages */
582#define AF_NETBIOS 33 /* NetBIOS */
583#define AF_PPP 34 /* PPP communication protocol */
584#define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers
585 * in interface output routine */
91447636 586#ifdef PRIVATE
0a7de745 587#define AF_AFP 36 /* Used by AFP */
91447636 588#else
0a7de745 589#define AF_RESERVED_36 36 /* Reserved for internal usage */
91447636 590#endif
0a7de745
A
591#define AF_IEEE80211 37 /* IEEE 802.11 protocol */
592#define AF_UTUN 38
39236c6e 593#ifdef PRIVATE
0a7de745 594#define AF_MULTIPATH 39
39236c6e 595#endif /* PRIVATE */
f427ee49
A
596#define AF_VSOCK 40 /* VM Sockets */
597#define AF_MAX 41
0a7de745 598#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b
A
599
600/*
91447636 601 * [XSI] Structure used by kernel to store most addresses.
1c79356b
A
602 */
603struct sockaddr {
0a7de745
A
604 __uint8_t sa_len; /* total length */
605 sa_family_t sa_family; /* [XSI] address family */
606 char sa_data[14]; /* [XSI] addr value (actually larger) */
1c79356b 607};
91447636 608
2d21ac55 609#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745 610#define SOCK_MAXADDRLEN 255 /* longest possible addresses */
1c79356b
A
611
612/*
613 * Structure used by kernel to pass protocol
614 * information in raw sockets.
615 */
616struct sockproto {
0a7de745
A
617 __uint16_t sp_family; /* address family */
618 __uint16_t sp_protocol; /* protocol */
1c79356b 619};
0a7de745 620#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b 621
1c79356b 622/*
9bccf70c 623 * RFC 2553: protocol-independent placeholder for socket addresses
1c79356b 624 */
0a7de745
A
625#define _SS_MAXSIZE 128
626#define _SS_ALIGNSIZE (sizeof(__int64_t))
627#define _SS_PAD1SIZE \
628 (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
629#define _SS_PAD2SIZE \
630 (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
631 _SS_PAD1SIZE - _SS_ALIGNSIZE)
1c79356b 632
91447636
A
633/*
634 * [XSI] sockaddr_storage
635 */
1c79356b 636struct sockaddr_storage {
0a7de745
A
637 __uint8_t ss_len; /* address length */
638 sa_family_t ss_family; /* [XSI] address family */
639 char __ss_pad1[_SS_PAD1SIZE];
640 __int64_t __ss_align; /* force structure storage alignment */
641 char __ss_pad2[_SS_PAD2SIZE];
1c79356b 642};
1c79356b
A
643
644/*
645 * Protocol families, same as address families for now.
646 */
0a7de745
A
647#define PF_UNSPEC AF_UNSPEC
648#define PF_LOCAL AF_LOCAL
649#define PF_UNIX PF_LOCAL /* backward compatibility */
650#define PF_INET AF_INET
651#define PF_IMPLINK AF_IMPLINK
652#define PF_PUP AF_PUP
653#define PF_CHAOS AF_CHAOS
654#define PF_NS AF_NS
655#define PF_ISO AF_ISO
656#define PF_OSI AF_ISO
657#define PF_ECMA AF_ECMA
658#define PF_DATAKIT AF_DATAKIT
659#define PF_CCITT AF_CCITT
660#define PF_SNA AF_SNA
661#define PF_DECnet AF_DECnet
662#define PF_DLI AF_DLI
663#define PF_LAT AF_LAT
664#define PF_HYLINK AF_HYLINK
665#define PF_APPLETALK AF_APPLETALK
666#define PF_ROUTE AF_ROUTE
667#define PF_LINK AF_LINK
668#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
669#define PF_COIP AF_COIP
670#define PF_CNT AF_CNT
671#define PF_SIP AF_SIP
672#define PF_IPX AF_IPX /* same format as AF_NS */
673#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
674#define PF_PIP pseudo_AF_PIP
675#define PF_NDRV AF_NDRV
676#define PF_ISDN AF_ISDN
677#define PF_KEY pseudo_AF_KEY
678#define PF_INET6 AF_INET6
679#define PF_NATM AF_NATM
680#define PF_SYSTEM AF_SYSTEM
681#define PF_NETBIOS AF_NETBIOS
682#define PF_PPP AF_PPP
91447636 683#ifdef PRIVATE
0a7de745 684#define PF_AFP AF_AFP
91447636 685#else
0a7de745 686#define PF_RESERVED_36 AF_RESERVED_36
91447636 687#endif
0a7de745 688#define PF_UTUN AF_UTUN
39236c6e 689#ifdef PRIVATE
0a7de745 690#define PF_MULTIPATH AF_MULTIPATH
39236c6e 691#endif /* PRIVATE */
f427ee49 692#define PF_VSOCK AF_VSOCK
0a7de745 693#define PF_MAX AF_MAX
1c79356b 694
91447636
A
695/*
696 * These do not have socket-layer support:
697 */
0a7de745
A
698#define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */
699#define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */
6d2010ae 700#ifdef KERNEL_PRIVATE
0a7de745 701#define PF_BRIDGE ((uint32_t)0x62726467) /* 'brdg' */
cb323159 702#define PF_802154 ((uint32_t)0x38313534) /* '8154' */
6d2010ae 703#endif /* KERNEL_PRIVATE */
91447636 704
1c79356b
A
705/*
706 * Definitions for network related sysctl, CTL_NET.
707 *
708 * Second level is protocol family.
709 * Third level is protocol number.
710 *
711 * Further levels are defined by the individual families below.
712 */
2d21ac55 713#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745 714#define NET_MAXID AF_MAX
2d21ac55 715#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
91447636
A
716
717#ifdef KERNEL_PRIVATE
0a7de745 718#define CTL_NET_NAMES { \
1c79356b
A
719 { 0, 0 }, \
720 { "local", CTLTYPE_NODE }, \
721 { "inet", CTLTYPE_NODE }, \
722 { "implink", CTLTYPE_NODE }, \
723 { "pup", CTLTYPE_NODE }, \
724 { "chaos", CTLTYPE_NODE }, \
725 { "xerox_ns", CTLTYPE_NODE }, \
726 { "iso", CTLTYPE_NODE }, \
727 { "emca", CTLTYPE_NODE }, \
728 { "datakit", CTLTYPE_NODE }, \
729 { "ccitt", CTLTYPE_NODE }, \
730 { "ibm_sna", CTLTYPE_NODE }, \
731 { "decnet", CTLTYPE_NODE }, \
732 { "dec_dli", CTLTYPE_NODE }, \
733 { "lat", CTLTYPE_NODE }, \
734 { "hylink", CTLTYPE_NODE }, \
735 { "appletalk", CTLTYPE_NODE }, \
736 { "route", CTLTYPE_NODE }, \
737 { "link_layer", CTLTYPE_NODE }, \
738 { "xtp", CTLTYPE_NODE }, \
739 { "coip", CTLTYPE_NODE }, \
740 { "cnt", CTLTYPE_NODE }, \
741 { "rtip", CTLTYPE_NODE }, \
742 { "ipx", CTLTYPE_NODE }, \
743 { "sip", CTLTYPE_NODE }, \
744 { "pip", CTLTYPE_NODE }, \
9bccf70c
A
745 { 0, 0 }, \
746 { "ndrv", CTLTYPE_NODE }, \
1c79356b
A
747 { "isdn", CTLTYPE_NODE }, \
748 { "key", CTLTYPE_NODE }, \
749 { "inet6", CTLTYPE_NODE }, \
750 { "natm", CTLTYPE_NODE }, \
9bccf70c
A
751 { "sys", CTLTYPE_NODE }, \
752 { "netbios", CTLTYPE_NODE }, \
753 { "ppp", CTLTYPE_NODE }, \
754 { "hdrcomplete", CTLTYPE_NODE }, \
f427ee49 755 { "vsock", CTLTYPE_NODE }, \
1c79356b 756}
2d21ac55 757#endif /* KERNEL_PRIVATE */
1c79356b 758
2d21ac55 759#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1c79356b
A
760/*
761 * PF_ROUTE - Routing table
762 *
763 * Three additional levels are defined:
764 * Fourth: address family, 0 is wildcard
765 * Fifth: type of info, defined below
766 * Sixth: flag(s) to mask with for NET_RT_FLAGS
767 */
0a7de745
A
768#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
769#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
770#define NET_RT_IFLIST 3 /* survey interface list */
771#define NET_RT_STAT 4 /* routing statistics */
772#define NET_RT_TRASH 5 /* routes not in table but not freed */
773#define NET_RT_IFLIST2 6 /* interface list with addresses */
774#define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
6d2010ae 775#ifdef PRIVATE
0a7de745
A
776#define NET_RT_DUMPX 8 /* private */
777#define NET_RT_DUMPX_FLAGS 9 /* private */
6d2010ae 778#endif /* PRIVATE */
d9a64523
A
779/*
780 * Allows read access non-local host's MAC address
781 * if the process has neighbor cache entitlement.
782 */
0a7de745
A
783#define NET_RT_FLAGS_PRIV 10
784#define NET_RT_MAXID 11
2d21ac55 785#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
91447636 786
cb323159
A
787#ifdef PRIVATE
788/* These are supported values for SO_STATISTICS_EVENT */
789#define SO_STATISTICS_EVENT_ENTER_CELLFALLBACK (1 << 0)
790#define SO_STATISTICS_EVENT_EXIT_CELLFALLBACK (1 << 1)
791#define SO_STATISTICS_EVENT_RESERVED_1 (1 << 2)
792#define SO_STATISTICS_EVENT_RESERVED_2 (1 << 3)
793#endif /* PRIVATE */
794
795
91447636 796#ifdef KERNEL_PRIVATE
0a7de745 797#define CTL_NET_RT_NAMES { \
1c79356b
A
798 { 0, 0 }, \
799 { "dump", CTLTYPE_STRUCT }, \
800 { "flags", CTLTYPE_STRUCT }, \
801 { "iflist", CTLTYPE_STRUCT }, \
91447636
A
802 { "stat", CTLTYPE_STRUCT }, \
803 { "trash", CTLTYPE_INT }, \
804 { "iflist2", CTLTYPE_STRUCT }, \
39037602
A
805 { "dump2", CTLTYPE_STRUCT }, \
806 { "dumpx", CTLTYPE_STRUCT }, \
807 { "dumpx_flags", CTLTYPE_STRUCT }, \
1c79356b
A
808}
809
2d21ac55 810#endif /* KERNEL_PRIVATE */
91447636 811
1c79356b
A
812/*
813 * Maximum queue length specifiable by listen.
814 */
0a7de745 815#define SOMAXCONN 128
1c79356b
A
816
817/*
91447636 818 * [XSI] Message header for recvmsg and sendmsg calls.
1c79356b
A
819 * Used value-result for recvmsg, value only for sendmsg.
820 */
821struct msghdr {
0a7de745
A
822 void *msg_name; /* [XSI] optional address */
823 socklen_t msg_namelen; /* [XSI] size of address */
824 struct iovec *msg_iov; /* [XSI] scatter/gather array */
825 int msg_iovlen; /* [XSI] # elements in msg_iov */
826 void *msg_control; /* [XSI] ancillary data, see below */
827 socklen_t msg_controllen; /* [XSI] ancillary data buffer len */
828 int msg_flags; /* [XSI] flags on received message */
91447636
A
829};
830
fe8ab488
A
831#ifdef PRIVATE
832/*
833 * Extended version for sendmsg_x() and recvmsg_x() calls
834 *
835 * For recvmsg_x(), the size of the data received is given by the field
836 * msg_datalen.
837 *
39037602 838 * For sendmsg_x(), the size of the data to send is given by the length of
fe8ab488
A
839 * the iovec array -- like sendmsg(). The field msg_datalen is ignored.
840 */
841struct msghdr_x {
0a7de745
A
842 void *msg_name; /* optional address */
843 socklen_t msg_namelen; /* size of address */
844 struct iovec *msg_iov; /* scatter/gather array */
845 int msg_iovlen; /* # elements in msg_iov */
846 void *msg_control; /* ancillary data, see below */
847 socklen_t msg_controllen; /* ancillary data buffer len */
848 int msg_flags; /* flags on received message */
849 size_t msg_datalen; /* byte length of buffer in msg_iov */
fe8ab488
A
850};
851#endif /* PRIVATE */
852
853#ifdef XNU_KERNEL_PRIVATE
b0d623f7
A
854/*
855 * In-kernel representation of "struct msghdr" from
856 * userspace. Has enough precision for 32-bit or
857 * 64-bit clients, but does not need to be packed.
91447636 858 */
91447636
A
859
860struct user_msghdr {
0a7de745
A
861 user_addr_t msg_name; /* optional address */
862 socklen_t msg_namelen; /* size of address */
863 user_addr_t msg_iov; /* scatter/gather array */
864 int msg_iovlen; /* # elements in msg_iov */
865 user_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 */
b0d623f7
A
868};
869
870/*
871 * LP64 user version of struct msghdr.
872 * WARNING - keep in sync with struct msghdr
873 */
874
875struct user64_msghdr {
0a7de745
A
876 user64_addr_t msg_name; /* optional address */
877 socklen_t msg_namelen; /* size of address */
878 user64_addr_t msg_iov; /* scatter/gather array */
879 int msg_iovlen; /* # elements in msg_iov */
880 user64_addr_t msg_control; /* ancillary data, see below */
881 socklen_t msg_controllen; /* ancillary data buffer len */
882 int msg_flags; /* flags on received message */
1c79356b
A
883};
884
b0d623f7
A
885/*
886 * ILP32 user version of struct msghdr.
887 * WARNING - keep in sync with struct msghdr
888 */
889
890struct user32_msghdr {
0a7de745
A
891 user32_addr_t msg_name; /* optional address */
892 socklen_t msg_namelen; /* size of address */
893 user32_addr_t msg_iov; /* scatter/gather array */
894 int msg_iovlen; /* # elements in msg_iov */
895 user32_addr_t msg_control; /* ancillary data, see below */
896 socklen_t msg_controllen; /* ancillary data buffer len */
897 int msg_flags; /* flags on received message */
b0d623f7
A
898};
899
fe8ab488
A
900/*
901 * In-kernel representation of "struct msghdr_x" from
902 * userspace. Has enough precision for 32-bit or
903 * 64-bit clients, but does not need to be packed.
904 */
905
906struct user_msghdr_x {
0a7de745
A
907 user_addr_t msg_name; /* optional address */
908 socklen_t msg_namelen; /* size of address */
909 user_addr_t msg_iov; /* scatter/gather array */
910 int msg_iovlen; /* # elements in msg_iov */
911 user_addr_t msg_control; /* ancillary data, see below */
912 socklen_t msg_controllen; /* ancillary data buffer len */
913 int msg_flags; /* flags on received message */
914 size_t msg_datalen; /* byte length of buffer in msg_iov */
fe8ab488
A
915};
916
917/*
918 * LP64 user version of struct msghdr_x
919 * WARNING - keep in sync with struct msghdr_x
920 */
921
922struct user64_msghdr_x {
0a7de745
A
923 user64_addr_t msg_name; /* optional address */
924 socklen_t msg_namelen; /* size of address */
925 user64_addr_t msg_iov; /* scatter/gather array */
926 int msg_iovlen; /* # elements in msg_iov */
927 user64_addr_t msg_control; /* ancillary data, see below */
928 socklen_t msg_controllen; /* ancillary data buffer len */
929 int msg_flags; /* flags on received message */
930 user64_size_t msg_datalen; /* byte length of buffer in msg_iov */
fe8ab488
A
931};
932
933/*
934 * ILP32 user version of struct msghdr_x
935 * WARNING - keep in sync with struct msghdr_x
936 */
937
938struct user32_msghdr_x {
0a7de745
A
939 user32_addr_t msg_name; /* optional address */
940 socklen_t msg_namelen; /* size of address */
941 user32_addr_t msg_iov; /* scatter/gather array */
942 int msg_iovlen; /* # elements in msg_iov */
943 user32_addr_t msg_control; /* ancillary data, see below */
944 socklen_t msg_controllen; /* ancillary data buffer len */
945 int msg_flags; /* flags on received message */
946 user32_size_t msg_datalen; /* byte length of buffer in msg_iov */
fe8ab488
A
947};
948
3e170ce0
A
949/*
950 * In-kernel representation of "struct sa_endpoints" from
951 * userspace. Has enough precision for 32-bit or
952 * 64-bit clients, but does not need to be packed.
953 */
954
955struct user_sa_endpoints {
0a7de745
A
956 unsigned int sae_srcif; /* optional source interface */
957 user_addr_t sae_srcaddr; /* optional source address */
958 socklen_t sae_srcaddrlen; /* size of source address */
959 user_addr_t sae_dstaddr; /* destination address */
960 socklen_t sae_dstaddrlen; /* size of destination address */
3e170ce0
A
961};
962
963/*
964 * LP64 user version of struct sa_endpoints
965 * WARNING - keep in sync with struct sa_endpoints
966 */
967
968struct user64_sa_endpoints {
0a7de745
A
969 unsigned int sae_srcif; /* optional source interface */
970 user64_addr_t sae_srcaddr; /* optional source address */
971 socklen_t sae_srcaddrlen; /* size of source address */
972 user64_addr_t sae_dstaddr; /* destination address */
973 socklen_t sae_dstaddrlen; /* size of destination address */
3e170ce0
A
974};
975
976/*
977 * ILP32 user version of struct sa_endpoints
978 * WARNING - keep in sync with struct sa_endpoints
979 */
980
981struct user32_sa_endpoints {
0a7de745
A
982 unsigned int sae_srcif; /* optional source interface */
983 user32_addr_t sae_srcaddr; /* optional source address */
984 socklen_t sae_srcaddrlen; /* size of source address */
985 user32_addr_t sae_dstaddr; /* destination address */
986 socklen_t sae_dstaddrlen; /* size of destination address */
3e170ce0
A
987};
988
fe8ab488 989#endif /* XNU_KERNEL_PRIVATE */
91447636 990
0a7de745
A
991#define MSG_OOB 0x1 /* process out-of-band data */
992#define MSG_PEEK 0x2 /* peek at incoming message */
993#define MSG_DONTROUTE 0x4 /* send without using routing tables */
994#define MSG_EOR 0x8 /* data completes record */
995#define MSG_TRUNC 0x10 /* data discarded before delivery */
996#define MSG_CTRUNC 0x20 /* control data lost before delivery */
997#define MSG_WAITALL 0x40 /* wait for full request or error */
2d21ac55 998#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
999#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
1000#define MSG_EOF 0x100 /* data completes connection */
9bccf70c 1001#ifdef __APPLE__
6d2010ae
A
1002#ifndef PRIVATE
1003#ifdef __APPLE_API_OBSOLETE
0a7de745 1004#define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
6d2010ae
A
1005#endif
1006#else
0a7de745 1007#define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
6d2010ae 1008#endif
cb323159
A
1009#define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp, deprecated */
1010#define MSG_HOLD 0x800 /* Hold frag in so_temp, deprecated */
1011#define MSG_SEND 0x1000 /* Send the packet in so_temp, deprecated */
0a7de745
A
1012#define MSG_HAVEMORE 0x2000 /* Data ready to be read */
1013#define MSG_RCVMORE 0x4000 /* Data remains in current pkt */
9bccf70c 1014#endif
2d21ac55 1015#ifdef KERNEL_PRIVATE
0a7de745 1016#define MSG_COMPAT 0x8000 /* deprecated */
2d21ac55 1017#endif /* KERNEL_PRIVATE */
0a7de745 1018#define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */
91447636 1019#ifdef KERNEL_PRIVATE
0a7de745
A
1020#define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */
1021#define MSG_SKIPCFIL 0x40000 /* skip pass content filter */
91447636 1022#endif
f427ee49
A
1023#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1024
1025#if __DARWIN_C_LEVEL >= 200809L
1026#define MSG_NOSIGNAL 0x80000 /* do not generate SIGPIPE on EOF */
1027#endif /* __DARWIN_C_LEVEL */
1028
1029#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745 1030#ifdef KERNEL
f427ee49 1031#define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */
91447636 1032#endif
0a7de745 1033#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b
A
1034
1035/*
1036 * Header for ancillary data objects in msg_control buffer.
1037 * Used for additional information with/about a datagram
1038 * not expressible by flags. The format is a sequence
1039 * of message elements headed by cmsghdr structures.
1040 */
1041struct cmsghdr {
0a7de745
A
1042 socklen_t cmsg_len; /* [XSI] data byte count, including hdr */
1043 int cmsg_level; /* [XSI] originating protocol */
1044 int cmsg_type; /* [XSI] protocol-specific type */
91447636 1045/* followed by unsigned char cmsg_data[]; */
1c79356b
A
1046};
1047
2d21ac55 1048#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
9bccf70c
A
1049#ifndef __APPLE__
1050/*
1051 * While we may have more groups than this, the cmsgcred struct must
1052 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
1053 * this.
39037602 1054 */
0a7de745 1055#define CMGROUP_MAX 16
1c79356b 1056
9bccf70c
A
1057/*
1058 * Credentials structure, used to verify the identity of a peer
1059 * process that has sent us a message. This is allocated by the
1060 * peer process but filled in by the kernel. This prevents the
1061 * peer from lying about its identity. (Note that cmcred_groups[0]
1062 * is the effective GID.)
1c79356b 1063 */
9bccf70c 1064struct cmsgcred {
0a7de745
A
1065 pid_t cmcred_pid; /* PID of sending process */
1066 uid_t cmcred_uid; /* real UID of sending process */
1067 uid_t cmcred_euid; /* effective UID of sending process */
1068 gid_t cmcred_gid; /* real GID of sending process */
1069 short cmcred_ngroups; /* number or groups */
1070 gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
9bccf70c
A
1071};
1072#endif
0a7de745 1073#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
9bccf70c
A
1074
1075/* given pointer to struct cmsghdr, return pointer to data */
0a7de745 1076#define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
39037602 1077 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
1c79356b 1078
b0d623f7
A
1079/*
1080 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
1081 * an empty list for some reasons.
1082 */
0a7de745 1083#define CMSG_FIRSTHDR(mhdr) \
39037602
A
1084 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
1085 (struct cmsghdr *)(mhdr)->msg_control : \
1086 (struct cmsghdr *)0L)
b0d623f7 1087
1c79356b 1088
39037602 1089/*
b0d623f7
A
1090 * Given pointer to struct cmsghdr, return pointer to next cmsghdr
1091 * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
1092 */
0a7de745
A
1093#define CMSG_NXTHDR(mhdr, cmsg) \
1094 ((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) : \
1095 ((((unsigned char *)(cmsg) + \
1096 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \
1097 __DARWIN_ALIGN32(sizeof(struct cmsghdr))) > \
1098 ((unsigned char *)(mhdr)->msg_control + \
1099 (mhdr)->msg_controllen)) ? \
1100 (struct cmsghdr *)0L /* NULL */ : \
1101 (struct cmsghdr *)(void *)((unsigned char *)(cmsg) + \
1102 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
1c79356b 1103
2d21ac55 1104#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
9bccf70c 1105/* RFC 2292 additions */
0a7de745
A
1106#define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
1107#define CMSG_LEN(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
9bccf70c
A
1108
1109#ifdef KERNEL
f427ee49 1110#define CMSG_ALIGN(n) ((typeof(n))__DARWIN_ALIGN32(n))
9bccf70c 1111#endif
0a7de745 1112#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b
A
1113
1114/* "Socket"-level control message types: */
0a7de745 1115#define SCM_RIGHTS 0x01 /* access rights (array of int) */
2d21ac55 1116#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745
A
1117#define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
1118#define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
1119#define SCM_TIMESTAMP_MONOTONIC 0x04 /* timestamp (uint64_t) */
1c79356b 1120
39236c6e 1121#ifdef PRIVATE
cb323159
A
1122#define SCM_TIMESTAMP_CONTINUOUS 0x07 /* timestamp (uint64_t) */
1123#define SCM_MPKL_SEND_INFO 0x08 /* send info for multi-layer packet logging (struct so_mpkl_send_info) */
1124#define SCM_MPKL_RECV_INFO 0x09 /* receive info for multi-layer packet logging (struct so_mpkl_recv_info */
39236c6e
A
1125#endif /* PRIVATE */
1126
2d21ac55 1127#ifdef KERNEL_PRIVATE
1c79356b 1128/*
2d21ac55 1129 * 4.3 compat sockaddr (deprecated)
1c79356b
A
1130 */
1131struct osockaddr {
0a7de745
A
1132 __uint16_t sa_family; /* address family */
1133 char sa_data[14]; /* up to 14 bytes of direct address */
1c79356b
A
1134};
1135
1136/*
2d21ac55 1137 * 4.3-compat message header (deprecated)
1c79356b
A
1138 */
1139struct omsghdr {
0a7de745
A
1140 void *msg_name; /* optional address */
1141 socklen_t msg_namelen; /* size of address */
1142 struct iovec *msg_iov; /* scatter/gather array */
1143 int msg_iovlen; /* # elements in msg_iov */
1144 void *msg_accrights; /* access rights sent/rcvd */
1145 int msg_accrightslen;
1c79356b 1146};
316670eb 1147
0a7de745 1148#define SA(s) ((struct sockaddr *)(void *)(s))
2d21ac55 1149#endif /* KERNEL_PRIVATE */
0a7de745 1150#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b
A
1151
1152/*
1153 * howto arguments for shutdown(2), specified by Posix.1g.
1154 */
0a7de745
A
1155#define SHUT_RD 0 /* shut down the reading side */
1156#define SHUT_WR 1 /* shut down the writing side */
1157#define SHUT_RDWR 2 /* shut down both sides */
1c79356b 1158
f427ee49 1159#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
1c79356b
A
1160/*
1161 * sendfile(2) header/trailer struct
1162 */
1163struct sf_hdtr {
0a7de745
A
1164 struct iovec *headers; /* pointer to an array of header struct iovec's */
1165 int hdr_cnt; /* number of header iovec's */
1166 struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
1167 int trl_cnt; /* number of trailer iovec's */
1c79356b 1168};
2d21ac55
A
1169
1170#ifdef KERNEL
1171
b0d623f7 1172/* In-kernel representation */
2d21ac55 1173struct user_sf_hdtr {
0a7de745
A
1174 user_addr_t headers; /* pointer to an array of header struct iovec's */
1175 int hdr_cnt; /* number of header iovec's */
1176 user_addr_t trailers; /* pointer to an array of trailer struct iovec's */
1177 int trl_cnt; /* number of trailer iovec's */
2d21ac55
A
1178};
1179
b0d623f7
A
1180/* LP64 user version of struct sf_hdtr */
1181struct user64_sf_hdtr {
0a7de745
A
1182 user64_addr_t headers; /* pointer to an array of header struct iovec's */
1183 int hdr_cnt; /* number of header iovec's */
1184 user64_addr_t trailers; /* pointer to an array of trailer struct iovec's */
1185 int trl_cnt; /* number of trailer iovec's */
b0d623f7
A
1186};
1187
1188/* ILP32 user version of struct sf_hdtr */
1189struct user32_sf_hdtr {
0a7de745
A
1190 user32_addr_t headers; /* pointer to an array of header struct iovec's */
1191 int hdr_cnt; /* number of header iovec's */
1192 user32_addr_t trailers; /* pointer to an array of trailer struct iovec's */
1193 int trl_cnt; /* number of trailer iovec's */
b0d623f7 1194};
2d21ac55
A
1195
1196#endif /* KERNEL */
1197
f427ee49 1198#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b 1199
39236c6e
A
1200#ifdef PRIVATE
1201#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
39236c6e
A
1202
1203/*
1204 * Structure for SIOCGASSOCIDS
1205 */
1206struct so_aidreq {
0a7de745
A
1207 __uint32_t sar_cnt; /* number of associations */
1208 sae_associd_t *sar_aidp; /* array of association IDs */
39236c6e
A
1209};
1210
1211#ifdef BSD_KERNEL_PRIVATE
1212struct so_aidreq32 {
0a7de745
A
1213 __uint32_t sar_cnt;
1214 user32_addr_t sar_aidp;
39236c6e
A
1215};
1216
1217struct so_aidreq64 {
0a7de745
A
1218 __uint32_t sar_cnt;
1219 user64_addr_t sar_aidp __attribute__((aligned(8)));
39236c6e
A
1220};
1221#endif /* BSD_KERNEL_PRIVATE */
1222
1223/*
1224 * Structure for SIOCGCONNIDS
1225 */
1226struct so_cidreq {
0a7de745
A
1227 sae_associd_t scr_aid; /* association ID */
1228 __uint32_t scr_cnt; /* number of connections */
1229 sae_connid_t *scr_cidp; /* array of connection IDs */
39236c6e
A
1230};
1231
1232#ifdef BSD_KERNEL_PRIVATE
1233struct so_cidreq32 {
0a7de745
A
1234 sae_associd_t scr_aid;
1235 __uint32_t scr_cnt;
1236 user32_addr_t scr_cidp;
39236c6e
A
1237};
1238
1239struct so_cidreq64 {
0a7de745
A
1240 sae_associd_t scr_aid;
1241 __uint32_t scr_cnt;
1242 user64_addr_t scr_cidp __attribute__((aligned(8)));
39236c6e
A
1243};
1244#endif /* BSD_KERNEL_PRIVATE */
1245
1246/*
1247 * Structure for SIOCGCONNINFO
1248 */
1249struct so_cinforeq {
0a7de745
A
1250 sae_connid_t scir_cid; /* connection ID */
1251 __uint32_t scir_flags; /* see flags below */
1252 __uint32_t scir_ifindex; /* (last) outbound interface */
1253 __int32_t scir_error; /* most recent error */
1254 struct sockaddr *scir_src; /* source address */
1255 socklen_t scir_src_len; /* source address len */
1256 struct sockaddr *scir_dst; /* destination address */
1257 socklen_t scir_dst_len; /* destination address len */
1258 __uint32_t scir_aux_type; /* aux data type (CIAUX) */
1259 void *scir_aux_data; /* aux data */
1260 __uint32_t scir_aux_len; /* aux data len */
39236c6e
A
1261};
1262
1263#ifdef BSD_KERNEL_PRIVATE
1264struct so_cinforeq32 {
0a7de745
A
1265 sae_connid_t scir_cid;
1266 __uint32_t scir_flags;
1267 __uint32_t scir_ifindex;
1268 __int32_t scir_error;
1269 user32_addr_t scir_src;
1270 socklen_t scir_src_len;
1271 user32_addr_t scir_dst;
1272 socklen_t scir_dst_len;
1273 __uint32_t scir_aux_type;
1274 user32_addr_t scir_aux_data;
1275 __uint32_t scir_aux_len;
39236c6e
A
1276};
1277
1278struct so_cinforeq64 {
0a7de745
A
1279 sae_connid_t scir_cid;
1280 __uint32_t scir_flags;
1281 __uint32_t scir_ifindex;
1282 __int32_t scir_error;
1283 user64_addr_t scir_src __attribute__((aligned(8)));
1284 socklen_t scir_src_len;
1285 user64_addr_t scir_dst __attribute__((aligned(8)));
1286 socklen_t scir_dst_len;
1287 __uint32_t scir_aux_type;
1288 user64_addr_t scir_aux_data __attribute__((aligned(8)));
1289 __uint32_t scir_aux_len;
39236c6e
A
1290};
1291#endif /* BSD_KERNEL_PRIVATE */
1292
1293/* valid connection info flags */
0a7de745
A
1294#define CIF_CONNECTING 0x1 /* connection was attempted */
1295#define CIF_CONNECTED 0x2 /* connection is established */
1296#define CIF_DISCONNECTING 0x4 /* disconnection was attempted */
1297#define CIF_DISCONNECTED 0x8 /* has been disconnected */
1298#define CIF_BOUND_IF 0x10 /* bound to an interface */
1299#define CIF_BOUND_IP 0x20 /* bound to a src address */
1300#define CIF_BOUND_PORT 0x40 /* bound to a src port */
1301#define CIF_PREFERRED 0x80 /* connection is primary/preferred */
1302#define CIF_MP_CAPABLE 0x100 /* supports multipath protocol */
1303#define CIF_MP_READY 0x200 /* multipath protocol confirmed */
1304#define CIF_MP_DEGRADED 0x400 /* has lost its multipath capability */
1305#define CIF_MP_ACTIVE 0x800 /* this is the active subflow */
39236c6e
A
1306
1307/* valid connection info auxiliary data types */
0a7de745 1308#define CIAUX_TCP 0x1 /* TCP auxiliary data (conninfo_tcp_t) */
f427ee49 1309#define CIAUX_MPTCP 0x2 /* MPTCP auxiliary data (conninfo_multipathtcp) */
39236c6e
A
1310
1311/*
1312 * Structure for SIOC{S,G}CONNORDER
1313 */
1314struct so_cordreq {
0a7de745
A
1315 sae_connid_t sco_cid; /* connection ID */
1316 __uint32_t sco_rank; /* rank (0 means unspecified) */
39236c6e
A
1317};
1318
39236c6e
A
1319/*
1320 * Common structure for KEV_NETPOLICY_SUBCLASS
1321 */
1322struct netpolicy_event_data {
0a7de745 1323 __uint64_t eupid; /* effective unique PID */
cb323159 1324 __uint64_t epid; /* effective PID */
0a7de745 1325 uuid_t euuid; /* effective UUID */
39236c6e
A
1326};
1327
1328/*
1329 * NETPOLICY_IFDENIED event structure
1330 */
1331struct kev_netpolicy_ifdenied {
0a7de745 1332 struct netpolicy_event_data ev_data;
39037602 1333 __uint32_t ev_if_functional_type;
39236c6e
A
1334};
1335
f427ee49
A
1336/*
1337 * KEV_NETPOLICY_NETDENIED event structure
1338 */
1339struct kev_netpolicy_netdenied {
1340 struct netpolicy_event_data ev_data;
1341 __uint32_t ev_network_type;
1342};
1343
39037602
A
1344/*
1345 * Network Service Type to DiffServ Code Point mapping
1346 */
1347struct netsvctype_dscp_map {
0a7de745
A
1348 int netsvctype;
1349 u_int8_t dscp; /* 6 bits diffserv code point */
39037602
A
1350};
1351
cb323159
A
1352/*
1353 * Multi-layer packet logging require SO_MPK_LOG to be set
1354 */
1355struct so_mpkl_send_info {
1356 uuid_t mpkl_uuid;
1357 __uint8_t mpkl_proto; /* see net/multi_layer_pkt_log.h */
1358};
1359
1360struct so_mpkl_recv_info {
1361 __uint32_t mpkl_seq;
1362 __uint8_t mpkl_proto; /* see net/multi_layer_pkt_log.h */
1363};
1364
0a7de745 1365#ifndef KERNEL
39236c6e 1366__BEGIN_DECLS
3e170ce0
A
1367
1368extern int peeloff(int s, sae_associd_t);
39236c6e 1369extern int socket_delegate(int, int, int, pid_t);
fe8ab488
A
1370
1371/*
1372 * recvmsg_x() is a system call similar to recvmsg(2) to receive
1373 * several datagrams at once in the array of message headers "msgp".
1374 *
1375 * recvmsg_x() can be used only with protocols handlers that have been specially
3e170ce0 1376 * modified to support sending and receiving several datagrams at once.
39037602 1377 *
fe8ab488
A
1378 * The size of the array "msgp" is given by the argument "cnt".
1379 *
1380 * The "flags" arguments supports only the value MSG_DONTWAIT.
39037602 1381 *
fe8ab488
A
1382 * Each member of "msgp" array is of type "struct msghdr_x".
1383 *
1384 * The "msg_iov" and "msg_iovlen" are input parameters that describe where to
1385 * store a datagram in a scatter gather locations of buffers -- see recvmsg(2).
1386 * On output the field "msg_datalen" gives the length of the received datagram.
1387 *
1388 * The field "msg_flags" must be set to zero on input. On output, "msg_flags"
1389 * may have MSG_TRUNC set to indicate the trailing portion of the datagram was
1390 * discarded because the datagram was larger than the buffer supplied.
1391 * recvmsg_x() returns as soon as a datagram is truncated.
1392 *
1393 * recvmsg_x() may return with less than "cnt" datagrams received based on
1394 * the low water mark and the amount of data pending in the socket buffer.
1395 *
3e170ce0 1396 * recvmsg_x() returns the number of datagrams that have been received,
39037602 1397 * or -1 if an error occurred.
fe8ab488
A
1398 *
1399 * NOTE: This a private system call, the API is subject to change.
1400 */
1401ssize_t recvmsg_x(int s, const struct msghdr_x *msgp, u_int cnt, int flags);
1402
1403/*
1404 * sendmsg_x() is a system call similar to send(2) to send
1405 * several datagrams at once in the array of message headers "msgp".
1406 *
1407 * sendmsg_x() can be used only with protocols handlers that have been specially
3e170ce0 1408 * modified to support sending and receiving several datagrams at once.
39037602 1409 *
fe8ab488
A
1410 * The size of the array "msgp" is given by the argument "cnt".
1411 *
1412 * The "flags" arguments supports only the value MSG_DONTWAIT.
39037602 1413 *
fe8ab488
A
1414 * Each member of "msgp" array is of type "struct msghdr_x".
1415 *
1416 * The "msg_iov" and "msg_iovlen" are input parameters that specify the
1417 * data to be sent in a scatter gather locations of buffers -- see sendmsg(2).
1418 *
1419 * sendmsg_x() fails with EMSGSIZE if the sum of the length of the datagrams
1420 * is greater than the high water mark.
1421 *
1422 * Address and ancillary data are not supported so the following fields
1423 * must be set to zero on input:
1424 * "msg_name", "msg_namelen", "msg_control" and "msg_controllen".
1425 *
39037602 1426 * The field "msg_flags" and "msg_datalen" must be set to zero on input.
fe8ab488
A
1427 *
1428 * sendmsg_x() returns the number of datagrams that have been sent,
39037602 1429 * or -1 if an error occurred.
fe8ab488
A
1430 *
1431 * NOTE: This a private system call, the API is subject to change.
1432 */
1433ssize_t sendmsg_x(int s, const struct msghdr_x *msgp, u_int cnt, int flags);
39236c6e
A
1434__END_DECLS
1435#endif /* !KERNEL */
0a7de745 1436#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
39236c6e
A
1437#endif /* PRIVATE */
1438
0a7de745 1439#ifndef KERNEL
1c79356b 1440__BEGIN_DECLS
3e170ce0 1441
0a7de745
A
1442int accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
1443__DARWIN_ALIAS_C(accept);
1444int bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
1445int connect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(connect);
1446int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
1447__DARWIN_ALIAS(getpeername);
1448int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
1449__DARWIN_ALIAS(getsockname);
1450int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
1451int listen(int, int) __DARWIN_ALIAS(listen);
1452ssize_t recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv);
1453ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict,
1454 socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
1455ssize_t recvmsg(int, struct msghdr *, int) __DARWIN_ALIAS_C(recvmsg);
1456ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);
1457ssize_t sendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS_C(sendmsg);
1458ssize_t sendto(int, const void *, size_t,
1459 int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(sendto);
1460int setsockopt(int, int, int, const void *, socklen_t);
1461int shutdown(int, int);
1462int sockatmark(int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
1463int socket(int, int, int);
1464int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair);
91447636 1465
2d21ac55 1466#if !defined(_POSIX_C_SOURCE)
0a7de745
A
1467int sendfile(int, int, off_t, off_t *, struct sf_hdtr *, int);
1468#endif /* !_POSIX_C_SOURCE */
2d21ac55
A
1469
1470#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
0a7de745 1471void pfctlinput(int, struct sockaddr *);
5ba3f43e
A
1472
1473__API_AVAILABLE(macosx(10.11), ios(9.0), tvos(9.0), watchos(2.0))
39037602 1474int connectx(int, const sa_endpoints_t *, sae_associd_t, unsigned int,
3e170ce0 1475 const struct iovec *, unsigned int, size_t *, sae_connid_t *);
5ba3f43e
A
1476
1477__API_AVAILABLE(macosx(10.11), ios(9.0), tvos(9.0), watchos(2.0))
39037602 1478int disconnectx(int, sae_associd_t, sae_connid_t);
0a7de745 1479#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
1c79356b 1480__END_DECLS
1c79356b 1481#endif /* !KERNEL */
9bccf70c 1482
91447636
A
1483#ifdef KERNEL
1484#include <sys/kpi_socket.h>
1485#endif
1486
1c79356b 1487#endif /* !_SYS_SOCKET_H_ */