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