xref: /illumos-gate/usr/src/uts/common/sys/socket.h (revision e4f35dba)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*e4f35dbaSgt  * Common Development and Distribution License (the "License").
6*e4f35dbaSgt  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*e4f35dbaSgt  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifndef	_SYS_SOCKET_H
407c478bd9Sstevel@tonic-gate #define	_SYS_SOCKET_H
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <sys/types.h>
457c478bd9Sstevel@tonic-gate #include <sys/uio.h>
467c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
477c478bd9Sstevel@tonic-gate #include <sys/socket_impl.h>
487c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
497c478bd9Sstevel@tonic-gate #ifndef	_KERNEL
507c478bd9Sstevel@tonic-gate #include <sys/netconfig.h>
517c478bd9Sstevel@tonic-gate #endif	/* !_KERNEL */
527c478bd9Sstevel@tonic-gate #include <netinet/in.h>
537c478bd9Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
567c478bd9Sstevel@tonic-gate extern "C" {
577c478bd9Sstevel@tonic-gate #endif
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #ifndef	_SOCKLEN_T
607c478bd9Sstevel@tonic-gate #define	_SOCKLEN_T
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * The socklen definitions are reproduced in netinet/in.h for the inet6_
647c478bd9Sstevel@tonic-gate  * functions.  Exposing all of sys/socket.h via netinet/in.h breaks existing
657c478bd9Sstevel@tonic-gate  * applications and is not required by austin.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64)
687c478bd9Sstevel@tonic-gate typedef	size_t		socklen_t;
697c478bd9Sstevel@tonic-gate #else
707c478bd9Sstevel@tonic-gate typedef	uint32_t	socklen_t;
717c478bd9Sstevel@tonic-gate #endif	/* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_BOOT)
747c478bd9Sstevel@tonic-gate typedef	socklen_t	*_RESTRICT_KYWD Psocklen_t;
757c478bd9Sstevel@tonic-gate #else
767c478bd9Sstevel@tonic-gate typedef	void		*_RESTRICT_KYWD Psocklen_t;
777c478bd9Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_BOOT) */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #endif	/* _SOCKLEN_T */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Definitions related to sockets: types, address families, options.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
857c478bd9Sstevel@tonic-gate #ifndef	NC_TPI_CLTS
867c478bd9Sstevel@tonic-gate #define	NC_TPI_CLTS	1		/* must agree with netconfig.h */
877c478bd9Sstevel@tonic-gate #define	NC_TPI_COTS	2		/* must agree with netconfig.h */
887c478bd9Sstevel@tonic-gate #define	NC_TPI_COTS_ORD	3		/* must agree with netconfig.h */
897c478bd9Sstevel@tonic-gate #define	NC_TPI_RAW	4		/* must agree with netconfig.h */
907c478bd9Sstevel@tonic-gate #endif	/* !NC_TPI_CLTS */
917c478bd9Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Types
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
977c478bd9Sstevel@tonic-gate #define	SOCK_STREAM	NC_TPI_COTS	/* stream socket */
987c478bd9Sstevel@tonic-gate #define	SOCK_DGRAM	NC_TPI_CLTS	/* datagram socket */
997c478bd9Sstevel@tonic-gate #define	SOCK_RAW	NC_TPI_RAW	/* raw-protocol interface */
1007c478bd9Sstevel@tonic-gate #else
1017c478bd9Sstevel@tonic-gate #define	SOCK_STREAM	2		/* stream socket */
1027c478bd9Sstevel@tonic-gate #define	SOCK_DGRAM	1		/* datagram socket */
1037c478bd9Sstevel@tonic-gate #define	SOCK_RAW	4		/* raw-protocol interface */
1047c478bd9Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1057c478bd9Sstevel@tonic-gate #define	SOCK_RDM	5		/* reliably-delivered message */
1067c478bd9Sstevel@tonic-gate #define	SOCK_SEQPACKET	6		/* sequenced packet stream */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * Option flags per-socket.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
1127c478bd9Sstevel@tonic-gate #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
1137c478bd9Sstevel@tonic-gate #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
1147c478bd9Sstevel@tonic-gate #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
1157c478bd9Sstevel@tonic-gate #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
1167c478bd9Sstevel@tonic-gate #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
1177c478bd9Sstevel@tonic-gate #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
1187c478bd9Sstevel@tonic-gate #define	SO_LINGER	0x0080		/* linger on close if data present */
1197c478bd9Sstevel@tonic-gate #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
1207c478bd9Sstevel@tonic-gate #define	SO_DGRAM_ERRIND	0x0200		/* Application wants delayed error */
1217c478bd9Sstevel@tonic-gate #define	SO_RECVUCRED	0x0400		/* Application wants ucred of sender */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1247c478bd9Sstevel@tonic-gate #define	SO_SND_COPYAVOID 0x0800		/* Internal: use zero-copy */
1257c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * N.B.: The following definition is present only for compatibility
1297c478bd9Sstevel@tonic-gate  * with release 3.0.  It will disappear in later releases.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	SO_DONTLINGER	(~SO_LINGER)	/* ~SO_LINGER */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Additional options, not kept in so_options.
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate #define	SO_SNDBUF	0x1001		/* send buffer size */
1377c478bd9Sstevel@tonic-gate #define	SO_RCVBUF	0x1002		/* receive buffer size */
1387c478bd9Sstevel@tonic-gate #define	SO_SNDLOWAT	0x1003		/* send low-water mark */
1397c478bd9Sstevel@tonic-gate #define	SO_RCVLOWAT	0x1004		/* receive low-water mark */
1407c478bd9Sstevel@tonic-gate #define	SO_SNDTIMEO	0x1005		/* send timeout */
1417c478bd9Sstevel@tonic-gate #define	SO_RCVTIMEO	0x1006		/* receive timeout */
1427c478bd9Sstevel@tonic-gate #define	SO_ERROR	0x1007		/* get error status and clear */
1437c478bd9Sstevel@tonic-gate #define	SO_TYPE		0x1008		/* get socket type */
1447c478bd9Sstevel@tonic-gate #define	SO_PROTOTYPE	0x1009		/* get/set protocol type */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /* "Socket"-level control message types: */
1477c478bd9Sstevel@tonic-gate #define	SCM_RIGHTS	0x1010		/* access rights (array of int) */
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #define	SO_SECATTR	0x1011		/* socket's security attributes */
1507c478bd9Sstevel@tonic-gate #define	SCM_UCRED	0x1012		/* sender's ucred */
151*e4f35dbaSgt #define	SO_TIMESTAMP	0x1013		/* socket-level timestamp option */
152*e4f35dbaSgt #define	SCM_TIMESTAMP	SO_TIMESTAMP	/* socket control message timestamp */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1557c478bd9Sstevel@tonic-gate #define	SO_SRCADDR	0x2001		/* Internal: AF_UNIX source address */
1567c478bd9Sstevel@tonic-gate #define	SO_FILEP	0x2002		/* Internal: AF_UNIX file pointer */
1577c478bd9Sstevel@tonic-gate #define	SO_UNIX_CLOSE	0x2003		/* Internal: AF_UNIX peer closed */
1587c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * new socket open flags to identify socket and acceptor streams
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate #define	SO_ACCEPTOR	0x20000		/* acceptor socket */
1657c478bd9Sstevel@tonic-gate #define	SO_SOCKSTR	0x40000		/* normal socket stream */
1667c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Structure used for manipulating linger option.
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate struct	linger {
1727c478bd9Sstevel@tonic-gate 	int	l_onoff;		/* option on/off */
1737c478bd9Sstevel@tonic-gate 	int	l_linger;		/* linger time */
1747c478bd9Sstevel@tonic-gate };
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * Level number for (get/set)sockopt() to apply to socket itself.
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate #define	SOL_SOCKET	0xffff		/* options for socket level */
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * Address families.
1837c478bd9Sstevel@tonic-gate  */
1847c478bd9Sstevel@tonic-gate #define	AF_UNSPEC	0		/* unspecified */
1857c478bd9Sstevel@tonic-gate #define	AF_UNIX		1		/* local to host (pipes, portals) */
1867c478bd9Sstevel@tonic-gate #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
1877c478bd9Sstevel@tonic-gate #define	AF_IMPLINK	3		/* arpanet imp addresses */
1887c478bd9Sstevel@tonic-gate #define	AF_PUP		4		/* pup protocols: e.g. BSP */
1897c478bd9Sstevel@tonic-gate #define	AF_CHAOS	5		/* mit CHAOS protocols */
1907c478bd9Sstevel@tonic-gate #define	AF_NS		6		/* XEROX NS protocols */
1917c478bd9Sstevel@tonic-gate #define	AF_NBS		7		/* nbs protocols */
1927c478bd9Sstevel@tonic-gate #define	AF_ECMA		8		/* european computer manufacturers */
1937c478bd9Sstevel@tonic-gate #define	AF_DATAKIT	9		/* datakit protocols */
1947c478bd9Sstevel@tonic-gate #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
1957c478bd9Sstevel@tonic-gate #define	AF_SNA		11		/* IBM SNA */
1967c478bd9Sstevel@tonic-gate #define	AF_DECnet	12		/* DECnet */
1977c478bd9Sstevel@tonic-gate #define	AF_DLI		13		/* Direct data link interface */
1987c478bd9Sstevel@tonic-gate #define	AF_LAT		14		/* LAT */
1997c478bd9Sstevel@tonic-gate #define	AF_HYLINK	15		/* NSC Hyperchannel */
2007c478bd9Sstevel@tonic-gate #define	AF_APPLETALK	16		/* Apple Talk */
2017c478bd9Sstevel@tonic-gate #define	AF_NIT		17		/* Network Interface Tap */
2027c478bd9Sstevel@tonic-gate #define	AF_802		18		/* IEEE 802.2, also ISO 8802 */
2037c478bd9Sstevel@tonic-gate #define	AF_OSI		19		/* umbrella for all families used */
2047c478bd9Sstevel@tonic-gate #define	AF_X25		20		/* CCITT X.25 in particular */
2057c478bd9Sstevel@tonic-gate #define	AF_OSINET	21		/* AFI = 47, IDI = 4 */
2067c478bd9Sstevel@tonic-gate #define	AF_GOSIP	22		/* U.S. Government OSI */
2077c478bd9Sstevel@tonic-gate #define	AF_IPX		23		/* Novell Internet Protocol */
2087c478bd9Sstevel@tonic-gate #define	AF_ROUTE	24		/* Internal Routing Protocol */
2097c478bd9Sstevel@tonic-gate #define	AF_LINK		25		/* Link-layer interface */
2107c478bd9Sstevel@tonic-gate #define	AF_INET6	26		/* Internet Protocol, Version 6 */
2117c478bd9Sstevel@tonic-gate #define	AF_KEY		27		/* Security Association DB socket */
2127c478bd9Sstevel@tonic-gate #define	AF_NCA		28		/* NCA socket */
2137c478bd9Sstevel@tonic-gate #define	AF_POLICY	29		/* Security Policy DB socket */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate #define	AF_MAX		29
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * Protocol families, same as address families for now.
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate #define	PF_UNSPEC	AF_UNSPEC
2217c478bd9Sstevel@tonic-gate #define	PF_UNIX		AF_UNIX
2227c478bd9Sstevel@tonic-gate #define	PF_INET		AF_INET
2237c478bd9Sstevel@tonic-gate #define	PF_IMPLINK	AF_IMPLINK
2247c478bd9Sstevel@tonic-gate #define	PF_PUP		AF_PUP
2257c478bd9Sstevel@tonic-gate #define	PF_CHAOS	AF_CHAOS
2267c478bd9Sstevel@tonic-gate #define	PF_NS		AF_NS
2277c478bd9Sstevel@tonic-gate #define	PF_NBS		AF_NBS
2287c478bd9Sstevel@tonic-gate #define	PF_ECMA		AF_ECMA
2297c478bd9Sstevel@tonic-gate #define	PF_DATAKIT	AF_DATAKIT
2307c478bd9Sstevel@tonic-gate #define	PF_CCITT	AF_CCITT
2317c478bd9Sstevel@tonic-gate #define	PF_SNA		AF_SNA
2327c478bd9Sstevel@tonic-gate #define	PF_DECnet	AF_DECnet
2337c478bd9Sstevel@tonic-gate #define	PF_DLI		AF_DLI
2347c478bd9Sstevel@tonic-gate #define	PF_LAT		AF_LAT
2357c478bd9Sstevel@tonic-gate #define	PF_HYLINK	AF_HYLINK
2367c478bd9Sstevel@tonic-gate #define	PF_APPLETALK	AF_APPLETALK
2377c478bd9Sstevel@tonic-gate #define	PF_NIT		AF_NIT
2387c478bd9Sstevel@tonic-gate #define	PF_802		AF_802
2397c478bd9Sstevel@tonic-gate #define	PF_OSI		AF_OSI
2407c478bd9Sstevel@tonic-gate #define	PF_X25		AF_X25
2417c478bd9Sstevel@tonic-gate #define	PF_OSINET	AF_OSINET
2427c478bd9Sstevel@tonic-gate #define	PF_GOSIP	AF_GOSIP
2437c478bd9Sstevel@tonic-gate #define	PF_IPX		AF_IPX
2447c478bd9Sstevel@tonic-gate #define	PF_ROUTE	AF_ROUTE
2457c478bd9Sstevel@tonic-gate #define	PF_LINK		AF_LINK
2467c478bd9Sstevel@tonic-gate #define	PF_INET6	AF_INET6
2477c478bd9Sstevel@tonic-gate #define	PF_KEY		AF_KEY
2487c478bd9Sstevel@tonic-gate #define	PF_NCA		AF_NCA
2497c478bd9Sstevel@tonic-gate #define	PF_POLICY	AF_POLICY
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate #define	PF_MAX		AF_MAX
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate /*
2547c478bd9Sstevel@tonic-gate  * Maximum queue length specifiable by listen.
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate #define	SOMAXCONN	128
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate  * Message header for recvmsg and sendmsg calls.
2607c478bd9Sstevel@tonic-gate  */
2617c478bd9Sstevel@tonic-gate struct msghdr {
2627c478bd9Sstevel@tonic-gate 	void		*msg_name;		/* optional address */
2637c478bd9Sstevel@tonic-gate 	socklen_t	msg_namelen;		/* size of address */
2647c478bd9Sstevel@tonic-gate 	struct iovec	*msg_iov;		/* scatter/gather array */
2657c478bd9Sstevel@tonic-gate 	int		msg_iovlen;		/* # elements in msg_iov */
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_KERNEL)
2687c478bd9Sstevel@tonic-gate 	void		*msg_control;		/* ancillary data */
2697c478bd9Sstevel@tonic-gate 	socklen_t	msg_controllen;		/* ancillary data buffer len */
2707c478bd9Sstevel@tonic-gate 	int		msg_flags;		/* flags on received message */
2717c478bd9Sstevel@tonic-gate #else
2727c478bd9Sstevel@tonic-gate 	caddr_t		msg_accrights;	/* access rights sent/received */
2737c478bd9Sstevel@tonic-gate 	int		msg_accrightslen;
2747c478bd9Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_KERNEL) */
2757c478bd9Sstevel@tonic-gate };
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #if	defined(_KERNEL)
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate /*
2807c478bd9Sstevel@tonic-gate  *	N.B.:  we assume that omsghdr and nmsghdr are isomorphic, with
2817c478bd9Sstevel@tonic-gate  *	the sole exception that nmsghdr has the additional msg_flags
2827c478bd9Sstevel@tonic-gate  *	field at the end.
2837c478bd9Sstevel@tonic-gate  */
2847c478bd9Sstevel@tonic-gate struct omsghdr {
2857c478bd9Sstevel@tonic-gate 	void		*msg_name;	/* optional address */
2867c478bd9Sstevel@tonic-gate 	socklen_t	msg_namelen;	/* size of address */
2877c478bd9Sstevel@tonic-gate 	struct	iovec	*msg_iov;	/* scatter/gather array */
2887c478bd9Sstevel@tonic-gate 	int		msg_iovlen;	/* # elements in msg_iov */
2897c478bd9Sstevel@tonic-gate 	caddr_t		msg_accrights;	/* access rights sent/received */
2907c478bd9Sstevel@tonic-gate 	int		msg_accrightslen;
2917c478bd9Sstevel@tonic-gate };
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #define	nmsghdr		msghdr
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate struct omsghdr32 {
2987c478bd9Sstevel@tonic-gate 	caddr32_t	msg_name;	/* optional address */
2997c478bd9Sstevel@tonic-gate 	uint32_t	msg_namelen;	/* size of address */
3007c478bd9Sstevel@tonic-gate 	caddr32_t	msg_iov;	/* scatter/gather array */
3017c478bd9Sstevel@tonic-gate 	int32_t		msg_iovlen;	/* # elements in msg_iov */
3027c478bd9Sstevel@tonic-gate 	caddr32_t	msg_accrights;	/* access rights sent/received */
3037c478bd9Sstevel@tonic-gate 	uint32_t	msg_accrightslen;
3047c478bd9Sstevel@tonic-gate };
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate struct msghdr32 {
3077c478bd9Sstevel@tonic-gate 	caddr32_t	msg_name;	/* optional address */
3087c478bd9Sstevel@tonic-gate 	uint32_t	msg_namelen;	/* size of address */
3097c478bd9Sstevel@tonic-gate 	caddr32_t	msg_iov;	/* scatter/gather array */
3107c478bd9Sstevel@tonic-gate 	int32_t		msg_iovlen;	/* # elements in msg_iov */
3117c478bd9Sstevel@tonic-gate 	caddr32_t	msg_control;	/* ancillary data */
3127c478bd9Sstevel@tonic-gate 	uint32_t	msg_controllen;	/* ancillary data buffer len */
3137c478bd9Sstevel@tonic-gate 	int32_t		msg_flags;	/* flags on received message */
3147c478bd9Sstevel@tonic-gate };
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate #define	nmsghdr32	msghdr32
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3197c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate #define	MSG_OOB		0x1		/* process out-of-band data */
3227c478bd9Sstevel@tonic-gate #define	MSG_PEEK	0x2		/* peek at incoming message */
3237c478bd9Sstevel@tonic-gate #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
3247c478bd9Sstevel@tonic-gate /* Added for XPGv2 compliance */
3257c478bd9Sstevel@tonic-gate #define	MSG_EOR		0x8		/* Terminates a record */
3267c478bd9Sstevel@tonic-gate #define	MSG_CTRUNC	0x10		/* Control data truncated */
3277c478bd9Sstevel@tonic-gate #define	MSG_TRUNC	0x20		/* Normal data truncated */
3287c478bd9Sstevel@tonic-gate #define	MSG_WAITALL	0x40		/* Wait for complete recv or error */
3297c478bd9Sstevel@tonic-gate /* End of XPGv2 compliance */
3307c478bd9Sstevel@tonic-gate #define	MSG_DONTWAIT	0x80		/* Don't block for this recv */
3317c478bd9Sstevel@tonic-gate #define	MSG_NOTIFICATION 0x100		/* Notification, not data */
3327c478bd9Sstevel@tonic-gate #define	MSG_XPG4_2	0x8000		/* Private: XPG4.2 flag */
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate #define	MSG_MAXIOVLEN	16
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate /* Added for XPGv2 compliance */
3377c478bd9Sstevel@tonic-gate #define	SHUT_RD		0
3387c478bd9Sstevel@tonic-gate #define	SHUT_WR		1
3397c478bd9Sstevel@tonic-gate #define	SHUT_RDWR	2
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate struct cmsghdr {
3427c478bd9Sstevel@tonic-gate 	socklen_t	cmsg_len;	/* data byte count, including hdr */
3437c478bd9Sstevel@tonic-gate 	int		cmsg_level;	/* originating protocol */
3447c478bd9Sstevel@tonic-gate 	int		cmsg_type;	/* protocol-specific type */
3457c478bd9Sstevel@tonic-gate };
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_KERNEL)
3487c478bd9Sstevel@tonic-gate #if defined(__sparc)
3497c478bd9Sstevel@tonic-gate /* To maintain backward compatibility, alignment needs to be 8 on sparc. */
3507c478bd9Sstevel@tonic-gate #define	_CMSG_HDR_ALIGNMENT	8
3517c478bd9Sstevel@tonic-gate #else
3527c478bd9Sstevel@tonic-gate /* for __i386 (and other future architectures) */
3537c478bd9Sstevel@tonic-gate #define	_CMSG_HDR_ALIGNMENT	4
3547c478bd9Sstevel@tonic-gate #endif	/* defined(__sparc) */
3557c478bd9Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_KERNEL) */
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate #if defined(_XPG4_2)
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate  * The cmsg headers (and macros dealing with them) were made available as
3607c478bd9Sstevel@tonic-gate  * part of UNIX95 and hence need to be protected with a _XPG4_2 define.
3617c478bd9Sstevel@tonic-gate  */
3627c478bd9Sstevel@tonic-gate #define	_CMSG_DATA_ALIGNMENT	(sizeof (int))
3637c478bd9Sstevel@tonic-gate #define	_CMSG_HDR_ALIGN(x)	(((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \
3647c478bd9Sstevel@tonic-gate 				    ~(_CMSG_HDR_ALIGNMENT - 1))
3657c478bd9Sstevel@tonic-gate #define	_CMSG_DATA_ALIGN(x)	(((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \
3667c478bd9Sstevel@tonic-gate 				    ~(_CMSG_DATA_ALIGNMENT - 1))
3677c478bd9Sstevel@tonic-gate #define	CMSG_DATA(c)							\
3687c478bd9Sstevel@tonic-gate 	((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1))
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate #define	CMSG_FIRSTHDR(m)						\
3717c478bd9Sstevel@tonic-gate 	(((m)->msg_controllen < sizeof (struct cmsghdr)) ?		\
3727c478bd9Sstevel@tonic-gate 	    (struct cmsghdr *)0 : (struct cmsghdr *)((m)->msg_control))
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate #define	CMSG_NXTHDR(m, c)						\
3757c478bd9Sstevel@tonic-gate 	(((c) == 0) ? CMSG_FIRSTHDR(m) :			\
3767c478bd9Sstevel@tonic-gate 	((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) +			\
3777c478bd9Sstevel@tonic-gate 	((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) >	\
3787c478bd9Sstevel@tonic-gate 	(((uintptr_t)((struct msghdr *)(m))->msg_control) +		\
3797c478bd9Sstevel@tonic-gate 	((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ?		\
3807c478bd9Sstevel@tonic-gate 	((struct cmsghdr *)0) :						\
3817c478bd9Sstevel@tonic-gate 	((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) +		\
3827c478bd9Sstevel@tonic-gate 	    ((struct cmsghdr *)(c))->cmsg_len))))
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /* Amount of space + padding needed for a message of length l */
3857c478bd9Sstevel@tonic-gate #define	CMSG_SPACE(l)							\
3867c478bd9Sstevel@tonic-gate 	((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate /* Value to be used in cmsg_len, does not include trailing padding */
3897c478bd9Sstevel@tonic-gate #define	CMSG_LEN(l)							\
3907c478bd9Sstevel@tonic-gate 	((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate #endif	/* _XPG4_2 */
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate #ifdef	_XPG4_2
3957c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
3967c478bd9Sstevel@tonic-gate #pragma redefine_extname bind __xnet_bind
3977c478bd9Sstevel@tonic-gate #pragma redefine_extname connect __xnet_connect
3987c478bd9Sstevel@tonic-gate #pragma redefine_extname recvmsg __xnet_recvmsg
3997c478bd9Sstevel@tonic-gate #pragma redefine_extname sendmsg __xnet_sendmsg
4007c478bd9Sstevel@tonic-gate #pragma redefine_extname sendto __xnet_sendto
4017c478bd9Sstevel@tonic-gate #pragma redefine_extname socket __xnet_socket
4027c478bd9Sstevel@tonic-gate #pragma redefine_extname socketpair __xnet_socketpair
4037c478bd9Sstevel@tonic-gate #pragma redefine_extname getsockopt __xnet_getsockopt
4047c478bd9Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
4057c478bd9Sstevel@tonic-gate #define	bind	__xnet_bind
4067c478bd9Sstevel@tonic-gate #define	connect	__xnet_connect
4077c478bd9Sstevel@tonic-gate #define	recvmsg	__xnet_recvmsg
4087c478bd9Sstevel@tonic-gate #define	sendmsg	__xnet_sendmsg
4097c478bd9Sstevel@tonic-gate #define	sendto	__xnet_sendto
4107c478bd9Sstevel@tonic-gate #define	socket	__xnet_socket
4117c478bd9Sstevel@tonic-gate #define	socketpair	__xnet_socketpair
4127c478bd9Sstevel@tonic-gate #define	getsockopt	__xnet_getsockopt
4137c478bd9Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate #endif	/* _XPG4_2 */
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5)
4187c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
4197c478bd9Sstevel@tonic-gate #pragma redefine_extname listen __xnet_listen
4207c478bd9Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
4217c478bd9Sstevel@tonic-gate #define	listen	__xnet_listen
4227c478bd9Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
4237c478bd9Sstevel@tonic-gate #endif /* (_XPG4_2) && !defined(_XPG5) */
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate #if !defined(_KERNEL) || defined(_BOOT)
4267c478bd9Sstevel@tonic-gate #ifdef	__STDC__
4277c478bd9Sstevel@tonic-gate extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
4287c478bd9Sstevel@tonic-gate extern int bind(int, const struct sockaddr *, socklen_t);
4297c478bd9Sstevel@tonic-gate extern int connect(int, const struct sockaddr *, socklen_t);
4307c478bd9Sstevel@tonic-gate extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
4317c478bd9Sstevel@tonic-gate extern int getsockname(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
4327c478bd9Sstevel@tonic-gate extern int getsockopt(int, int, int, void *_RESTRICT_KYWD, Psocklen_t);
4337c478bd9Sstevel@tonic-gate extern int listen(int, int);	/* XXX - fixme???  where do I go */
4347c478bd9Sstevel@tonic-gate extern int socketpair(int, int, int, int *);
4357c478bd9Sstevel@tonic-gate extern ssize_t recv(int, void *, size_t, int);
4367c478bd9Sstevel@tonic-gate extern ssize_t recvfrom(int, void *_RESTRICT_KYWD, size_t, int,
4377c478bd9Sstevel@tonic-gate 	struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
4387c478bd9Sstevel@tonic-gate extern ssize_t recvmsg(int, struct msghdr *, int);
4397c478bd9Sstevel@tonic-gate extern ssize_t send(int, const void *, size_t, int);
4407c478bd9Sstevel@tonic-gate extern ssize_t sendmsg(int, const struct msghdr *, int);
4417c478bd9Sstevel@tonic-gate extern ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
4427c478bd9Sstevel@tonic-gate 	socklen_t);
4437c478bd9Sstevel@tonic-gate extern int setsockopt(int, int, int, const void *, socklen_t);
4447c478bd9Sstevel@tonic-gate extern int shutdown(int, int);
4457c478bd9Sstevel@tonic-gate extern int socket(int, int, int);
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
4487c478bd9Sstevel@tonic-gate extern int sockatmark(int);
4497c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
4507c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
4517c478bd9Sstevel@tonic-gate extern int accept();
4527c478bd9Sstevel@tonic-gate extern int bind();
4537c478bd9Sstevel@tonic-gate extern int connect();
4547c478bd9Sstevel@tonic-gate extern int getpeername();
4557c478bd9Sstevel@tonic-gate extern int getsockname();
4567c478bd9Sstevel@tonic-gate extern int getsockopt();
4577c478bd9Sstevel@tonic-gate extern int listen();
4587c478bd9Sstevel@tonic-gate extern int recv();
4597c478bd9Sstevel@tonic-gate extern int recvfrom();
4607c478bd9Sstevel@tonic-gate extern int send();
4617c478bd9Sstevel@tonic-gate extern int sendto();
4627c478bd9Sstevel@tonic-gate extern int setsockopt();
4637c478bd9Sstevel@tonic-gate extern int sockatmark();
4647c478bd9Sstevel@tonic-gate extern int socket();
4657c478bd9Sstevel@tonic-gate extern int recvmsg();
4667c478bd9Sstevel@tonic-gate extern int sendmsg();
4677c478bd9Sstevel@tonic-gate extern int shutdown();
4687c478bd9Sstevel@tonic-gate extern int socketpair();
4697c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
4707c478bd9Sstevel@tonic-gate #endif	/* !defined(_KERNEL) || defined(_BOOT) */
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate #endif
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate #endif	/* _SYS_SOCKET_H */
477