]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/socket.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / sys / socket.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, 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 #ifndef _SYS_SOCKET_H_
67 #define _SYS_SOCKET_H_
68
69 #include <sys/_types.h>
70 #include <sys/cdefs.h>
71
72 #define _NO_NAMESPACE_POLLUTION
73 #include <machine/param.h>
74 #undef _NO_NAMESPACE_POLLUTION
75
76 /*
77 * Definitions related to sockets: types, address families, options.
78 */
79
80 /*
81 * Data types.
82 */
83 #ifndef _GID_T
84 typedef __darwin_gid_t gid_t;
85 #define _GID_T
86 #endif
87
88 #ifndef _OFF_T
89 typedef __darwin_off_t off_t;
90 #define _OFF_T
91 #endif
92
93 #ifndef _PID_T
94 typedef __darwin_pid_t pid_t;
95 #define _PID_T
96 #endif
97
98 #ifndef _SA_FAMILY_T
99 #define _SA_FAMILY_T
100 typedef __uint8_t sa_family_t;
101 #endif
102
103 #ifndef _SOCKLEN_T
104 #define _SOCKLEN_T
105 typedef __darwin_socklen_t socklen_t;
106 #endif
107
108 /* XXX Not explicitly defined by POSIX, but function return types are */
109 #ifndef _SIZE_T
110 #define _SIZE_T
111 typedef __darwin_size_t size_t;
112 #endif
113
114 /* XXX Not explicitly defined by POSIX, but function return types are */
115 #ifndef _SSIZE_T
116 #define _SSIZE_T
117 typedef __darwin_ssize_t ssize_t;
118 #endif
119
120 /*
121 * [XSI] The iovec structure shall be defined as described in <sys/uio.h>.
122 */
123 #ifndef _STRUCT_IOVEC
124 #define _STRUCT_IOVEC
125 struct iovec {
126 void * iov_base; /* [XSI] Base address of I/O memory region */
127 size_t iov_len; /* [XSI] Size of region iov_base points to */
128 };
129 #endif
130
131 /*
132 * Types
133 */
134 #define SOCK_STREAM 1 /* stream socket */
135 #define SOCK_DGRAM 2 /* datagram socket */
136 #define SOCK_RAW 3 /* raw-protocol interface */
137 #ifndef _POSIX_C_SOURCE
138 #define SOCK_RDM 4 /* reliably-delivered message */
139 #endif /* !_POSIX_C_SOURCE */
140 #define SOCK_SEQPACKET 5 /* sequenced packet stream */
141
142 /*
143 * Option flags per-socket.
144 */
145 #define SO_DEBUG 0x0001 /* turn on debugging info recording */
146 #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
147 #define SO_REUSEADDR 0x0004 /* allow local address reuse */
148 #define SO_KEEPALIVE 0x0008 /* keep connections alive */
149 #define SO_DONTROUTE 0x0010 /* just use interface addresses */
150 #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
151 #ifndef _POSIX_C_SOURCE
152 #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
153 #define SO_LINGER 0x0080 /* linger on close if data present (in ticks) */
154 #else
155 #define SO_LINGER 0x1080 /* linger on close if data present (in seconds) */
156 #endif /* !_POSIX_C_SOURCE */
157 #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
158 #ifndef _POSIX_C_SOURCE
159 #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
160 #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
161 #ifndef __APPLE__
162 #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
163 #else
164 #define SO_DONTTRUNC 0x2000 /* APPLE: Retain unread data */
165 /* (ATOMIC proto) */
166 #define SO_WANTMORE 0x4000 /* APPLE: Give hint when more data ready */
167 #define SO_WANTOOBFLAG 0x8000 /* APPLE: Want OOB in MSG_FLAG on receive */
168 #endif
169 #endif /* !_POSIX_C_SOURCE */
170
171 /*
172 * Additional options, not kept in so_options.
173 */
174 #define SO_SNDBUF 0x1001 /* send buffer size */
175 #define SO_RCVBUF 0x1002 /* receive buffer size */
176 #define SO_SNDLOWAT 0x1003 /* send low-water mark */
177 #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
178 #define SO_SNDTIMEO 0x1005 /* send timeout */
179 #define SO_RCVTIMEO 0x1006 /* receive timeout */
180 #define SO_ERROR 0x1007 /* get error status and clear */
181 #define SO_TYPE 0x1008 /* get socket type */
182 #ifndef _POSIX_C_SOURCE
183 /*efine SO_PRIVSTATE 0x1009 get/deny privileged state */
184 #ifdef __APPLE__
185 #define SO_NREAD 0x1020 /* APPLE: get 1st-packet byte count */
186 #define SO_NKE 0x1021 /* APPLE: Install socket-level NKE */
187 #define SO_NOSIGPIPE 0x1022 /* APPLE: No SIGPIPE on EPIPE */
188 #define SO_NOADDRERR 0x1023 /* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
189 #define SO_NWRITE 0x1024 /* APPLE: Get number of bytes currently in send socket buffer */
190 #define SO_LINGER_SEC 0x1080 /* linger on close if data present (in seconds) */
191 #endif
192 #endif /* !_POSIX_C_SOURCE */
193
194 /*
195 * Structure used for manipulating linger option.
196 */
197 struct linger {
198 int l_onoff; /* option on/off */
199 int l_linger; /* linger time */
200 };
201
202 #ifndef __APPLE__
203 struct accept_filter_arg {
204 char af_name[16];
205 char af_arg[256-16];
206 };
207 #endif
208
209 /*
210 * Level number for (get/set)sockopt() to apply to socket itself.
211 */
212 #define SOL_SOCKET 0xffff /* options for socket level */
213
214 /*
215 * Address families.
216 */
217 #define AF_UNSPEC 0 /* unspecified */
218 #define AF_UNIX 1 /* local to host (pipes) */
219 #ifndef _POSIX_C_SOURCE
220 #define AF_LOCAL AF_UNIX /* backward compatibility */
221 #endif /* !_POSIX_C_SOURCE */
222 #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
223 #ifndef _POSIX_C_SOURCE
224 #define AF_IMPLINK 3 /* arpanet imp addresses */
225 #define AF_PUP 4 /* pup protocols: e.g. BSP */
226 #define AF_CHAOS 5 /* mit CHAOS protocols */
227 #define AF_NS 6 /* XEROX NS protocols */
228 #define AF_ISO 7 /* ISO protocols */
229 #define AF_OSI AF_ISO
230 #define AF_ECMA 8 /* European computer manufacturers */
231 #define AF_DATAKIT 9 /* datakit protocols */
232 #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
233 #define AF_SNA 11 /* IBM SNA */
234 #define AF_DECnet 12 /* DECnet */
235 #define AF_DLI 13 /* DEC Direct data link interface */
236 #define AF_LAT 14 /* LAT */
237 #define AF_HYLINK 15 /* NSC Hyperchannel */
238 #define AF_APPLETALK 16 /* Apple Talk */
239 #define AF_ROUTE 17 /* Internal Routing Protocol */
240 #define AF_LINK 18 /* Link layer interface */
241 #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
242 #define AF_COIP 20 /* connection-oriented IP, aka ST II */
243 #define AF_CNT 21 /* Computer Network Technology */
244 #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
245 #define AF_IPX 23 /* Novell Internet Protocol */
246 #define AF_SIP 24 /* Simple Internet Protocol */
247 #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
248 #ifdef __APPLE__
249 /*define pseudo_AF_BLUE 26 Identify packets for Blue Box - Not used */
250 #define AF_NDRV 27 /* Network Driver 'raw' access */
251 #endif
252 #define AF_ISDN 28 /* Integrated Services Digital Network*/
253 #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
254 #define pseudo_AF_KEY 29 /* Internal key-management function */
255 #endif /* !_POSIX_C_SOURCE */
256 #define AF_INET6 30 /* IPv6 */
257 #ifndef _POSIX_C_SOURCE
258 #define AF_NATM 31 /* native ATM access */
259 #ifdef __APPLE__
260 #define AF_SYSTEM 32 /* Kernel event messages */
261 #define AF_NETBIOS 33 /* NetBIOS */
262 #define AF_PPP 34 /* PPP communication protocol */
263 #else
264 #define AF_ATM 30 /* ATM */
265 #endif
266 #define pseudo_AF_HDRCMPLT 35 /* Used by BPF to not rewrite headers
267 * in interface output routine
268 */
269 #ifdef PRIVATE
270 #define AF_AFP 36 /* Used by AFP */
271 #else
272 #define AF_RESERVED_36 36 /* Reserved for internal usage */
273 #endif
274
275 #ifndef __APPLE__
276 #define AF_NETGRAPH 32 /* Netgraph sockets */
277 #endif
278 #define AF_MAX 37
279 #endif /* !_POSIX_C_SOURCE */
280
281 /*
282 * [XSI] Structure used by kernel to store most addresses.
283 */
284 struct sockaddr {
285 __uint8_t sa_len; /* total length */
286 sa_family_t sa_family; /* [XSI] address family */
287 char sa_data[14]; /* [XSI] addr value (actually larger) */
288 };
289
290 #ifndef _POSIX_C_SOURCE
291 #define SOCK_MAXADDRLEN 255 /* longest possible addresses */
292
293 /*
294 * Structure used by kernel to pass protocol
295 * information in raw sockets.
296 */
297 struct sockproto {
298 __uint16_t sp_family; /* address family */
299 __uint16_t sp_protocol; /* protocol */
300 };
301 #endif /* !_POSIX_C_SOURCE*/
302
303 /*
304 * RFC 2553: protocol-independent placeholder for socket addresses
305 */
306 #define _SS_MAXSIZE 128
307 #define _SS_ALIGNSIZE (sizeof(__int64_t))
308 #define _SS_PAD1SIZE \
309 (_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
310 #define _SS_PAD2SIZE \
311 (_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
312 _SS_PAD1SIZE - _SS_ALIGNSIZE)
313
314 /*
315 * [XSI] sockaddr_storage
316 */
317 struct sockaddr_storage {
318 __uint8_t ss_len; /* address length */
319 sa_family_t ss_family; /* [XSI] address family */
320 char __ss_pad1[_SS_PAD1SIZE];
321 __int64_t __ss_align; /* force structure storage alignment */
322 char __ss_pad2[_SS_PAD2SIZE];
323 };
324
325 /*
326 * Protocol families, same as address families for now.
327 */
328 #define PF_UNSPEC AF_UNSPEC
329 #define PF_LOCAL AF_LOCAL
330 #define PF_UNIX PF_LOCAL /* backward compatibility */
331 #define PF_INET AF_INET
332 #define PF_IMPLINK AF_IMPLINK
333 #define PF_PUP AF_PUP
334 #define PF_CHAOS AF_CHAOS
335 #define PF_NS AF_NS
336 #define PF_ISO AF_ISO
337 #define PF_OSI AF_ISO
338 #define PF_ECMA AF_ECMA
339 #define PF_DATAKIT AF_DATAKIT
340 #define PF_CCITT AF_CCITT
341 #define PF_SNA AF_SNA
342 #define PF_DECnet AF_DECnet
343 #define PF_DLI AF_DLI
344 #define PF_LAT AF_LAT
345 #define PF_HYLINK AF_HYLINK
346 #define PF_APPLETALK AF_APPLETALK
347 #define PF_ROUTE AF_ROUTE
348 #define PF_LINK AF_LINK
349 #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
350 #define PF_COIP AF_COIP
351 #define PF_CNT AF_CNT
352 #define PF_SIP AF_SIP
353 #define PF_IPX AF_IPX /* same format as AF_NS */
354 #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
355 #define PF_PIP pseudo_AF_PIP
356 #ifdef __APPLE__
357 #define PF_NDRV AF_NDRV
358 #endif
359 #define PF_ISDN AF_ISDN
360 #define PF_KEY pseudo_AF_KEY
361 #define PF_INET6 AF_INET6
362 #define PF_NATM AF_NATM
363 #ifdef __APPLE__
364 #define PF_SYSTEM AF_SYSTEM
365 #define PF_NETBIOS AF_NETBIOS
366 #define PF_PPP AF_PPP
367 #ifdef PRIVATE
368 #define PF_AFP AF_AFP
369 #else
370 #define PF_RESERVED_36 AF_RESERVED_36
371 #endif
372
373 #else
374 #define PF_ATM AF_ATM
375 #define PF_NETGRAPH AF_NETGRAPH
376 #endif
377
378 #define PF_MAX AF_MAX
379
380 /*
381 * These do not have socket-layer support:
382 */
383 #define PF_VLAN ((uint32_t)0x766c616e) /* 'vlan' */
384 #define PF_BOND ((uint32_t)0x626f6e64) /* 'bond' */
385
386 /*
387 * Definitions for network related sysctl, CTL_NET.
388 *
389 * Second level is protocol family.
390 * Third level is protocol number.
391 *
392 * Further levels are defined by the individual families below.
393 */
394 #define NET_MAXID AF_MAX
395
396
397 #ifdef KERNEL_PRIVATE
398 #define CTL_NET_NAMES { \
399 { 0, 0 }, \
400 { "local", CTLTYPE_NODE }, \
401 { "inet", CTLTYPE_NODE }, \
402 { "implink", CTLTYPE_NODE }, \
403 { "pup", CTLTYPE_NODE }, \
404 { "chaos", CTLTYPE_NODE }, \
405 { "xerox_ns", CTLTYPE_NODE }, \
406 { "iso", CTLTYPE_NODE }, \
407 { "emca", CTLTYPE_NODE }, \
408 { "datakit", CTLTYPE_NODE }, \
409 { "ccitt", CTLTYPE_NODE }, \
410 { "ibm_sna", CTLTYPE_NODE }, \
411 { "decnet", CTLTYPE_NODE }, \
412 { "dec_dli", CTLTYPE_NODE }, \
413 { "lat", CTLTYPE_NODE }, \
414 { "hylink", CTLTYPE_NODE }, \
415 { "appletalk", CTLTYPE_NODE }, \
416 { "route", CTLTYPE_NODE }, \
417 { "link_layer", CTLTYPE_NODE }, \
418 { "xtp", CTLTYPE_NODE }, \
419 { "coip", CTLTYPE_NODE }, \
420 { "cnt", CTLTYPE_NODE }, \
421 { "rtip", CTLTYPE_NODE }, \
422 { "ipx", CTLTYPE_NODE }, \
423 { "sip", CTLTYPE_NODE }, \
424 { "pip", CTLTYPE_NODE }, \
425 { 0, 0 }, \
426 { "ndrv", CTLTYPE_NODE }, \
427 { "isdn", CTLTYPE_NODE }, \
428 { "key", CTLTYPE_NODE }, \
429 { "inet6", CTLTYPE_NODE }, \
430 { "natm", CTLTYPE_NODE }, \
431 { "sys", CTLTYPE_NODE }, \
432 { "netbios", CTLTYPE_NODE }, \
433 { "ppp", CTLTYPE_NODE }, \
434 { "hdrcomplete", CTLTYPE_NODE }, \
435 }
436 #endif KERNEL_PRIVATE
437
438 /*
439 * PF_ROUTE - Routing table
440 *
441 * Three additional levels are defined:
442 * Fourth: address family, 0 is wildcard
443 * Fifth: type of info, defined below
444 * Sixth: flag(s) to mask with for NET_RT_FLAGS
445 */
446 #define NET_RT_DUMP 1 /* dump; may limit to a.f. */
447 #define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
448 #define NET_RT_IFLIST 3 /* survey interface list */
449 #define NET_RT_STAT 4 /* routing statistics */
450 #define NET_RT_TRASH 5 /* routes not in table but not freed */
451 #define NET_RT_IFLIST2 6 /* interface list with addresses */
452 #define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
453 #define NET_RT_MAXID 8
454
455 #ifdef KERNEL_PRIVATE
456 #define CTL_NET_RT_NAMES { \
457 { 0, 0 }, \
458 { "dump", CTLTYPE_STRUCT }, \
459 { "flags", CTLTYPE_STRUCT }, \
460 { "iflist", CTLTYPE_STRUCT }, \
461 { "stat", CTLTYPE_STRUCT }, \
462 { "trash", CTLTYPE_INT }, \
463 { "iflist2", CTLTYPE_STRUCT }, \
464 { "dump2", CTLTYPE_STRUCT }, \
465 }
466
467 #endif KERNEL_PRIVATE
468
469 /*
470 * Maximum queue length specifiable by listen.
471 */
472 #define SOMAXCONN 128
473
474 /*
475 * [XSI] Message header for recvmsg and sendmsg calls.
476 * Used value-result for recvmsg, value only for sendmsg.
477 */
478 struct msghdr {
479 void *msg_name; /* [XSI] optional address */
480 socklen_t msg_namelen; /* [XSI] size of address */
481 struct iovec *msg_iov; /* [XSI] scatter/gather array */
482 int msg_iovlen; /* [XSI] # elements in msg_iov */
483 void *msg_control; /* [XSI] ancillary data, see below */
484 socklen_t msg_controllen; /* [XSI] ancillary data buffer len */
485 int msg_flags; /* [XSI] flags on received message */
486 };
487
488 // LP64todo - should this move?
489 #ifdef KERNEL
490 /* LP64 version of struct msghdr. all pointers
491 * grow when we're dealing with a 64-bit process.
492 * WARNING - keep in sync with struct msghdr
493 */
494 #if __DARWIN_ALIGN_NATURAL
495 #pragma options align=natural
496 #endif
497
498 struct user_msghdr {
499 user_addr_t msg_name; /* optional address */
500 socklen_t msg_namelen; /* size of address */
501 user_addr_t msg_iov; /* scatter/gather array */
502 int msg_iovlen; /* # elements in msg_iov */
503 user_addr_t msg_control; /* ancillary data, see below */
504 socklen_t msg_controllen; /* ancillary data buffer len */
505 int msg_flags; /* flags on received message */
506 };
507
508 #if __DARWIN_ALIGN_NATURAL
509 #pragma options align=reset
510 #endif
511
512 #endif // KERNEL
513
514 #define MSG_OOB 0x1 /* process out-of-band data */
515 #define MSG_PEEK 0x2 /* peek at incoming message */
516 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
517 #define MSG_EOR 0x8 /* data completes record */
518 #define MSG_TRUNC 0x10 /* data discarded before delivery */
519 #define MSG_CTRUNC 0x20 /* control data lost before delivery */
520 #define MSG_WAITALL 0x40 /* wait for full request or error */
521 #ifndef _POSIX_C_SOURCE
522 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
523 #define MSG_EOF 0x100 /* data completes connection */
524 #ifdef __APPLE__
525 #define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
526 #define MSG_FLUSH 0x400 /* Start of 'hold' seq; dump so_temp */
527 #define MSG_HOLD 0x800 /* Hold frag in so_temp */
528 #define MSG_SEND 0x1000 /* Send the packet in so_temp */
529 #define MSG_HAVEMORE 0x2000 /* Data ready to be read */
530 #define MSG_RCVMORE 0x4000 /* Data remains in current pkt */
531 #endif
532 #define MSG_COMPAT 0x8000 /* used in sendit() */
533 #define MSG_NEEDSA 0x10000 /* Fail receive if socket address cannot be allocated */
534 #ifdef KERNEL_PRIVATE
535 #define MSG_NBIO 0x20000 /* FIONBIO mode, used by fifofs */
536 #endif
537 #ifdef KERNEL
538 #define MSG_USEUPCALL 0x80000000 /* Inherit upcall in sock_accept */
539 #endif
540 #endif /* !_POSIX_C_SOURCE */
541
542 /*
543 * Header for ancillary data objects in msg_control buffer.
544 * Used for additional information with/about a datagram
545 * not expressible by flags. The format is a sequence
546 * of message elements headed by cmsghdr structures.
547 */
548 struct cmsghdr {
549 socklen_t cmsg_len; /* [XSI] data byte count, including hdr */
550 int cmsg_level; /* [XSI] originating protocol */
551 int cmsg_type; /* [XSI] protocol-specific type */
552 /* followed by unsigned char cmsg_data[]; */
553 };
554
555 #ifndef _POSIX_C_SOURCE
556 #ifndef __APPLE__
557 /*
558 * While we may have more groups than this, the cmsgcred struct must
559 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
560 * this.
561 */
562 #define CMGROUP_MAX 16
563
564 /*
565 * Credentials structure, used to verify the identity of a peer
566 * process that has sent us a message. This is allocated by the
567 * peer process but filled in by the kernel. This prevents the
568 * peer from lying about its identity. (Note that cmcred_groups[0]
569 * is the effective GID.)
570 */
571 struct cmsgcred {
572 pid_t cmcred_pid; /* PID of sending process */
573 uid_t cmcred_uid; /* real UID of sending process */
574 uid_t cmcred_euid; /* effective UID of sending process */
575 gid_t cmcred_gid; /* real GID of sending process */
576 short cmcred_ngroups; /* number or groups */
577 gid_t cmcred_groups[CMGROUP_MAX]; /* groups */
578 };
579 #endif
580 #endif /* !_POSIX_C_SOURCE */
581
582 /* given pointer to struct cmsghdr, return pointer to data */
583 #define CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
584 ALIGN(sizeof(struct cmsghdr)))
585
586 /* given pointer to struct cmsghdr, return pointer to next cmsghdr */
587 #define CMSG_NXTHDR(mhdr, cmsg) \
588 (((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len) + \
589 ALIGN(sizeof(struct cmsghdr)) > \
590 (unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) ? \
591 (struct cmsghdr *)0 /* NULL */ : \
592 (struct cmsghdr *)((unsigned char *)(cmsg) + ALIGN((cmsg)->cmsg_len)))
593
594 #define CMSG_FIRSTHDR(mhdr) ((struct cmsghdr *)(mhdr)->msg_control)
595
596 #ifndef _POSIX_C_SOURCE
597 /* RFC 2292 additions */
598 #define CMSG_SPACE(l) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(l))
599 #define CMSG_LEN(l) (ALIGN(sizeof(struct cmsghdr)) + (l))
600
601 #ifdef KERNEL
602 #define CMSG_ALIGN(n) ALIGN(n)
603 #endif
604 #endif /* !_POSIX_C_SOURCE */
605
606 /* "Socket"-level control message types: */
607 #define SCM_RIGHTS 0x01 /* access rights (array of int) */
608 #ifndef _POSIX_C_SOURCE
609 #define SCM_TIMESTAMP 0x02 /* timestamp (struct timeval) */
610 #define SCM_CREDS 0x03 /* process creds (struct cmsgcred) */
611
612 /*
613 * 4.3 compat sockaddr, move to compat file later
614 */
615 struct osockaddr {
616 __uint16_t sa_family; /* address family */
617 char sa_data[14]; /* up to 14 bytes of direct address */
618 };
619
620 /*
621 * 4.3-compat message header (move to compat file later).
622 */
623 // LP64todo - fix this. should msg_iov be * iovec_64?
624 struct omsghdr {
625 void *msg_name; /* optional address */
626 socklen_t msg_namelen; /* size of address */
627 struct iovec *msg_iov; /* scatter/gather array */
628 int msg_iovlen; /* # elements in msg_iov */
629 void *msg_accrights; /* access rights sent/rcvd */
630 int msg_accrightslen;
631 };
632 #endif /* !_POSIX_C_SOURCE */
633
634 /*
635 * howto arguments for shutdown(2), specified by Posix.1g.
636 */
637 #define SHUT_RD 0 /* shut down the reading side */
638 #define SHUT_WR 1 /* shut down the writing side */
639 #define SHUT_RDWR 2 /* shut down both sides */
640
641 #ifndef _POSIX_C_SOURCE
642 #if SENDFILE
643 /*
644 * sendfile(2) header/trailer struct
645 */
646 struct sf_hdtr {
647 struct iovec *headers; /* pointer to an array of header struct iovec's */
648 int hdr_cnt; /* number of header iovec's */
649 struct iovec *trailers; /* pointer to an array of trailer struct iovec's */
650 int trl_cnt; /* number of trailer iovec's */
651 };
652 #endif
653 #endif /* !_POSIX_C_SOURCE */
654
655 #ifndef KERNEL
656 __BEGIN_DECLS
657 int accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
658 __DARWIN_ALIAS(accept);
659 int bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
660 int connect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS( connect);
661 int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
662 __DARWIN_ALIAS(getpeername);
663 int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
664 __DARWIN_ALIAS(getsockname);
665 int getsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
666 int listen(int, int) __DARWIN_ALIAS(listen);
667 ssize_t recv(int, void *, size_t, int) __DARWIN_ALIAS(recv);
668 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr * __restrict,
669 socklen_t * __restrict) __DARWIN_ALIAS(recvfrom);
670 ssize_t recvmsg(int, struct msghdr *, int) __DARWIN_ALIAS(recvmsg);
671 ssize_t send(int, const void *, size_t, int) __DARWIN_ALIAS(send);
672 ssize_t sendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS(sendmsg);
673 ssize_t sendto(int, const void *, size_t,
674 int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(sendto);
675 int setsockopt(int, int, int, const void *, socklen_t);
676 int shutdown(int, int);
677 int socket(int, int, int);
678 int socketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair);
679 /*
680 * NOTIMP:
681 * int sockatmark(int s);
682 */
683
684 #ifndef _POSIX_C_SOURCE
685 #if SENDFILE
686 int sendfile(int, int, off_t, size_t, struct sf_hdtr *, off_t *, int);
687 #endif
688 void pfctlinput(int, struct sockaddr *);
689 #endif /* !_POSIX_C_SOURCE */
690 __END_DECLS
691
692 #endif /* !KERNEL */
693
694 #ifdef KERNEL
695 #include <sys/kpi_socket.h>
696 #endif
697
698 #endif /* !_SYS_SOCKET_H_ */