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