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