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