]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/socket.h
xnu-1504.9.17.tar.gz
[apple/xnu.git] / bsd / sys / socket.h
1 /*
2 * Copyright (c) 2000-2007 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 #endif
209 #define SO_LABEL 0x1010 /* socket's MAC label */
210 #define SO_PEERLABEL 0x1011 /* socket's peer MAC label */
211 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
212
213 /*
214 * Structure used for manipulating linger option.
215 */
216 struct linger {
217 int l_onoff; /* option on/off */
218 int l_linger; /* linger time */
219 };
220
221 #ifndef __APPLE__
222 struct accept_filter_arg {
223 char af_name[16];
224 char af_arg[256-16];
225 };
226 #endif
227
228 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
229 #ifdef __APPLE__
230
231 /*
232 * Structure to control non-portable Sockets extension to POSIX
233 */
234 struct so_np_extensions {
235 u_int32_t npx_flags;
236 u_int32_t npx_mask;
237 };
238
239 #define SONPX_SETOPTSHUT 0x000000001 /* flag for allowing setsockopt after shutdown */
240
241
242 #ifdef KERNEL_PRIVATE
243 #define SONPX_MASK_VALID (SONPX_SETOPTSHUT)
244 #endif
245
246 #endif
247 #endif
248
249 /*
250 * Level number for (get/set)sockopt() to apply to socket itself.
251 */
252 #define SOL_SOCKET 0xffff /* options for socket level */
253
254
255 /*
256 * Address families.
257 */
258 #define AF_UNSPEC 0 /* unspecified */
259 #define AF_UNIX 1 /* local to host (pipes) */
260 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
261 #define AF_LOCAL AF_UNIX /* backward compatibility */
262 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
263 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
264 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
265 #define AF_IMPLINK 3 /* arpanet imp addresses */
266 #define AF_PUP 4 /* pup protocols: e.g. BSP */
267 #define AF_CHAOS 5 /* mit CHAOS protocols */
268 #define AF_NS 6 /* XEROX NS protocols */
269 #define AF_ISO 7 /* ISO protocols */
270 #define AF_OSI AF_ISO
271 #define AF_ECMA 8 /* European computer manufacturers */
272 #define AF_DATAKIT 9 /* datakit protocols */
273 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
274 #define AF_SNA 11 /* IBM SNA */
275 #define AF_DECnet 12 /* DECnet */
276 #define AF_DLI 13 /* DEC Direct data link interface */
277 #define AF_LAT 14 /* LAT */
278 #define AF_HYLINK 15 /* NSC Hyperchannel */
279 #define AF_APPLETALK 16 /* Apple Talk */
280 #define AF_ROUTE 17 /* Internal Routing Protocol */
281 #define AF_LINK 18 /* Link layer interface */
282 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
283 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
284 #define AF_CNT 21 /* Computer Network Technology */
285 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
286 #define AF_IPX 23 /* Novell Internet Protocol */
287 #define AF_SIP 24 /* Simple Internet Protocol */
288 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
289 #ifdef __APPLE__
290 /*define pseudo_AF_BLUE 26 Identify packets for Blue Box - Not used */
291 #define AF_NDRV 27 /* Network Driver 'raw' access */
292 #endif
293 #define AF_ISDN 28 /* Integrated Services Digital Network*/
294 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
295 #define pseudo_AF_KEY 29 /* Internal key-management function */
296 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
297 #define AF_INET6 30 /* IPv6 */
298 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
299 #define AF_NATM 31 /* native ATM access */
300 #ifdef __APPLE__
301 #define AF_SYSTEM 32 /* Kernel event messages */
302 #define AF_NETBIOS 33 /* NetBIOS */
303 #define AF_PPP 34 /* PPP communication protocol */
304 #else
305 #define AF_ATM 30 /* ATM */
306 #endif
307 #define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers
308 * in interface output routine
309 */
310 #ifdef PRIVATE
311 #define AF_AFP 36 /* Used by AFP */
312 #else
313 #define AF_RESERVED_36 36 /* Reserved for internal usage */
314 #endif
315
316 #ifndef __APPLE__
317 #define AF_NETGRAPH 32 /* Netgraph sockets */
318 #endif
319 #define AF_IEEE80211 37 /* IEEE 802.11 protocol */
320 #define AF_MAX 38
321 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
322
323 /*
324 * [XSI] Structure used by kernel to store most addresses.
325 */
326 struct sockaddr {
327 __uint8_t sa_len; /* total length */
328 sa_family_t sa_family; /* [XSI] address family */
329 char sa_data[14]; /* [XSI] addr value (actually larger) */
330 };
331
332 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
333 #define SOCK_MAXADDRLEN 255 /* longest possible addresses */
334
335 /*
336 * Structure used by kernel to pass protocol
337 * information in raw sockets.
338 */
339 struct sockproto {
340 __uint16_t sp_family; /* address family */
341 __uint16_t sp_protocol; /* protocol */
342 };
343 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE)*/
344
345 /*
346 * RFC 2553: protocol-independent placeholder for socket addresses
347 */
348 #define _SS_MAXSIZE 128
349 #define _SS_ALIGNSIZE (sizeof(__int64_t))
350 #define _SS_PAD1SIZE \
351 (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
352 #define _SS_PAD2SIZE \
353 (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
354 _SS_PAD1SIZE - _SS_ALIGNSIZE)
355
356 /*
357 * [XSI] sockaddr_storage
358 */
359 struct sockaddr_storage {
360 __uint8_t ss_len; /* address length */
361 sa_family_t ss_family; /* [XSI] address family */
362 char __ss_pad1[_SS_PAD1SIZE];
363 __int64_t __ss_align; /* force structure storage alignment */
364 char __ss_pad2[_SS_PAD2SIZE];
365 };
366
367 /*
368 * Protocol families, same as address families for now.
369 */
370 #define PF_UNSPEC AF_UNSPEC
371 #define PF_LOCAL AF_LOCAL
372 #define PF_UNIX PF_LOCAL /* backward compatibility */
373 #define PF_INET AF_INET
374 #define PF_IMPLINK AF_IMPLINK
375 #define PF_PUP AF_PUP
376 #define PF_CHAOS AF_CHAOS
377 #define PF_NS AF_NS
378 #define PF_ISO AF_ISO
379 #define PF_OSI AF_ISO
380 #define PF_ECMA AF_ECMA
381 #define PF_DATAKIT AF_DATAKIT
382 #define PF_CCITT AF_CCITT
383 #define PF_SNA AF_SNA
384 #define PF_DECnet AF_DECnet
385 #define PF_DLI AF_DLI
386 #define PF_LAT AF_LAT
387 #define PF_HYLINK AF_HYLINK
388 #define PF_APPLETALK AF_APPLETALK
389 #define PF_ROUTE AF_ROUTE
390 #define PF_LINK AF_LINK
391 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
392 #define PF_COIP AF_COIP
393 #define PF_CNT AF_CNT
394 #define PF_SIP AF_SIP
395 #define PF_IPX AF_IPX /* same format as AF_NS */
396 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
397 #define PF_PIP pseudo_AF_PIP
398 #ifdef __APPLE__
399 #define PF_NDRV AF_NDRV
400 #endif
401 #define PF_ISDN AF_ISDN
402 #define PF_KEY pseudo_AF_KEY
403 #define PF_INET6 AF_INET6
404 #define PF_NATM AF_NATM
405 #ifdef __APPLE__
406 #define PF_SYSTEM AF_SYSTEM
407 #define PF_NETBIOS AF_NETBIOS
408 #define PF_PPP AF_PPP
409 #ifdef PRIVATE
410 #define PF_AFP AF_AFP
411 #else
412 #define PF_RESERVED_36 AF_RESERVED_36
413 #endif
414
415 #else
416 #define PF_ATM AF_ATM
417 #define PF_NETGRAPH AF_NETGRAPH
418 #endif
419
420 #define PF_MAX AF_MAX
421
422 /*
423 * These do not have socket-layer support:
424 */
425 #define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */
426 #define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */
427
428 /*
429 * Definitions for network related sysctl, CTL_NET.
430 *
431 * Second level is protocol family.
432 * Third level is protocol number.
433 *
434 * Further levels are defined by the individual families below.
435 */
436 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
437 #define NET_MAXID AF_MAX
438 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
439
440 #ifdef KERNEL_PRIVATE
441 #define CTL_NET_NAMES { \
442 { 0, 0 }, \
443 { "local", CTLTYPE_NODE }, \
444 { "inet", CTLTYPE_NODE }, \
445 { "implink", CTLTYPE_NODE }, \
446 { "pup", CTLTYPE_NODE }, \
447 { "chaos", CTLTYPE_NODE }, \
448 { "xerox_ns", CTLTYPE_NODE }, \
449 { "iso", CTLTYPE_NODE }, \
450 { "emca", CTLTYPE_NODE }, \
451 { "datakit", CTLTYPE_NODE }, \
452 { "ccitt", CTLTYPE_NODE }, \
453 { "ibm_sna", CTLTYPE_NODE }, \
454 { "decnet", CTLTYPE_NODE }, \
455 { "dec_dli", CTLTYPE_NODE }, \
456 { "lat", CTLTYPE_NODE }, \
457 { "hylink", CTLTYPE_NODE }, \
458 { "appletalk", CTLTYPE_NODE }, \
459 { "route", CTLTYPE_NODE }, \
460 { "link_layer", CTLTYPE_NODE }, \
461 { "xtp", CTLTYPE_NODE }, \
462 { "coip", CTLTYPE_NODE }, \
463 { "cnt", CTLTYPE_NODE }, \
464 { "rtip", CTLTYPE_NODE }, \
465 { "ipx", CTLTYPE_NODE }, \
466 { "sip", CTLTYPE_NODE }, \
467 { "pip", CTLTYPE_NODE }, \
468 { 0, 0 }, \
469 { "ndrv", CTLTYPE_NODE }, \
470 { "isdn", CTLTYPE_NODE }, \
471 { "key", CTLTYPE_NODE }, \
472 { "inet6", CTLTYPE_NODE }, \
473 { "natm", CTLTYPE_NODE }, \
474 { "sys", CTLTYPE_NODE }, \
475 { "netbios", CTLTYPE_NODE }, \
476 { "ppp", CTLTYPE_NODE }, \
477 { "hdrcomplete", CTLTYPE_NODE }, \
478 }
479 #endif /* KERNEL_PRIVATE */
480
481 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
482 /*
483 * PF_ROUTE - Routing table
484 *
485 * Three additional levels are defined:
486 * Fourth: address family, 0 is wildcard
487 * Fifth: type of info, defined below
488 * Sixth: flag(s) to mask with for NET_RT_FLAGS
489 */
490 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
491 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
492 #define NET_RT_IFLIST 3 /* survey interface list */
493 #define NET_RT_STAT 4 /* routing statistics */
494 #define NET_RT_TRASH 5 /* routes not in table but not freed */
495 #define NET_RT_IFLIST2 6 /* interface list with addresses */
496 #define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
497 #define NET_RT_MAXID 8
498 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
499
500 #ifdef KERNEL_PRIVATE
501 #define CTL_NET_RT_NAMES { \
502 { 0, 0 }, \
503 { "dump", CTLTYPE_STRUCT }, \
504 { "flags", CTLTYPE_STRUCT }, \
505 { "iflist", CTLTYPE_STRUCT }, \
506 { "stat", CTLTYPE_STRUCT }, \
507 { "trash", CTLTYPE_INT }, \
508 { "iflist2", CTLTYPE_STRUCT }, \
509 { "dump2", CTLTYPE_STRUCT }, \
510 }
511
512 #endif /* KERNEL_PRIVATE */
513
514 /*
515 * Maximum queue length specifiable by listen.
516 */
517 #define SOMAXCONN 128
518
519 /*
520 * [XSI] Message header for recvmsg and sendmsg calls.
521 * Used value-result for recvmsg, value only for sendmsg.
522 */
523 struct msghdr {
524 void *msg_name; /* [XSI] optional address */
525 socklen_t msg_namelen; /* [XSI] size of address */
526 struct iovec *msg_iov; /* [XSI] scatter/gather array */
527 int msg_iovlen; /* [XSI] # elements in msg_iov */
528 void *msg_control; /* [XSI] ancillary data, see below */
529 socklen_t msg_controllen; /* [XSI] ancillary data buffer len */
530 int msg_flags; /* [XSI] flags on received message */
531 };
532
533 #ifdef KERNEL
534 /*
535 * In-kernel representation of "struct msghdr" from
536 * userspace. Has enough precision for 32-bit or
537 * 64-bit clients, but does not need to be packed.
538 */
539
540 struct user_msghdr {
541 user_addr_t msg_name; /* optional address */
542 socklen_t msg_namelen; /* size of address */
543 user_addr_t msg_iov; /* scatter/gather array */
544 int msg_iovlen; /* # elements in msg_iov */
545 user_addr_t msg_control; /* ancillary data, see below */
546 socklen_t msg_controllen; /* ancillary data buffer len */
547 int msg_flags; /* flags on received message */
548 };
549
550 /*
551 * LP64 user version of struct msghdr.
552 * WARNING - keep in sync with struct msghdr
553 */
554
555 struct user64_msghdr {
556 user64_addr_t msg_name; /* optional address */
557 socklen_t msg_namelen; /* size of address */
558 user64_addr_t msg_iov; /* scatter/gather array */
559 int msg_iovlen; /* # elements in msg_iov */
560 user64_addr_t msg_control; /* ancillary data, see below */
561 socklen_t msg_controllen; /* ancillary data buffer len */
562 int msg_flags; /* flags on received message */
563 };
564
565 /*
566 * ILP32 user version of struct msghdr.
567 * WARNING - keep in sync with struct msghdr
568 */
569
570 struct user32_msghdr {
571 user32_addr_t msg_name; /* optional address */
572 socklen_t msg_namelen; /* size of address */
573 user32_addr_t msg_iov; /* scatter/gather array */
574 int msg_iovlen; /* # elements in msg_iov */
575 user32_addr_t msg_control; /* ancillary data, see below */
576 socklen_t msg_controllen; /* ancillary data buffer len */
577 int msg_flags; /* flags on received message */
578 };
579
580 #endif // KERNEL
581
582 #define MSG_OOB 0x1 /* process out-of-band data */
583 #define MSG_PEEK 0x2 /* peek at incoming message */
584 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
585 #define MSG_EOR 0x8 /* data completes record */
586 #define MSG_TRUNC 0x10 /* data discarded before delivery */
587 #define MSG_CTRUNC 0x20 /* control data lost before delivery */
588 #define MSG_WAITALL 0x40 /* wait for full request or error */
589 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
590 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
591 #define MSG_EOF 0x100 /* data completes connection */
592 #ifdef __APPLE__
593 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
594 #define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp */
595 #define MSG_HOLD 0x800 /* Hold frag in so_temp */
596 #define MSG_SEND 0x1000 /* Send the packet in so_temp */
597 #define MSG_HAVEMORE 0x2000 /* Data ready to be read */
598 #define MSG_RCVMORE 0x4000 /* Data remains in current pkt */
599 #endif
600 #ifdef KERNEL_PRIVATE
601 #define MSG_COMPAT 0x8000 /* deprecated */
602 #endif /* KERNEL_PRIVATE */
603 #define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */
604 #ifdef KERNEL_PRIVATE
605 #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */
606 #endif
607 #ifdef KERNEL
608 #define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */
609 #endif
610 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
611
612 /*
613 * Header for ancillary data objects in msg_control buffer.
614 * Used for additional information with/about a datagram
615 * not expressible by flags. The format is a sequence
616 * of message elements headed by cmsghdr structures.
617 */
618 struct cmsghdr {
619 socklen_t cmsg_len; /* [XSI] data byte count, including hdr */
620 int cmsg_level; /* [XSI] originating protocol */
621 int cmsg_type; /* [XSI] protocol-specific type */
622 /* followed by unsigned char cmsg_data[]; */
623 };
624
625 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
626 #ifndef __APPLE__
627 /*
628 * While we may have more groups than this, the cmsgcred struct must
629 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
630 * this.
631 */
632 #define CMGROUP_MAX 16
633
634 /*
635 * Credentials structure, used to verify the identity of a peer
636 * process that has sent us a message. This is allocated by the
637 * peer process but filled in by the kernel. This prevents the
638 * peer from lying about its identity. (Note that cmcred_groups[0]
639 * is the effective GID.)
640 */
641 struct cmsgcred {
642 pid_t cmcred_pid; /* PID of sending process */
643 uid_t cmcred_uid; /* real UID of sending process */
644 uid_t cmcred_euid; /* effective UID of sending process */
645 gid_t cmcred_gid; /* real GID of sending process */
646 short cmcred_ngroups; /* number or groups */
647 gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
648 };
649 #endif
650 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
651
652 /* given pointer to struct cmsghdr, return pointer to data */
653 #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
654 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
655
656 /*
657 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
658 * an empty list for some reasons.
659 */
660 #define CMSG_FIRSTHDR(mhdr) \
661 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
662 (struct cmsghdr *)(mhdr)->msg_control : \
663 (struct cmsghdr *)0L)
664
665
666 /*
667 * Given pointer to struct cmsghdr, return pointer to next cmsghdr
668 * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
669 */
670 #define CMSG_NXTHDR(mhdr, cmsg) \
671 ((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) : \
672 ((((unsigned char *)(cmsg) + \
673 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) + \
674 __DARWIN_ALIGN32(sizeof(struct cmsghdr))) > \
675 ((unsigned char *)(mhdr)->msg_control + \
676 (mhdr)->msg_controllen)) ? \
677 (struct cmsghdr *)0L /* NULL */ : \
678 (struct cmsghdr *)((unsigned char *)(cmsg) + \
679 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
680
681 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
682 /* RFC 2292 additions */
683 #define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
684 #define CMSG_LEN(l) (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
685
686 #ifdef KERNEL
687 #define CMSG_ALIGN(n) __DARWIN_ALIGN32(n)
688 #endif
689 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
690
691 /* "Socket"-level control message types: */
692 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
693 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
694 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
695 #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
696
697 #ifdef KERNEL_PRIVATE
698 /*
699 * 4.3 compat sockaddr (deprecated)
700 */
701 struct osockaddr {
702 __uint16_t sa_family; /* address family */
703 char sa_data[14]; /* up to 14 bytes of direct address */
704 };
705
706 /*
707 * 4.3-compat message header (deprecated)
708 */
709 struct omsghdr {
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_accrights; /* access rights sent/rcvd */
715 int msg_accrightslen;
716 };
717 #endif /* KERNEL_PRIVATE */
718 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
719
720 /*
721 * howto arguments for shutdown(2), specified by Posix.1g.
722 */
723 #define SHUT_RD 0 /* shut down the reading side */
724 #define SHUT_WR 1 /* shut down the writing side */
725 #define SHUT_RDWR 2 /* shut down both sides */
726
727 #if !defined(_POSIX_C_SOURCE)
728 /*
729 * sendfile(2) header/trailer struct
730 */
731 struct sf_hdtr {
732 struct iovec *headers; /* pointer to an array of header struct iovec's */
733 int hdr_cnt; /* number of header iovec's */
734 struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
735 int trl_cnt; /* number of trailer iovec's */
736 };
737
738 #ifdef KERNEL
739
740 /* In-kernel representation */
741 struct user_sf_hdtr {
742 user_addr_t headers; /* pointer to an array of header struct iovec's */
743 int hdr_cnt; /* number of header iovec's */
744 user_addr_t trailers; /* pointer to an array of trailer struct iovec's */
745 int trl_cnt; /* number of trailer iovec's */
746 };
747
748 /* LP64 user version of struct sf_hdtr */
749 struct user64_sf_hdtr {
750 user64_addr_t headers; /* pointer to an array of header struct iovec's */
751 int hdr_cnt; /* number of header iovec's */
752 user64_addr_t trailers; /* pointer to an array of trailer struct iovec's */
753 int trl_cnt; /* number of trailer iovec's */
754 };
755
756 /* ILP32 user version of struct sf_hdtr */
757 struct user32_sf_hdtr {
758 user32_addr_t headers; /* pointer to an array of header struct iovec's */
759 int hdr_cnt; /* number of header iovec's */
760 user32_addr_t trailers; /* pointer to an array of trailer struct iovec's */
761 int trl_cnt; /* number of trailer iovec's */
762 };
763
764 #endif /* KERNEL */
765
766 #endif /* !_POSIX_C_SOURCE */
767
768 #ifndef KERNEL
769 __BEGIN_DECLS
770 int accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
771 __DARWIN_ALIAS_C(accept);
772 int bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
773 int connect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C( connect);
774 int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
775 __DARWIN_ALIAS(getpeername);
776 int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
777 __DARWIN_ALIAS(getsockname);
778 int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
779 int listen(int, int) __DARWIN_ALIAS(listen);
780 ssize_t recv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv);
781 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict,
782 socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
783 ssize_t recvmsg(int, struct msghdr *, int) __DARWIN_ALIAS_C(recvmsg);
784 ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);
785 ssize_t sendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS_C(sendmsg);
786 ssize_t sendto(int, const void *, size_t,
787 int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(sendto);
788 int setsockopt(int, int, int, const void *, socklen_t);
789 int shutdown(int, int);
790 int sockatmark(int);
791 int socket(int, int, int);
792 int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair);
793
794 #if !defined(_POSIX_C_SOURCE)
795 int sendfile(int, int, off_t, off_t *, struct sf_hdtr *, int);
796 #endif /* !_POSIX_C_SOURCE */
797
798 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
799 void pfctlinput(int, struct sockaddr *);
800 #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
801 __END_DECLS
802
803 #endif /* !KERNEL */
804
805 #ifdef KERNEL
806 #include <sys/kpi_socket.h>
807 #endif
808
809 #endif /* !_SYS_SOCKET_H_ */