Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Modules/i386/include/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.h8.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
87typedef __darwin_gid_tgid_t;
88#define _GID_T
89#endif
90
91#ifndef _OFF_T
92typedef __darwin_off_toff_t;
93#define _OFF_T
94#endif
95
96#ifndef _PID_T
97typedef __darwin_pid_tpid_t;
98#define _PID_T
99#endif
100
101#ifndef _SA_FAMILY_T
102#define _SA_FAMILY_T
103typedef __uint8_tsa_family_t;
104#endif
105
106#ifndef _SOCKLEN_T
107#define _SOCKLEN_T
108typedef__darwin_socklen_tsocklen_t;
109#endif
110
111/* XXX Not explicitly defined by POSIX, but function return types are */
112#ifndef _SIZE_T
113#define _SIZE_T
114typedef __darwin_size_tsize_t;
115#endif
116
117/* XXX Not explicitly defined by POSIX, but function return types are */
118#ifndef_SSIZE_T
119#define_SSIZE_T
120typedef__darwin_ssize_tssize_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
128struct iovec {
129void * iov_base;/* [XSI] Base address of I/O memory region */
130size_t iov_len;/* [XSI] Size of region iov_base points to */
131};
132#endif
133
134/*
135 * Types
136 */
137#defineSOCK_STREAM1/* stream socket */
138#defineSOCK_DGRAM2/* datagram socket */
139#defineSOCK_RAW3/* raw-protocol interface */
140#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
141#defineSOCK_RDM4/* reliably-delivered message */
142#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
143#defineSOCK_SEQPACKET5/* sequenced packet stream */
144
145/*
146 * Option flags per-socket.
147 */
148#defineSO_DEBUG0x0001/* turn on debugging info recording */
149#defineSO_ACCEPTCONN0x0002/* socket has had listen() */
150#defineSO_REUSEADDR0x0004/* allow local address reuse */
151#defineSO_KEEPALIVE0x0008/* keep connections alive */
152#defineSO_DONTROUTE0x0010/* just use interface addresses */
153#defineSO_BROADCAST0x0020/* permit sending of broadcast msgs */
154#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
155#defineSO_USELOOPBACK0x0040/* bypass hardware when possible */
156#define SO_LINGER0x0080 /* linger on close if data present (in ticks) */
157#else
158#define SO_LINGER0x1080 /* linger on close if data present (in seconds) */
159#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
160#defineSO_OOBINLINE0x0100/* leave received OOB data in line */
161#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
162#defineSO_REUSEPORT0x0200/* allow local address & port reuse */
163#defineSO_TIMESTAMP0x0400/* timestamp received dgram traffic */
164#ifndef __APPLE__
165#defineSO_ACCEPTFILTER0x1000/* there is an accept filter */
166#else
167#define SO_DONTTRUNC0x2000/* APPLE: Retain unread data */
168/* (ATOMIC proto) */
169#define SO_WANTMORE0x4000/* APPLE: Give hint when more data ready */
170#define SO_WANTOOBFLAG0x8000/* 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_SNDBUF0x1001/* send buffer size */
178#define SO_RCVBUF0x1002/* receive buffer size */
179#define SO_SNDLOWAT0x1003/* send low-water mark */
180#define SO_RCVLOWAT0x1004/* receive low-water mark */
181#define SO_SNDTIMEO0x1005/* send timeout */
182#define SO_RCVTIMEO0x1006/* receive timeout */
183#defineSO_ERROR0x1007/* get error status and clear */
184#defineSO_TYPE0x1008/* get socket type */
185#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
186/*efineSO_PRIVSTATE0x1009 get/deny privileged state */
187#ifdef __APPLE__
188#define SO_NREAD0x1020/* APPLE: get 1st-packet byte count */
189#define SO_NKE0x1021/* APPLE: Install socket-level NKE */
190#define SO_NOSIGPIPE0x1022/* APPLE: No SIGPIPE on EPIPE */
191#define SO_NOADDRERR0x1023/* APPLE: Returns EADDRNOTAVAIL when src is not available anymore */
192#define SO_NWRITE0x1024/* APPLE: Get number of bytes currently in send socket buffer */
193#define SO_REUSESHAREUID0x1025/* APPLE: Allow reuse of port/socket by different userids */
194#ifdef __APPLE_API_PRIVATE
195#define SO_NOTIFYCONFLICT0x1026/* APPLE: send notification if there is a bind on a port which is already in use */
196#defineSO_UPCALLCLOSEWAIT0x1027/* APPLE: block on close until an upcall returns */
197#endif
198#define SO_LINGER_SEC0x1080 /* linger on close if data present (in seconds) */
199#define SO_RESTRICTIONS0x1081/* APPLE: deny inbound/outbound/both/flag set */
200#define SO_RESTRICT_DENYIN0x00000001/* flag for SO_RESTRICTIONS - deny inbound */
201#define SO_RESTRICT_DENYOUT0x00000002/* flag for SO_RESTRICTIONS - deny outbound */
202#define SO_RESTRICT_DENYSET0x80000000/* flag for SO_RESTRICTIONS - deny has been set */
203#define SO_RANDOMPORT 0x1082 /* APPLE: request local port randomization */
204#define SO_NP_EXTENSIONS0x1083/* To turn off some POSIX behavior */
205#endif
206#defineSO_LABEL0x1010/* socket's MAC label */
207#defineSO_PEERLABEL0x1011/* socket's peer MAC label */
208#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
209
210/*
211 * Structure used for manipulating linger option.
212 */
213structlinger {
214intl_onoff;/* option on/off */
215intl_linger;/* linger time */
216};
217
218#ifndef __APPLE__
219structaccept_filter_arg {
220charaf_name[16];
221charaf_arg[256-16];
222};
223#endif
224
225#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
226#ifdef __APPLE__
227
228/*
229 * Structure to control non-portable Sockets extension to POSIX
230 */
231struct so_np_extensions {
232u_int32_tnpx_flags;
233u_int32_tnpx_mask;
234};
235
236#define SONPX_SETOPTSHUT0x000000001 /* flag for allowing setsockopt after shutdown */
237
238
239
240#endif
241#endif
242
243/*
244 * Level number for (get/set)sockopt() to apply to socket itself.
245 */
246#defineSOL_SOCKET0xffff/* options for socket level */
247
248
249/*
250 * Address families.
251 */
252#defineAF_UNSPEC0/* unspecified */
253#defineAF_UNIX1/* local to host (pipes) */
254#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
255#defineAF_LOCALAF_UNIX/* backward compatibility */
256#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
257#defineAF_INET2/* internetwork: UDP, TCP, etc. */
258#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
259#defineAF_IMPLINK3/* arpanet imp addresses */
260#defineAF_PUP4/* pup protocols: e.g. BSP */
261#defineAF_CHAOS5/* mit CHAOS protocols */
262#defineAF_NS6/* XEROX NS protocols */
263#defineAF_ISO7/* ISO protocols */
264#defineAF_OSIAF_ISO
265#defineAF_ECMA8/* European computer manufacturers */
266#defineAF_DATAKIT9/* datakit protocols */
267#defineAF_CCITT10/* CCITT protocols, X.25 etc */
268#defineAF_SNA11/* IBM SNA */
269#define AF_DECnet12/* DECnet */
270#define AF_DLI13/* DEC Direct data link interface */
271#define AF_LAT14/* LAT */
272#defineAF_HYLINK15/* NSC Hyperchannel */
273#defineAF_APPLETALK16/* Apple Talk */
274#defineAF_ROUTE17/* Internal Routing Protocol */
275#defineAF_LINK18/* Link layer interface */
276#definepseudo_AF_XTP19/* eXpress Transfer Protocol (no AF) */
277#defineAF_COIP20/* connection-oriented IP, aka ST II */
278#defineAF_CNT21/* Computer Network Technology */
279#define pseudo_AF_RTIP22/* Help Identify RTIP packets */
280#defineAF_IPX23/* Novell Internet Protocol */
281#defineAF_SIP24/* Simple Internet Protocol */
282#define pseudo_AF_PIP25/* Help Identify PIP packets */
283#ifdef __APPLE__
284/*define pseudo_AF_BLUE26 Identify packets for Blue Box - Not used */
285#define AF_NDRV27/* Network Driver 'raw' access */
286#endif
287#defineAF_ISDN28/* Integrated Services Digital Network*/
288#defineAF_E164AF_ISDN/* CCITT E.164 recommendation */
289#definepseudo_AF_KEY29/* Internal key-management function */
290#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
291#defineAF_INET630/* IPv6 */
292#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
293#defineAF_NATM31/* native ATM access */
294#ifdef __APPLE__
295#define AF_SYSTEM32/* Kernel event messages */
296#define AF_NETBIOS33/* NetBIOS */
297#define AF_PPP34/* PPP communication protocol */
298#else
299#defineAF_ATM30/* ATM */
300#endif
301#define pseudo_AF_HDRCMPLT 35/* Used by BPF to not rewrite headers
302 * in interface output routine
303 */
304#define AF_RESERVED_3636/* Reserved for internal usage */
305
306#ifndef __APPLE__
307#defineAF_NETGRAPH32/* Netgraph sockets */
308#endif
309#define AF_IEEE80211 37 /* IEEE 802.11 protocol */
310#defineAF_MAX38
311#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
312
313/*
314 * [XSI] Structure used by kernel to store most addresses.
315 */
316struct sockaddr {
317__uint8_tsa_len;/* total length */
318sa_family_tsa_family;/* [XSI] address family */
319charsa_data[14];/* [XSI] addr value (actually larger) */
320};
321
322#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
323#defineSOCK_MAXADDRLEN255/* longest possible addresses */
324
325/*
326 * Structure used by kernel to pass protocol
327 * information in raw sockets.
328 */
329struct sockproto {
330__uint16_tsp_family;/* address family */
331__uint16_tsp_protocol;/* protocol */
332};
333#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE)*/
334
335/*
336 * RFC 2553: protocol-independent placeholder for socket addresses
337 */
338#define_SS_MAXSIZE128
339#define_SS_ALIGNSIZE(sizeof(__int64_t))
340#define_SS_PAD1SIZE\
341(_SS_ALIGNSIZE - sizeof(__uint8_t) - sizeof(sa_family_t))
342#define_SS_PAD2SIZE\
343(_SS_MAXSIZE - sizeof(__uint8_t) - sizeof(sa_family_t) - \
344_SS_PAD1SIZE - _SS_ALIGNSIZE)
345
346/*
347 * [XSI] sockaddr_storage
348 */
349struct sockaddr_storage {
350__uint8_tss_len;/* address length */
351sa_family_tss_family;/* [XSI] address family */
352char__ss_pad1[_SS_PAD1SIZE];
353__int64_t__ss_align;/* force structure storage alignment */
354char__ss_pad2[_SS_PAD2SIZE];
355};
356
357/*
358 * Protocol families, same as address families for now.
359 */
360#definePF_UNSPECAF_UNSPEC
361#definePF_LOCALAF_LOCAL
362#definePF_UNIXPF_LOCAL/* backward compatibility */
363#definePF_INETAF_INET
364#definePF_IMPLINKAF_IMPLINK
365#definePF_PUPAF_PUP
366#definePF_CHAOSAF_CHAOS
367#definePF_NSAF_NS
368#definePF_ISOAF_ISO
369#definePF_OSIAF_ISO
370#definePF_ECMAAF_ECMA
371#definePF_DATAKITAF_DATAKIT
372#definePF_CCITTAF_CCITT
373#definePF_SNAAF_SNA
374#define PF_DECnetAF_DECnet
375#define PF_DLIAF_DLI
376#define PF_LATAF_LAT
377#definePF_HYLINKAF_HYLINK
378#definePF_APPLETALKAF_APPLETALK
379#definePF_ROUTEAF_ROUTE
380#definePF_LINKAF_LINK
381#definePF_XTPpseudo_AF_XTP/* really just proto family, no AF */
382#definePF_COIPAF_COIP
383#definePF_CNTAF_CNT
384#definePF_SIPAF_SIP
385#definePF_IPXAF_IPX/* same format as AF_NS */
386#define PF_RTIPpseudo_AF_RTIP/* same format as AF_INET */
387#define PF_PIPpseudo_AF_PIP
388#ifdef __APPLE__
389#define PF_NDRVAF_NDRV
390#endif
391#definePF_ISDNAF_ISDN
392#definePF_KEYpseudo_AF_KEY
393#definePF_INET6AF_INET6
394#definePF_NATMAF_NATM
395#ifdef __APPLE__
396#define PF_SYSTEMAF_SYSTEM
397#define PF_NETBIOSAF_NETBIOS
398#define PF_PPPAF_PPP
399#define PF_RESERVED_36 AF_RESERVED_36
400
401#else
402#definePF_ATMAF_ATM
403#definePF_NETGRAPHAF_NETGRAPH
404#endif
405
406#definePF_MAXAF_MAX
407
408/*
409 * These do not have socket-layer support:
410 */
411#definePF_VLAN((uint32_t)0x766c616e)/* 'vlan' */
412#define PF_BOND((uint32_t)0x626f6e64)/* 'bond' */
413
414/*
415 * Definitions for network related sysctl, CTL_NET.
416 *
417 * Second level is protocol family.
418 * Third level is protocol number.
419 *
420 * Further levels are defined by the individual families below.
421 */
422#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
423#define NET_MAXIDAF_MAX
424#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
425
426
427#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
428/*
429 * PF_ROUTE - Routing table
430 *
431 * Three additional levels are defined:
432 *Fourth: address family, 0 is wildcard
433 *Fifth: type of info, defined below
434 *Sixth: flag(s) to mask with for NET_RT_FLAGS
435 */
436#define NET_RT_DUMP1/* dump; may limit to a.f. */
437#define NET_RT_FLAGS2/* by flags, e.g. RESOLVING */
438#define NET_RT_IFLIST3/* survey interface list */
439#define NET_RT_STAT4/* routing statistics */
440#define NET_RT_TRASH5/* routes not in table but not freed */
441#define NET_RT_IFLIST26/* interface list with addresses */
442#define NET_RT_DUMP2 7 /* dump; may limit to a.f. */
443#defineNET_RT_MAXID8
444#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
445
446
447/*
448 * Maximum queue length specifiable by listen.
449 */
450#defineSOMAXCONN128
451
452/*
453 * [XSI] Message header for recvmsg and sendmsg calls.
454 * Used value-result for recvmsg, value only for sendmsg.
455 */
456struct msghdr {
457void*msg_name;/* [XSI] optional address */
458socklen_tmsg_namelen;/* [XSI] size of address */
459structiovec *msg_iov;/* [XSI] scatter/gather array */
460intmsg_iovlen;/* [XSI] # elements in msg_iov */
461void*msg_control;/* [XSI] ancillary data, see below */
462socklen_tmsg_controllen;/* [XSI] ancillary data buffer len */
463intmsg_flags;/* [XSI] flags on received message */
464};
465
466
467#defineMSG_OOB0x1/* process out-of-band data */
468#defineMSG_PEEK0x2/* peek at incoming message */
469#defineMSG_DONTROUTE0x4/* send without using routing tables */
470#defineMSG_EOR0x8/* data completes record */
471#defineMSG_TRUNC0x10/* data discarded before delivery */
472#defineMSG_CTRUNC0x20/* control data lost before delivery */
473#defineMSG_WAITALL0x40/* wait for full request or error */
474#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
475#defineMSG_DONTWAIT0x80/* this message should be nonblocking */
476#defineMSG_EOF0x100/* data completes connection */
477#ifdef __APPLE__
478#define MSG_WAITSTREAM 0x200 /* wait up to full request.. may return partial */
479#define MSG_FLUSH0x400/* Start of 'hold' seq; dump so_temp */
480#define MSG_HOLD0x800/* Hold frag in so_temp */
481#define MSG_SEND0x1000/* Send the packet in so_temp */
482#define MSG_HAVEMORE0x2000/* Data ready to be read */
483#define MSG_RCVMORE0x4000/* Data remains in current pkt */
484#endif
485#define MSG_NEEDSA0x10000/* Fail receive if socket address cannot be allocated */
486#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
487
488/*
489 * Header for ancillary data objects in msg_control buffer.
490 * Used for additional information with/about a datagram
491 * not expressible by flags. The format is a sequence
492 * of message elements headed by cmsghdr structures.
493 */
494struct cmsghdr {
495socklen_tcmsg_len;/* [XSI] data byte count, including hdr */
496intcmsg_level;/* [XSI] originating protocol */
497intcmsg_type;/* [XSI] protocol-specific type */
498/* followed byunsigned char cmsg_data[]; */
499};
500
501#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
502#ifndef __APPLE__
503/*
504 * While we may have more groups than this, the cmsgcred struct must
505 * be able to fit in an mbuf, and NGROUPS_MAX is too large to allow
506 * this.
507*/
508#define CMGROUP_MAX 16
509
510/*
511 * Credentials structure, used to verify the identity of a peer
512 * process that has sent us a message. This is allocated by the
513 * peer process but filled in by the kernel. This prevents the
514 * peer from lying about its identity. (Note that cmcred_groups[0]
515 * is the effective GID.)
516 */
517struct cmsgcred {
518pid_tcmcred_pid;/* PID of sending process */
519uid_tcmcred_uid;/* real UID of sending process */
520uid_tcmcred_euid;/* effective UID of sending process */
521gid_tcmcred_gid;/* real GID of sending process */
522shortcmcred_ngroups;/* number or groups */
523gid_tcmcred_groups[CMGROUP_MAX];/* groups */
524};
525#endif
526#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
527
528/* given pointer to struct cmsghdr, return pointer to data */
529#defineCMSG_DATA(cmsg)((unsigned char *)(cmsg) + \
530 __DARWIN_ALIGN32(sizeof(struct cmsghdr)))
531
532/*
533 * RFC 2292 requires to check msg_controllen, in case that the kernel returns
534 * an empty list for some reasons.
535 */
536#define CMSG_FIRSTHDR(mhdr) \
537 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
538 (struct cmsghdr *)(mhdr)->msg_control : \
539 (struct cmsghdr *)0L)
540
541
542/*
543 * Given pointer to struct cmsghdr, return pointer to next cmsghdr
544 * RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
545 */
546#defineCMSG_NXTHDR(mhdr, cmsg)\
547((char *)(cmsg) == (char *)0L ? CMSG_FIRSTHDR(mhdr) :\
548 ((((unsigned char *)(cmsg) +\
549 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len) +\
550 __DARWIN_ALIGN32(sizeof(struct cmsghdr))) >\
551 ((unsigned char *)(mhdr)->msg_control +\
552 (mhdr)->msg_controllen)) ?\
553 (struct cmsghdr *)0L /* NULL */ :\
554 (struct cmsghdr *)((unsigned char *)(cmsg) +\
555 __DARWIN_ALIGN32((__uint32_t)(cmsg)->cmsg_len))))
556
557#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
558/* RFC 2292 additions */
559#defineCMSG_SPACE(l)(__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l))
560#defineCMSG_LEN(l)(__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + (l))
561
562#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
563
564/* "Socket"-level control message types: */
565#defineSCM_RIGHTS0x01/* access rights (array of int) */
566#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
567#defineSCM_TIMESTAMP0x02/* timestamp (struct timeval) */
568#defineSCM_CREDS0x03/* process creds (struct cmsgcred) */
569
570#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
571
572/*
573 * howto arguments for shutdown(2), specified by Posix.1g.
574 */
575#defineSHUT_RD0/* shut down the reading side */
576#defineSHUT_WR1/* shut down the writing side */
577#defineSHUT_RDWR2/* shut down both sides */
578
579#if !defined(_POSIX_C_SOURCE)
580/*
581 * sendfile(2) header/trailer struct
582 */
583struct sf_hdtr {
584struct iovec *headers;/* pointer to an array of header struct iovec's */
585int hdr_cnt;/* number of header iovec's */
586struct iovec *trailers;/* pointer to an array of trailer struct iovec's */
587int trl_cnt;/* number of trailer iovec's */
588};
589
590
591#endif/* !_POSIX_C_SOURCE */
592
593__BEGIN_DECLS
594intaccept(int, struct sockaddr * __restrict, socklen_t * __restrict)
595__DARWIN_ALIAS_C(accept);
596intbind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
597intconnect(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C( connect);
598intgetpeername(int, struct sockaddr * __restrict, socklen_t * __restrict)
599__DARWIN_ALIAS(getpeername);
600intgetsockname(int, struct sockaddr * __restrict, socklen_t * __restrict)
601__DARWIN_ALIAS(getsockname);
602intgetsockopt(int, int, int, void * __restrict, socklen_t * __restrict);
603intlisten(int, int) __DARWIN_ALIAS(listen);
604ssize_trecv(int, void *, size_t, int) __DARWIN_ALIAS_C(recv);
605ssize_trecvfrom(int, void *, size_t, int, struct sockaddr * __restrict,
606socklen_t * __restrict) __DARWIN_ALIAS_C(recvfrom);
607ssize_trecvmsg(int, struct msghdr *, int) __DARWIN_ALIAS_C(recvmsg);
608ssize_tsend(int, const void *, size_t, int) __DARWIN_ALIAS_C(send);
609ssize_tsendmsg(int, const struct msghdr *, int) __DARWIN_ALIAS_C(sendmsg);
610ssize_tsendto(int, const void *, size_t,
611int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS_C(sendto);
612intsetsockopt(int, int, int, const void *, socklen_t);
613intshutdown(int, int);
614intsockatmark(int);
615intsocket(int, int, int);
616intsocketpair(int, int, int, int *) __DARWIN_ALIAS(socketpair);
617
618#if !defined(_POSIX_C_SOURCE)
619intsendfile(int, int, off_t, off_t *, struct sf_hdtr *, int);
620#endif/* !_POSIX_C_SOURCE */
621
622#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
623voidpfctlinput(int, struct sockaddr *);
624#endif/* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
625__END_DECLS
626
627
628
629#endif /* !_SYS_SOCKET_H_ */
630

Archive Download this file

Revision: 1621