xref: /illumos-gate/usr/src/uts/common/sys/socket.h (revision 6abf6dcd9a6075af0f385cd9c9457091079152d5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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 /*
22  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2015, Joyent, Inc. All rights reserved.
24  * Copyright 2022 Garrett D'Amore
25  *
26  */
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 
41 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
42 
43 #ifndef	_SYS_SOCKET_H
44 #define	_SYS_SOCKET_H
45 
46 #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 */
54 /*
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>
64 #include <netinet/in.h>
65 #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
66 
67 #ifdef	__cplusplus
68 extern "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)
80 typedef	size_t		socklen_t;
81 #else
82 typedef	uint32_t	socklen_t;
83 #endif	/* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
84 
85 #if defined(_XPG4_2) || defined(_BOOT)
86 typedef	socklen_t	*_RESTRICT_KYWD Psocklen_t;
87 #else
88 typedef	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 */
119 #define	SOCK_TYPE_MASK	0xffff		/* type reside in these bits only */
120 
121 /*
122  * Flags for socket() and accept4()
123  */
124 #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 */
127 #define	SOCK_CLOFORK	0x400000	/* set FD_CLOFORK on the socket */
128 
129 /*
130  * Option flags per-socket.
131  */
132 #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
133 #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
134 #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
135 #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
136 #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
137 #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
138 #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
139 #define	SO_LINGER	0x0080		/* linger on close if data present */
140 #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
141 #define	SO_DGRAM_ERRIND	0x0200		/* Application wants delayed error */
142 #define	SO_RECVUCRED	0x0400		/* Application wants ucred of sender */
143 
144 /*
145  * Socket options are passed using a signed integer, but it is also rare
146  * for more than one to ever be passed at the same time with setsockopt
147  * and only one at a time can be retrieved with getsockopt.
148  *
149  * Since the lower numbers cannot be renumbered for compatibility reasons,
150  * it would seem that we need to start a new number space (0x40000000 -
151  * 0x7fffffff) for those that don't need to be stored as a bit flag
152  * somewhere. This limits the flag options to 30 but that seems to be
153  * plenty, anyway. 0x40000000 is reserved for future use.
154  */
155 #define	SO_ATTACH_FILTER	0x40000001
156 #define	SO_DETACH_FILTER	0x40000002
157 
158 #ifdef _KERNEL
159 #define	SO_SND_COPYAVOID 0x0800		/* Internal: use zero-copy */
160 #define	SO_SND_BUFINFO	0x1000		/* Internal: get buffer info */
161 					/* when doing zero-copy */
162 
163 struct so_snd_bufinfo {
164 	ushort_t	sbi_wroff;	/* Write offset */
165 	ssize_t		sbi_maxblk;	/* Max size of a single mblk */
166 	ssize_t		sbi_maxpsz;	/* Max total size of a mblk chain */
167 	ushort_t	sbi_tail;	/* Extra space available at the end */
168 };
169 #endif /* _KERNEL */
170 
171 /*
172  * N.B.: The following definition is present only for compatibility
173  * with release 3.0.  It will disappear in later releases.
174  */
175 #define	SO_DONTLINGER	(~SO_LINGER)	/* ~SO_LINGER */
176 
177 /*
178  * Additional options, not kept in so_options.
179  */
180 #define	SO_SNDBUF	0x1001		/* send buffer size */
181 #define	SO_RCVBUF	0x1002		/* receive buffer size */
182 #define	SO_SNDLOWAT	0x1003		/* send low-water mark */
183 #define	SO_RCVLOWAT	0x1004		/* receive low-water mark */
184 #define	SO_SNDTIMEO	0x1005		/* send timeout */
185 #define	SO_RCVTIMEO	0x1006		/* receive timeout */
186 #define	SO_ERROR	0x1007		/* get error status and clear */
187 #define	SO_TYPE		0x1008		/* get socket type */
188 #define	SO_PROTOTYPE	0x1009		/* get/set protocol type */
189 #define	SO_PROTOCOL	SO_PROTOTYPE	/* POSIX name */
190 #define	SO_ANON_MLP	0x100a		/* create MLP on anonymous bind */
191 #define	SO_MAC_EXEMPT	0x100b		/* allow dominated unlabeled peers */
192 #define	SO_DOMAIN	0x100c		/* get socket domain */
193 #define	SO_RCVPSH	0x100d		/* receive interval to push data */
194 
195 /* "Socket"-level control message types: */
196 #define	SCM_RIGHTS	0x1010		/* access rights (array of int) */
197 #define	SO_SECATTR	0x1011		/* socket's security attributes */
198 #define	SCM_UCRED	0x1012		/* sender's ucred */
199 #define	SO_TIMESTAMP	0x1013		/* socket-level timestamp option */
200 #define	SCM_TIMESTAMP	SO_TIMESTAMP	/* socket control message timestamp */
201 #define	SO_ALLZONES	0x1014		/* bind in all zones */
202 #define	SO_EXCLBIND	0x1015		/* exclusive binding */
203 #define	SO_MAC_IMPLICIT	0x1016		/* hide mac labels on wire */
204 #define	SO_VRRP		0x1017		/* VRRP control socket */
205 
206 #ifdef	_KERNEL
207 #define	SO_SRCADDR	0x2001		/* Internal: AF_UNIX source address */
208 #define	SO_FILEP	0x2002		/* Internal: AF_UNIX file pointer */
209 #define	SO_UNIX_CLOSE	0x2003		/* Internal: AF_UNIX peer closed */
210 #endif	/* _KERNEL */
211 
212 /*
213  * Socket filter options
214  */
215 #define	FIL_ATTACH	0x1		/* attach filter */
216 #define	FIL_DETACH	0x2		/* detach filter */
217 #define	FIL_LIST	0x3		/* list attached filters */
218 
219 #define	FILNAME_MAX	32
220 /*
221  * Structure returned by FIL_LIST
222  */
223 struct fil_info {
224 	int	fi_flags;		/* see below (FILF_*) */
225 	int	fi_pos;			/* position (0 is bottom) */
226 	char	fi_name[FILNAME_MAX];	/* filter name */
227 };
228 
229 #define	FILF_PROG	0x1		/* programmatic attach */
230 #define	FILF_AUTO	0x2		/* automatic attach */
231 #define	FILF_BYPASS	0x4		/* filter is not active */
232 
233 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
234 /*
235  * new socket open flags to identify socket and acceptor streams
236  */
237 #define	SO_ACCEPTOR	0x20000		/* acceptor socket */
238 #define	SO_SOCKSTR	0x40000		/* normal socket stream */
239 #define	SO_FALLBACK	0x80000		/* fallback to TPI socket */
240 
241 /*
242  * Flags for socket_create() and socket_newconn()
243  */
244 #define	SOCKET_SLEEP	KM_SLEEP
245 #define	SOCKET_NOSLEEP	KM_NOSLEEP
246 
247 #endif	/* _KERNEL */
248 
249 /*
250  * Structure used for manipulating linger option.
251  */
252 struct	linger {
253 	int	l_onoff;		/* option on/off */
254 	int	l_linger;		/* linger time */
255 };
256 
257 /*
258  * Levels for (get/set)sockopt() that don't apply to a specific protocol.
259  */
260 #define	SOL_SOCKET	0xffff		/* options for socket level */
261 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
262 #define	SOL_ROUTE	0xfffe		/* options for routing socket level */
263 #endif
264 #define	SOL_PACKET	0xfffd		/* options for packet level */
265 #define	SOL_FILTER	0xfffc		/* options for socket filter level */
266 
267 /*
268  * Address families.
269  *
270  * Some of these constant names are copied for the DTrace IP provider in
271  * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
272  * in sync.
273  */
274 #define	AF_UNSPEC	0		/* unspecified */
275 #define	AF_UNIX		1		/* local to host (pipes, portals) */
276 #define	AF_LOCAL	AF_UNIX		/* Synonym for AF_UNIX */
277 #define	AF_FILE		AF_UNIX		/* Synonym for AF_UNIX */
278 #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
279 #define	AF_IMPLINK	3		/* arpanet imp addresses */
280 #define	AF_PUP		4		/* pup protocols: e.g. BSP */
281 #define	AF_CHAOS	5		/* mit CHAOS protocols */
282 #define	AF_NS		6		/* XEROX NS protocols */
283 #define	AF_NBS		7		/* nbs protocols */
284 #define	AF_ECMA		8		/* european computer manufacturers */
285 #define	AF_DATAKIT	9		/* datakit protocols */
286 #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
287 #define	AF_SNA		11		/* IBM SNA */
288 #define	AF_DECnet	12		/* DECnet */
289 #define	AF_DLI		13		/* Direct data link interface */
290 #define	AF_LAT		14		/* LAT */
291 #define	AF_HYLINK	15		/* NSC Hyperchannel */
292 #define	AF_APPLETALK	16		/* Apple Talk */
293 #define	AF_NIT		17		/* Network Interface Tap */
294 #define	AF_802		18		/* IEEE 802.2, also ISO 8802 */
295 #define	AF_OSI		19		/* umbrella for all families used */
296 #define	AF_X25		20		/* CCITT X.25 in particular */
297 #define	AF_OSINET	21		/* AFI = 47, IDI = 4 */
298 #define	AF_GOSIP	22		/* U.S. Government OSI */
299 #define	AF_IPX		23		/* Novell Internet Protocol */
300 #define	AF_ROUTE	24		/* Internal Routing Protocol */
301 #define	AF_LINK		25		/* Link-layer interface */
302 #define	AF_INET6	26		/* Internet Protocol, Version 6 */
303 #define	AF_KEY		27		/* Security Association DB socket */
304 #define	AF_NCA		28		/* NCA socket (obsolete) */
305 #define	AF_POLICY	29		/* Security Policy DB socket */
306 #define	AF_INET_OFFLOAD	30		/* Sun private; do not use */
307 #define	AF_TRILL	31		/* TRILL interface */
308 #define	AF_PACKET	32		/* PF_PACKET Linux socket interface */
309 
310 #define	AF_MAX		32
311 
312 /*
313  * Protocol families, same as address families for now.
314  */
315 #define	PF_UNSPEC	AF_UNSPEC
316 #define	PF_UNIX		AF_UNIX
317 #define	PF_LOCAL	PF_UNIX
318 #define	PF_FILE		PF_UNIX
319 #define	PF_INET		AF_INET
320 #define	PF_IMPLINK	AF_IMPLINK
321 #define	PF_PUP		AF_PUP
322 #define	PF_CHAOS	AF_CHAOS
323 #define	PF_NS		AF_NS
324 #define	PF_NBS		AF_NBS
325 #define	PF_ECMA		AF_ECMA
326 #define	PF_DATAKIT	AF_DATAKIT
327 #define	PF_CCITT	AF_CCITT
328 #define	PF_SNA		AF_SNA
329 #define	PF_DECnet	AF_DECnet
330 #define	PF_DLI		AF_DLI
331 #define	PF_LAT		AF_LAT
332 #define	PF_HYLINK	AF_HYLINK
333 #define	PF_APPLETALK	AF_APPLETALK
334 #define	PF_NIT		AF_NIT
335 #define	PF_802		AF_802
336 #define	PF_OSI		AF_OSI
337 #define	PF_X25		AF_X25
338 #define	PF_OSINET	AF_OSINET
339 #define	PF_GOSIP	AF_GOSIP
340 #define	PF_IPX		AF_IPX
341 #define	PF_ROUTE	AF_ROUTE
342 #define	PF_LINK		AF_LINK
343 #define	PF_INET6	AF_INET6
344 #define	PF_KEY		AF_KEY
345 #define	PF_NCA		AF_NCA
346 #define	PF_POLICY	AF_POLICY
347 #define	PF_INET_OFFLOAD	AF_INET_OFFLOAD	/* Sun private; do not use */
348 #define	PF_TRILL	AF_TRILL
349 #define	PF_PACKET	AF_PACKET
350 
351 #define	PF_MAX		AF_MAX
352 
353 /*
354  * Maximum queue length specifiable by listen.
355  */
356 #define	SOMAXCONN	128
357 
358 /*
359  * Message header for recvmsg and sendmsg calls.
360  */
361 struct msghdr {
362 	void		*msg_name;		/* optional address */
363 	socklen_t	msg_namelen;		/* size of address */
364 	struct iovec	*msg_iov;		/* scatter/gather array */
365 	int		msg_iovlen;		/* # elements in msg_iov */
366 
367 #if defined(_XPG4_2) || defined(_KERNEL)
368 	void		*msg_control;		/* ancillary data */
369 	socklen_t	msg_controllen;		/* ancillary data buffer len */
370 	int		msg_flags;		/* flags on received message */
371 #else
372 	caddr_t		msg_accrights;	/* access rights sent/received */
373 	int		msg_accrightslen;
374 #endif	/* defined(_XPG4_2) || defined(_KERNEL) */
375 };
376 
377 #if	defined(_KERNEL) || defined(_FAKE_KERNEL)
378 
379 /*
380  *	N.B.:  we assume that omsghdr and nmsghdr are isomorphic, with
381  *	the sole exception that nmsghdr has the additional msg_flags
382  *	field at the end.
383  */
384 struct omsghdr {
385 	void		*msg_name;	/* optional address */
386 	socklen_t	msg_namelen;	/* size of address */
387 	struct	iovec	*msg_iov;	/* scatter/gather array */
388 	int		msg_iovlen;	/* # elements in msg_iov */
389 	caddr_t		msg_accrights;	/* access rights sent/received */
390 	int		msg_accrightslen;
391 };
392 
393 #define	nmsghdr		msghdr
394 
395 #if defined(_SYSCALL32)
396 
397 struct omsghdr32 {
398 	caddr32_t	msg_name;	/* optional address */
399 	uint32_t	msg_namelen;	/* size of address */
400 	caddr32_t	msg_iov;	/* scatter/gather array */
401 	int32_t		msg_iovlen;	/* # elements in msg_iov */
402 	caddr32_t	msg_accrights;	/* access rights sent/received */
403 	uint32_t	msg_accrightslen;
404 };
405 
406 struct msghdr32 {
407 	caddr32_t	msg_name;	/* optional address */
408 	uint32_t	msg_namelen;	/* size of address */
409 	caddr32_t	msg_iov;	/* scatter/gather array */
410 	int32_t		msg_iovlen;	/* # elements in msg_iov */
411 	caddr32_t	msg_control;	/* ancillary data */
412 	uint32_t	msg_controllen;	/* ancillary data buffer len */
413 	int32_t		msg_flags;	/* flags on received message */
414 };
415 
416 #define	nmsghdr32	msghdr32
417 
418 #endif	/* _SYSCALL32 */
419 #endif	/* _KERNEL */
420 
421 #define	MSG_OOB		0x1		/* process out-of-band data */
422 #define	MSG_PEEK	0x2		/* peek at incoming message */
423 #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
424 #define	MSG_EOR		0x8		/* Terminates a record */
425 #define	MSG_CTRUNC	0x10		/* Control data truncated */
426 #define	MSG_TRUNC	0x20		/* Normal data truncated */
427 #define	MSG_WAITALL	0x40		/* Wait for complete recv or error */
428 #define	MSG_DONTWAIT	0x80		/* Don't block for this recv */
429 #define	MSG_NOTIFICATION 0x100		/* Notification, not data */
430 #define	MSG_NOSIGNAL	0x200		/* Don't generate SIGPIPE */
431 #define	MSG_DUPCTRL	0x800		/* Save control message for use with */
432 					/* with left over data */
433 #define	MSG_CMSG_CLOEXEC	0x1000	/* FD_CLOEXEC w/ SCM_RIGHTS */
434 #define	MSG_CMSG_CLOFORK	0x2000	/* FD_CLOFORK w/ SCM_RIGHTS */
435 #define	MSG_XPG4_2	0x8000		/* Private: XPG4.2 flag */
436 
437 /* Obsolete but kept for compilation compatibility. Use IOV_MAX. */
438 #define	MSG_MAXIOVLEN	16
439 
440 #ifdef _KERNEL
441 
442 /*
443  * Internal-only MSG_... flags
444  */
445 
446 #define	MSG_SENDTO_NOXLATE	0x08000000	/* Skip so_ux_addr_xlate */
447 
448 #define	MSG_MBLK_QUICKRELE	0x10000000	/* free mblk chain */
449 						/* in timely manner */
450 #define	MSG_USERSPACE		0x20000000	/* buffer from user space */
451 
452 #endif /* _KERNEL */
453 
454 
455 /* Added for XPGv2 compliance */
456 #define	SHUT_RD		0
457 #define	SHUT_WR		1
458 #define	SHUT_RDWR	2
459 
460 struct cmsghdr {
461 	socklen_t	cmsg_len;	/* data byte count, including hdr */
462 	int		cmsg_level;	/* originating protocol */
463 	int		cmsg_type;	/* protocol-specific type */
464 };
465 
466 #if defined(_XPG4_2) || defined(_KERNEL)
467 #if defined(__sparc)
468 /* To maintain backward compatibility, alignment needs to be 8 on sparc. */
469 #define	_CMSG_HDR_ALIGNMENT	8
470 #else
471 /* for __i386 (and other future architectures) */
472 #define	_CMSG_HDR_ALIGNMENT	4
473 #endif	/* defined(__sparc) */
474 #endif	/* defined(_XPG4_2) || defined(_KERNEL) */
475 
476 #if defined(_XPG4_2)
477 /*
478  * The cmsg headers (and macros dealing with them) were made available as
479  * part of UNIX95 and hence need to be protected with a _XPG4_2 define.
480  */
481 #define	_CMSG_DATA_ALIGNMENT	(sizeof (int))
482 #define	_CMSG_HDR_ALIGN(x)	(((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \
483 				    ~(_CMSG_HDR_ALIGNMENT - 1))
484 #define	_CMSG_DATA_ALIGN(x)	(((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \
485 				    ~(_CMSG_DATA_ALIGNMENT - 1))
486 #define	CMSG_DATA(c)							\
487 	((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1))
488 
489 #define	CMSG_FIRSTHDR(m)						\
490 	(((m)->msg_controllen < sizeof (struct cmsghdr)) ?		\
491 	    (struct cmsghdr *)0 : (struct cmsghdr *)((m)->msg_control))
492 
493 #define	CMSG_NXTHDR(m, c)						\
494 	(((c) == 0) ? CMSG_FIRSTHDR(m) :			\
495 	((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) +			\
496 	((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) >	\
497 	(((uintptr_t)((struct msghdr *)(m))->msg_control) +		\
498 	((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ?		\
499 	((struct cmsghdr *)0) :						\
500 	((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) +		\
501 	    ((struct cmsghdr *)(c))->cmsg_len))))
502 
503 /* Amount of space + padding needed for a message of length l */
504 #define	CMSG_SPACE(l)							\
505 	((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
506 
507 /* Value to be used in cmsg_len, does not include trailing padding */
508 #define	CMSG_LEN(l)							\
509 	((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
510 
511 #endif	/* _XPG4_2 */
512 
513 #ifdef	_XPG4_2
514 #ifdef	__PRAGMA_REDEFINE_EXTNAME
515 #pragma redefine_extname bind __xnet_bind
516 #pragma redefine_extname connect __xnet_connect
517 #pragma redefine_extname recvmsg __xnet_recvmsg
518 #pragma redefine_extname sendmsg __xnet_sendmsg
519 #pragma redefine_extname sendto __xnet_sendto
520 #pragma redefine_extname socket __xnet_socket
521 #pragma redefine_extname socketpair __xnet_socketpair
522 #pragma redefine_extname getsockopt __xnet_getsockopt
523 #else	/* __PRAGMA_REDEFINE_EXTNAME */
524 #define	bind	__xnet_bind
525 #define	connect	__xnet_connect
526 #define	recvmsg	__xnet_recvmsg
527 #define	sendmsg	__xnet_sendmsg
528 #define	sendto	__xnet_sendto
529 #define	socket	__xnet_socket
530 #define	socketpair	__xnet_socketpair
531 #define	getsockopt	__xnet_getsockopt
532 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
533 
534 #endif	/* _XPG4_2 */
535 
536 #if defined(_XPG4_2) && !defined(_XPG5)
537 #ifdef	__PRAGMA_REDEFINE_EXTNAME
538 #pragma redefine_extname listen __xnet_listen
539 #else	/* __PRAGMA_REDEFINE_EXTNAME */
540 #define	listen	__xnet_listen
541 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
542 #endif /* (_XPG4_2) && !defined(_XPG5) */
543 
544 #if !defined(_KERNEL) || defined(_BOOT)
545 extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
546 extern int accept4(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t, int);
547 extern int bind(int, const struct sockaddr *, socklen_t);
548 extern int connect(int, const struct sockaddr *, socklen_t);
549 extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
550 extern int getsockname(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
551 extern int getsockopt(int, int, int, void *_RESTRICT_KYWD, Psocklen_t);
552 extern int listen(int, int);
553 extern int socketpair(int, int, int, int *);
554 extern ssize_t recv(int, void *, size_t, int);
555 extern ssize_t recvfrom(int, void *_RESTRICT_KYWD, size_t, int,
556 	struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
557 extern ssize_t recvmsg(int, struct msghdr *, int);
558 extern ssize_t send(int, const void *, size_t, int);
559 extern ssize_t sendmsg(int, const struct msghdr *, int);
560 extern ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
561 	socklen_t);
562 extern int setsockopt(int, int, int, const void *, socklen_t);
563 extern int shutdown(int, int);
564 extern int socket(int, int, int);
565 
566 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
567 extern int sockatmark(int);
568 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
569 #endif	/* !defined(_KERNEL) || defined(_BOOT) */
570 
571 #ifdef	__cplusplus
572 }
573 #endif
574 
575 #endif	/* _SYS_SOCKET_H */
576