blob: 9e61bc7bb0e61f9e0fa2f71463cacedfa48d0cd5 [file] [log] [blame]
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -07001/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
gt145670e4f35db2006-03-23 19:03:11 -08005 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -07007 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
Anders Persson3e95bd42010-06-17 17:22:09 -070022 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
Bryan Cantrill8e935252014-10-04 09:02:58 +000023 * Copyright 2015, Joyent, Inc. All rights reserved.
Garrett D'Amore15f90b02022-07-03 19:05:50 -070024 * Copyright 2022 Garrett D'Amore
25 *
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070026 */
27
28/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29/* All Rights Reserved */
30
31/*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
Theo Schlossnagle187670a2013-04-12 15:07:53 -040041/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
42
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070043#ifndef _SYS_SOCKET_H
44#define _SYS_SOCKET_H
45
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070046#include <sys/types.h>
47#include <sys/uio.h>
48#include <sys/feature_tests.h>
49#include <sys/socket_impl.h>
50#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
51#ifndef _KERNEL
52#include <sys/netconfig.h>
53#endif /* !_KERNEL */
Gordon Ross33697082017-05-08 10:08:35 -040054/*
55 * Historically, netinet/in.h included sys/stream.h, which pulled in
56 * several things. The more troublesome namespace pollution was from
57 * sys/stream.h so that was removed. To avoid having to fix lots of
58 * programs, pull in a few things that are now (for better or worse)
59 * expected by programs that include sys/socket.h
60 */
61#include <sys/param.h>
62#include <sys/cred.h>
63#include <sys/poll.h>
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -070064#include <netinet/in.h>
65#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71#ifndef _SOCKLEN_T
72#define _SOCKLEN_T
73
74/*
75 * The socklen definitions are reproduced in netinet/in.h for the inet6_
76 * functions. Exposing all of sys/socket.h via netinet/in.h breaks existing
77 * applications and is not required by austin.
78 */
79#if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64)
80typedef size_t socklen_t;
81#else
82typedef uint32_t socklen_t;
83#endif /* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
84
85#if defined(_XPG4_2) || defined(_BOOT)
86typedef socklen_t *_RESTRICT_KYWD Psocklen_t;
87#else
88typedef void *_RESTRICT_KYWD Psocklen_t;
89#endif /* defined(_XPG4_2) || defined(_BOOT) */
90
91#endif /* _SOCKLEN_T */
92
93/*
94 * Definitions related to sockets: types, address families, options.
95 */
96#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
97#ifndef NC_TPI_CLTS
98#define NC_TPI_CLTS 1 /* must agree with netconfig.h */
99#define NC_TPI_COTS 2 /* must agree with netconfig.h */
100#define NC_TPI_COTS_ORD 3 /* must agree with netconfig.h */
101#define NC_TPI_RAW 4 /* must agree with netconfig.h */
102#endif /* !NC_TPI_CLTS */
103#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
104
105/*
106 * Types
107 */
108#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
109#define SOCK_STREAM NC_TPI_COTS /* stream socket */
110#define SOCK_DGRAM NC_TPI_CLTS /* datagram socket */
111#define SOCK_RAW NC_TPI_RAW /* raw-protocol interface */
112#else
113#define SOCK_STREAM 2 /* stream socket */
114#define SOCK_DGRAM 1 /* datagram socket */
115#define SOCK_RAW 4 /* raw-protocol interface */
116#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
117#define SOCK_RDM 5 /* reliably-delivered message */
118#define SOCK_SEQPACKET 6 /* sequenced packet stream */
Theo Schlossnagle187670a2013-04-12 15:07:53 -0400119#define SOCK_TYPE_MASK 0xffff /* type reside in these bits only */
120
121/*
Theo Schlossnagle5dbfd192013-04-11 04:50:36 +0000122 * Flags for socket() and accept4()
Theo Schlossnagle187670a2013-04-12 15:07:53 -0400123 */
Theo Schlossnagle5dbfd192013-04-11 04:50:36 +0000124#define SOCK_CLOEXEC 0x080000 /* like open(2) O_CLOEXEC for socket */
125#define SOCK_NONBLOCK 0x100000 /* like O_NONBLOCK */
126#define SOCK_NDELAY 0x200000 /* like O_NDELAY */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700127
128/*
129 * Option flags per-socket.
130 */
131#define SO_DEBUG 0x0001 /* turn on debugging info recording */
132#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
133#define SO_REUSEADDR 0x0004 /* allow local address reuse */
134#define SO_KEEPALIVE 0x0008 /* keep connections alive */
135#define SO_DONTROUTE 0x0010 /* just use interface addresses */
136#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
137#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
138#define SO_LINGER 0x0080 /* linger on close if data present */
139#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
140#define SO_DGRAM_ERRIND 0x0200 /* Application wants delayed error */
141#define SO_RECVUCRED 0x0400 /* Application wants ucred of sender */
142
Darren Reed0a0e9772009-09-24 07:28:12 -0700143/*
144 * Socket options are passed using a signed integer, but it is also rare
145 * for more than one to ever be passed at the same time with setsockopt
146 * and only one at a time can be retrieved with getsockopt.
147 *
148 * Since the lower numbers cannot be renumbered for compatibility reasons,
149 * it would seem that we need to start a new number space (0x40000000 -
150 * 0x7fffffff) for those that don't need to be stored as a bit flag
151 * somewhere. This limits the flag options to 30 but that seems to be
152 * plenty, anyway. 0x40000000 is reserved for future use.
153 */
154#define SO_ATTACH_FILTER 0x40000001
155#define SO_DETACH_FILTER 0x40000002
156
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700157#ifdef _KERNEL
158#define SO_SND_COPYAVOID 0x0800 /* Internal: use zero-copy */
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800159#define SO_SND_BUFINFO 0x1000 /* Internal: get buffer info */
160 /* when doing zero-copy */
161
162struct so_snd_bufinfo {
Garrett D'Amore15f90b02022-07-03 19:05:50 -0700163 ushort_t sbi_wroff; /* Write offset */
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800164 ssize_t sbi_maxblk; /* Max size of a single mblk */
165 ssize_t sbi_maxpsz; /* Max total size of a mblk chain */
166 ushort_t sbi_tail; /* Extra space available at the end */
167};
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700168#endif /* _KERNEL */
169
170/*
171 * N.B.: The following definition is present only for compatibility
172 * with release 3.0. It will disappear in later releases.
173 */
174#define SO_DONTLINGER (~SO_LINGER) /* ~SO_LINGER */
175
176/*
177 * Additional options, not kept in so_options.
178 */
179#define SO_SNDBUF 0x1001 /* send buffer size */
180#define SO_RCVBUF 0x1002 /* receive buffer size */
181#define SO_SNDLOWAT 0x1003 /* send low-water mark */
182#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
183#define SO_SNDTIMEO 0x1005 /* send timeout */
184#define SO_RCVTIMEO 0x1006 /* receive timeout */
185#define SO_ERROR 0x1007 /* get error status and clear */
186#define SO_TYPE 0x1008 /* get socket type */
187#define SO_PROTOTYPE 0x1009 /* get/set protocol type */
jpk45916cd2006-03-24 12:29:20 -0800188#define SO_ANON_MLP 0x100a /* create MLP on anonymous bind */
189#define SO_MAC_EXEMPT 0x100b /* allow dominated unlabeled peers */
kcpoon88cda072007-01-08 20:32:18 -0800190#define SO_DOMAIN 0x100c /* get socket domain */
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800191#define SO_RCVPSH 0x100d /* receive interval to push data */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700192
193/* "Socket"-level control message types: */
194#define SCM_RIGHTS 0x1010 /* access rights (array of int) */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700195#define SO_SECATTR 0x1011 /* socket's security attributes */
196#define SCM_UCRED 0x1012 /* sender's ucred */
gt145670e4f35db2006-03-23 19:03:11 -0800197#define SO_TIMESTAMP 0x1013 /* socket-level timestamp option */
198#define SCM_TIMESTAMP SO_TIMESTAMP /* socket control message timestamp */
sommerfe5d0bc3e2006-06-22 12:52:27 -0700199#define SO_ALLZONES 0x1014 /* bind in all zones */
kcpoonae347572006-07-24 23:50:09 -0700200#define SO_EXCLBIND 0x1015 /* exclusive binding */
Bill Sommerfeld5d3b8cb2009-11-02 15:39:20 -0800201#define SO_MAC_IMPLICIT 0x1016 /* hide mac labels on wire */
Cathy Zhou1cb875a2009-11-17 09:17:48 -0800202#define SO_VRRP 0x1017 /* VRRP control socket */
sommerfe5d0bc3e2006-06-22 12:52:27 -0700203
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700204#ifdef _KERNEL
205#define SO_SRCADDR 0x2001 /* Internal: AF_UNIX source address */
206#define SO_FILEP 0x2002 /* Internal: AF_UNIX file pointer */
207#define SO_UNIX_CLOSE 0x2003 /* Internal: AF_UNIX peer closed */
208#endif /* _KERNEL */
209
Anders Persson3e95bd42010-06-17 17:22:09 -0700210/*
211 * Socket filter options
212 */
213#define FIL_ATTACH 0x1 /* attach filter */
214#define FIL_DETACH 0x2 /* detach filter */
215#define FIL_LIST 0x3 /* list attached filters */
216
217#define FILNAME_MAX 32
218/*
219 * Structure returned by FIL_LIST
220 */
221struct fil_info {
222 int fi_flags; /* see below (FILF_*) */
223 int fi_pos; /* position (0 is bottom) */
224 char fi_name[FILNAME_MAX]; /* filter name */
225};
226
227#define FILF_PROG 0x1 /* programmatic attach */
228#define FILF_AUTO 0x2 /* automatic attach */
229#define FILF_BYPASS 0x4 /* filter is not active */
230
Gordon Rossb819cea2013-06-17 10:34:00 -0400231#if defined(_KERNEL) || defined(_FAKE_KERNEL)
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700232/*
233 * new socket open flags to identify socket and acceptor streams
234 */
235#define SO_ACCEPTOR 0x20000 /* acceptor socket */
236#define SO_SOCKSTR 0x40000 /* normal socket stream */
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800237#define SO_FALLBACK 0x80000 /* fallback to TPI socket */
238
239/*
240 * Flags for socket_create() and socket_newconn()
241 */
242#define SOCKET_SLEEP KM_SLEEP
243#define SOCKET_NOSLEEP KM_NOSLEEP
244
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700245#endif /* _KERNEL */
246
247/*
248 * Structure used for manipulating linger option.
249 */
250struct linger {
251 int l_onoff; /* option on/off */
252 int l_linger; /* linger time */
253};
254
255/*
meeme11c3f42009-01-06 20:16:25 -0500256 * Levels for (get/set)sockopt() that don't apply to a specific protocol.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700257 */
258#define SOL_SOCKET 0xffff /* options for socket level */
meeme11c3f42009-01-06 20:16:25 -0500259#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
260#define SOL_ROUTE 0xfffe /* options for routing socket level */
261#endif
Darren Reed0a0e9772009-09-24 07:28:12 -0700262#define SOL_PACKET 0xfffd /* options for packet level */
Anders Persson3e95bd42010-06-17 17:22:09 -0700263#define SOL_FILTER 0xfffc /* options for socket filter level */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700264
265/*
266 * Address families.
brendan10e6dad2008-06-13 19:06:55 -0700267 *
268 * Some of these constant names are copied for the DTrace IP provider in
269 * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
270 * in sync.
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700271 */
272#define AF_UNSPEC 0 /* unspecified */
273#define AF_UNIX 1 /* local to host (pipes, portals) */
Palle Lyckegaard406d6272008-10-29 22:28:53 -0400274#define AF_LOCAL AF_UNIX /* Synonym for AF_UNIX */
275#define AF_FILE AF_UNIX /* Synonym for AF_UNIX */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700276#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
277#define AF_IMPLINK 3 /* arpanet imp addresses */
278#define AF_PUP 4 /* pup protocols: e.g. BSP */
279#define AF_CHAOS 5 /* mit CHAOS protocols */
280#define AF_NS 6 /* XEROX NS protocols */
281#define AF_NBS 7 /* nbs protocols */
282#define AF_ECMA 8 /* european computer manufacturers */
283#define AF_DATAKIT 9 /* datakit protocols */
284#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
285#define AF_SNA 11 /* IBM SNA */
286#define AF_DECnet 12 /* DECnet */
287#define AF_DLI 13 /* Direct data link interface */
288#define AF_LAT 14 /* LAT */
289#define AF_HYLINK 15 /* NSC Hyperchannel */
290#define AF_APPLETALK 16 /* Apple Talk */
291#define AF_NIT 17 /* Network Interface Tap */
292#define AF_802 18 /* IEEE 802.2, also ISO 8802 */
293#define AF_OSI 19 /* umbrella for all families used */
294#define AF_X25 20 /* CCITT X.25 in particular */
295#define AF_OSINET 21 /* AFI = 47, IDI = 4 */
296#define AF_GOSIP 22 /* U.S. Government OSI */
297#define AF_IPX 23 /* Novell Internet Protocol */
298#define AF_ROUTE 24 /* Internal Routing Protocol */
299#define AF_LINK 25 /* Link-layer interface */
300#define AF_INET6 26 /* Internet Protocol, Version 6 */
301#define AF_KEY 27 /* Security Association DB socket */
Garrett D'Amore15f90b02022-07-03 19:05:50 -0700302#define AF_NCA 28 /* NCA socket (obsolete) */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700303#define AF_POLICY 29 /* Security Policy DB socket */
agirib86efd92006-12-20 21:01:52 -0800304#define AF_INET_OFFLOAD 30 /* Sun private; do not use */
Rishi Srivatsavai4eaa4712009-09-10 15:11:49 -0400305#define AF_TRILL 31 /* TRILL interface */
Darren Reed0a0e9772009-09-24 07:28:12 -0700306#define AF_PACKET 32 /* PF_PACKET Linux socket interface */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700307
Darren Reed0a0e9772009-09-24 07:28:12 -0700308#define AF_MAX 32
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700309
310/*
311 * Protocol families, same as address families for now.
312 */
313#define PF_UNSPEC AF_UNSPEC
314#define PF_UNIX AF_UNIX
Palle Lyckegaard406d6272008-10-29 22:28:53 -0400315#define PF_LOCAL PF_UNIX
316#define PF_FILE PF_UNIX
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700317#define PF_INET AF_INET
318#define PF_IMPLINK AF_IMPLINK
319#define PF_PUP AF_PUP
320#define PF_CHAOS AF_CHAOS
321#define PF_NS AF_NS
322#define PF_NBS AF_NBS
323#define PF_ECMA AF_ECMA
324#define PF_DATAKIT AF_DATAKIT
325#define PF_CCITT AF_CCITT
326#define PF_SNA AF_SNA
327#define PF_DECnet AF_DECnet
328#define PF_DLI AF_DLI
329#define PF_LAT AF_LAT
330#define PF_HYLINK AF_HYLINK
331#define PF_APPLETALK AF_APPLETALK
332#define PF_NIT AF_NIT
333#define PF_802 AF_802
334#define PF_OSI AF_OSI
335#define PF_X25 AF_X25
336#define PF_OSINET AF_OSINET
337#define PF_GOSIP AF_GOSIP
338#define PF_IPX AF_IPX
339#define PF_ROUTE AF_ROUTE
340#define PF_LINK AF_LINK
341#define PF_INET6 AF_INET6
342#define PF_KEY AF_KEY
343#define PF_NCA AF_NCA
344#define PF_POLICY AF_POLICY
agirib86efd92006-12-20 21:01:52 -0800345#define PF_INET_OFFLOAD AF_INET_OFFLOAD /* Sun private; do not use */
Rishi Srivatsavai4eaa4712009-09-10 15:11:49 -0400346#define PF_TRILL AF_TRILL
Darren Reed0a0e9772009-09-24 07:28:12 -0700347#define PF_PACKET AF_PACKET
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700348
349#define PF_MAX AF_MAX
350
351/*
352 * Maximum queue length specifiable by listen.
353 */
354#define SOMAXCONN 128
355
356/*
357 * Message header for recvmsg and sendmsg calls.
358 */
359struct msghdr {
360 void *msg_name; /* optional address */
361 socklen_t msg_namelen; /* size of address */
362 struct iovec *msg_iov; /* scatter/gather array */
363 int msg_iovlen; /* # elements in msg_iov */
364
365#if defined(_XPG4_2) || defined(_KERNEL)
366 void *msg_control; /* ancillary data */
367 socklen_t msg_controllen; /* ancillary data buffer len */
368 int msg_flags; /* flags on received message */
369#else
370 caddr_t msg_accrights; /* access rights sent/received */
371 int msg_accrightslen;
372#endif /* defined(_XPG4_2) || defined(_KERNEL) */
373};
374
Gordon Rossb819cea2013-06-17 10:34:00 -0400375#if defined(_KERNEL) || defined(_FAKE_KERNEL)
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700376
377/*
378 * N.B.: we assume that omsghdr and nmsghdr are isomorphic, with
379 * the sole exception that nmsghdr has the additional msg_flags
380 * field at the end.
381 */
382struct omsghdr {
383 void *msg_name; /* optional address */
384 socklen_t msg_namelen; /* size of address */
385 struct iovec *msg_iov; /* scatter/gather array */
386 int msg_iovlen; /* # elements in msg_iov */
387 caddr_t msg_accrights; /* access rights sent/received */
388 int msg_accrightslen;
389};
390
391#define nmsghdr msghdr
392
393#if defined(_SYSCALL32)
394
395struct omsghdr32 {
396 caddr32_t msg_name; /* optional address */
397 uint32_t msg_namelen; /* size of address */
398 caddr32_t msg_iov; /* scatter/gather array */
399 int32_t msg_iovlen; /* # elements in msg_iov */
400 caddr32_t msg_accrights; /* access rights sent/received */
401 uint32_t msg_accrightslen;
402};
403
404struct msghdr32 {
405 caddr32_t msg_name; /* optional address */
406 uint32_t msg_namelen; /* size of address */
407 caddr32_t msg_iov; /* scatter/gather array */
408 int32_t msg_iovlen; /* # elements in msg_iov */
409 caddr32_t msg_control; /* ancillary data */
410 uint32_t msg_controllen; /* ancillary data buffer len */
411 int32_t msg_flags; /* flags on received message */
412};
413
414#define nmsghdr32 msghdr32
415
416#endif /* _SYSCALL32 */
417#endif /* _KERNEL */
418
419#define MSG_OOB 0x1 /* process out-of-band data */
420#define MSG_PEEK 0x2 /* peek at incoming message */
421#define MSG_DONTROUTE 0x4 /* send without using routing tables */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700422#define MSG_EOR 0x8 /* Terminates a record */
423#define MSG_CTRUNC 0x10 /* Control data truncated */
424#define MSG_TRUNC 0x20 /* Normal data truncated */
425#define MSG_WAITALL 0x40 /* Wait for complete recv or error */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700426#define MSG_DONTWAIT 0x80 /* Don't block for this recv */
427#define MSG_NOTIFICATION 0x100 /* Notification, not data */
Sebastian Wiedenrothf67b7b82017-06-14 15:35:56 +0200428#define MSG_NOSIGNAL 0x200 /* Don't generate SIGPIPE */
429#define MSG_DUPCTRL 0x800 /* Save control message for use with */
430 /* with left over data */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700431#define MSG_XPG4_2 0x8000 /* Private: XPG4.2 flag */
432
Bryan Cantrill8e935252014-10-04 09:02:58 +0000433/* Obsolete but kept for compilation compatibility. Use IOV_MAX. */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700434#define MSG_MAXIOVLEN 16
435
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800436#ifdef _KERNEL
437
438/*
Gordon Rossf012ee02016-11-17 22:13:10 -0500439 * Internal-only MSG_... flags
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800440 */
Gordon Rossf012ee02016-11-17 22:13:10 -0500441
442#define MSG_SENDTO_NOXLATE 0x08000000 /* Skip so_ux_addr_xlate */
443
Yu Xiangning0f1702c2008-12-11 20:04:13 -0800444#define MSG_MBLK_QUICKRELE 0x10000000 /* free mblk chain */
445 /* in timely manner */
446#define MSG_USERSPACE 0x20000000 /* buffer from user space */
447
448#endif /* _KERNEL */
449
450
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700451/* Added for XPGv2 compliance */
452#define SHUT_RD 0
453#define SHUT_WR 1
454#define SHUT_RDWR 2
455
456struct cmsghdr {
457 socklen_t cmsg_len; /* data byte count, including hdr */
458 int cmsg_level; /* originating protocol */
459 int cmsg_type; /* protocol-specific type */
460};
461
462#if defined(_XPG4_2) || defined(_KERNEL)
463#if defined(__sparc)
464/* To maintain backward compatibility, alignment needs to be 8 on sparc. */
465#define _CMSG_HDR_ALIGNMENT 8
466#else
467/* for __i386 (and other future architectures) */
468#define _CMSG_HDR_ALIGNMENT 4
469#endif /* defined(__sparc) */
470#endif /* defined(_XPG4_2) || defined(_KERNEL) */
471
472#if defined(_XPG4_2)
473/*
474 * The cmsg headers (and macros dealing with them) were made available as
475 * part of UNIX95 and hence need to be protected with a _XPG4_2 define.
476 */
477#define _CMSG_DATA_ALIGNMENT (sizeof (int))
478#define _CMSG_HDR_ALIGN(x) (((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \
479 ~(_CMSG_HDR_ALIGNMENT - 1))
480#define _CMSG_DATA_ALIGN(x) (((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \
481 ~(_CMSG_DATA_ALIGNMENT - 1))
482#define CMSG_DATA(c) \
483 ((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1))
484
485#define CMSG_FIRSTHDR(m) \
486 (((m)->msg_controllen < sizeof (struct cmsghdr)) ? \
487 (struct cmsghdr *)0 : (struct cmsghdr *)((m)->msg_control))
488
489#define CMSG_NXTHDR(m, c) \
490 (((c) == 0) ? CMSG_FIRSTHDR(m) : \
491 ((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) + \
492 ((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) > \
493 (((uintptr_t)((struct msghdr *)(m))->msg_control) + \
494 ((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ? \
495 ((struct cmsghdr *)0) : \
496 ((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) + \
497 ((struct cmsghdr *)(c))->cmsg_len))))
498
499/* Amount of space + padding needed for a message of length l */
500#define CMSG_SPACE(l) \
501 ((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
502
503/* Value to be used in cmsg_len, does not include trailing padding */
504#define CMSG_LEN(l) \
505 ((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
506
507#endif /* _XPG4_2 */
508
509#ifdef _XPG4_2
510#ifdef __PRAGMA_REDEFINE_EXTNAME
511#pragma redefine_extname bind __xnet_bind
512#pragma redefine_extname connect __xnet_connect
513#pragma redefine_extname recvmsg __xnet_recvmsg
514#pragma redefine_extname sendmsg __xnet_sendmsg
515#pragma redefine_extname sendto __xnet_sendto
516#pragma redefine_extname socket __xnet_socket
517#pragma redefine_extname socketpair __xnet_socketpair
518#pragma redefine_extname getsockopt __xnet_getsockopt
519#else /* __PRAGMA_REDEFINE_EXTNAME */
520#define bind __xnet_bind
521#define connect __xnet_connect
522#define recvmsg __xnet_recvmsg
523#define sendmsg __xnet_sendmsg
524#define sendto __xnet_sendto
525#define socket __xnet_socket
526#define socketpair __xnet_socketpair
527#define getsockopt __xnet_getsockopt
528#endif /* __PRAGMA_REDEFINE_EXTNAME */
529
530#endif /* _XPG4_2 */
531
532#if defined(_XPG4_2) && !defined(_XPG5)
533#ifdef __PRAGMA_REDEFINE_EXTNAME
534#pragma redefine_extname listen __xnet_listen
535#else /* __PRAGMA_REDEFINE_EXTNAME */
536#define listen __xnet_listen
537#endif /* __PRAGMA_REDEFINE_EXTNAME */
538#endif /* (_XPG4_2) && !defined(_XPG5) */
539
540#if !defined(_KERNEL) || defined(_BOOT)
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700541extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
Theo Schlossnagle5dbfd192013-04-11 04:50:36 +0000542extern int accept4(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t, int);
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700543extern int bind(int, const struct sockaddr *, socklen_t);
544extern int connect(int, const struct sockaddr *, socklen_t);
545extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
546extern int getsockname(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
547extern int getsockopt(int, int, int, void *_RESTRICT_KYWD, Psocklen_t);
548extern int listen(int, int); /* XXX - fixme??? where do I go */
549extern int socketpair(int, int, int, int *);
550extern ssize_t recv(int, void *, size_t, int);
551extern ssize_t recvfrom(int, void *_RESTRICT_KYWD, size_t, int,
552 struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
553extern ssize_t recvmsg(int, struct msghdr *, int);
554extern ssize_t send(int, const void *, size_t, int);
555extern ssize_t sendmsg(int, const struct msghdr *, int);
556extern ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
557 socklen_t);
558extern int setsockopt(int, int, int, const void *, socklen_t);
559extern int shutdown(int, int);
560extern int socket(int, int, int);
561
562#if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
563extern int sockatmark(int);
564#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
stevel@tonic-gate7c478bd2005-06-14 00:00:00 -0700565#endif /* !defined(_KERNEL) || defined(_BOOT) */
566
567#ifdef __cplusplus
568}
569#endif
570
571#endif /* _SYS_SOCKET_H */