xref: /onnv-gate/usr/src/uts/common/sys/socket.h (revision 12643:044ff822d212)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51673Sgt145670  * Common Development and Distribution License (the "License").
61673Sgt145670  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12643SAnders.Persson@Sun.COM  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
260Sstevel@tonic-gate /*	  All Rights Reserved	*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
300Sstevel@tonic-gate  * The Regents of the University of California
310Sstevel@tonic-gate  * All Rights Reserved
320Sstevel@tonic-gate  *
330Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
340Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
350Sstevel@tonic-gate  * contributors.
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifndef	_SYS_SOCKET_H
390Sstevel@tonic-gate #define	_SYS_SOCKET_H
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include <sys/types.h>
420Sstevel@tonic-gate #include <sys/uio.h>
430Sstevel@tonic-gate #include <sys/feature_tests.h>
440Sstevel@tonic-gate #include <sys/socket_impl.h>
450Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
460Sstevel@tonic-gate #ifndef	_KERNEL
470Sstevel@tonic-gate #include <sys/netconfig.h>
480Sstevel@tonic-gate #endif	/* !_KERNEL */
490Sstevel@tonic-gate #include <netinet/in.h>
500Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #ifdef	__cplusplus
530Sstevel@tonic-gate extern "C" {
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #ifndef	_SOCKLEN_T
570Sstevel@tonic-gate #define	_SOCKLEN_T
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * The socklen definitions are reproduced in netinet/in.h for the inet6_
610Sstevel@tonic-gate  * functions.  Exposing all of sys/socket.h via netinet/in.h breaks existing
620Sstevel@tonic-gate  * applications and is not required by austin.
630Sstevel@tonic-gate  */
640Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64)
650Sstevel@tonic-gate typedef	size_t		socklen_t;
660Sstevel@tonic-gate #else
670Sstevel@tonic-gate typedef	uint32_t	socklen_t;
680Sstevel@tonic-gate #endif	/* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
690Sstevel@tonic-gate 
700Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_BOOT)
710Sstevel@tonic-gate typedef	socklen_t	*_RESTRICT_KYWD Psocklen_t;
720Sstevel@tonic-gate #else
730Sstevel@tonic-gate typedef	void		*_RESTRICT_KYWD Psocklen_t;
740Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_BOOT) */
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #endif	/* _SOCKLEN_T */
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * Definitions related to sockets: types, address families, options.
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
820Sstevel@tonic-gate #ifndef	NC_TPI_CLTS
830Sstevel@tonic-gate #define	NC_TPI_CLTS	1		/* must agree with netconfig.h */
840Sstevel@tonic-gate #define	NC_TPI_COTS	2		/* must agree with netconfig.h */
850Sstevel@tonic-gate #define	NC_TPI_COTS_ORD	3		/* must agree with netconfig.h */
860Sstevel@tonic-gate #define	NC_TPI_RAW	4		/* must agree with netconfig.h */
870Sstevel@tonic-gate #endif	/* !NC_TPI_CLTS */
880Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * Types
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
940Sstevel@tonic-gate #define	SOCK_STREAM	NC_TPI_COTS	/* stream socket */
950Sstevel@tonic-gate #define	SOCK_DGRAM	NC_TPI_CLTS	/* datagram socket */
960Sstevel@tonic-gate #define	SOCK_RAW	NC_TPI_RAW	/* raw-protocol interface */
970Sstevel@tonic-gate #else
980Sstevel@tonic-gate #define	SOCK_STREAM	2		/* stream socket */
990Sstevel@tonic-gate #define	SOCK_DGRAM	1		/* datagram socket */
1000Sstevel@tonic-gate #define	SOCK_RAW	4		/* raw-protocol interface */
1010Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1020Sstevel@tonic-gate #define	SOCK_RDM	5		/* reliably-delivered message */
1030Sstevel@tonic-gate #define	SOCK_SEQPACKET	6		/* sequenced packet stream */
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate /*
1060Sstevel@tonic-gate  * Option flags per-socket.
1070Sstevel@tonic-gate  */
1080Sstevel@tonic-gate #define	SO_DEBUG	0x0001		/* turn on debugging info recording */
1090Sstevel@tonic-gate #define	SO_ACCEPTCONN	0x0002		/* socket has had listen() */
1100Sstevel@tonic-gate #define	SO_REUSEADDR	0x0004		/* allow local address reuse */
1110Sstevel@tonic-gate #define	SO_KEEPALIVE	0x0008		/* keep connections alive */
1120Sstevel@tonic-gate #define	SO_DONTROUTE	0x0010		/* just use interface addresses */
1130Sstevel@tonic-gate #define	SO_BROADCAST	0x0020		/* permit sending of broadcast msgs */
1140Sstevel@tonic-gate #define	SO_USELOOPBACK	0x0040		/* bypass hardware when possible */
1150Sstevel@tonic-gate #define	SO_LINGER	0x0080		/* linger on close if data present */
1160Sstevel@tonic-gate #define	SO_OOBINLINE	0x0100		/* leave received OOB data in line */
1170Sstevel@tonic-gate #define	SO_DGRAM_ERRIND	0x0200		/* Application wants delayed error */
1180Sstevel@tonic-gate #define	SO_RECVUCRED	0x0400		/* Application wants ucred of sender */
1190Sstevel@tonic-gate 
12010639SDarren.Reed@Sun.COM /*
12110639SDarren.Reed@Sun.COM  * Socket options are passed using a signed integer, but it is also rare
12210639SDarren.Reed@Sun.COM  * for more than one to ever be passed at the same time with setsockopt
12310639SDarren.Reed@Sun.COM  * and only one at a time can be retrieved with getsockopt.
12410639SDarren.Reed@Sun.COM  *
12510639SDarren.Reed@Sun.COM  * Since the lower numbers cannot be renumbered for compatibility reasons,
12610639SDarren.Reed@Sun.COM  * it would seem that we need to start a new number space (0x40000000 -
12710639SDarren.Reed@Sun.COM  * 0x7fffffff) for those that don't need to be stored as a bit flag
12810639SDarren.Reed@Sun.COM  * somewhere. This limits the flag options to 30 but that seems to be
12910639SDarren.Reed@Sun.COM  * plenty, anyway. 0x40000000 is reserved for future use.
13010639SDarren.Reed@Sun.COM  */
13110639SDarren.Reed@Sun.COM #define	SO_ATTACH_FILTER	0x40000001
13210639SDarren.Reed@Sun.COM #define	SO_DETACH_FILTER	0x40000002
13310639SDarren.Reed@Sun.COM 
1340Sstevel@tonic-gate #ifdef _KERNEL
1350Sstevel@tonic-gate #define	SO_SND_COPYAVOID 0x0800		/* Internal: use zero-copy */
1368348SEric.Yu@Sun.COM #define	SO_SND_BUFINFO	0x1000		/* Internal: get buffer info */
1378348SEric.Yu@Sun.COM 					/* when doing zero-copy */
1388348SEric.Yu@Sun.COM 
1398348SEric.Yu@Sun.COM struct so_snd_bufinfo {
1408348SEric.Yu@Sun.COM 	ushort_t	sbi_wroff; 	/* Write offset */
1418348SEric.Yu@Sun.COM 	ssize_t		sbi_maxblk;	/* Max size of a single mblk */
1428348SEric.Yu@Sun.COM 	ssize_t		sbi_maxpsz;	/* Max total size of a mblk chain */
1438348SEric.Yu@Sun.COM 	ushort_t	sbi_tail;	/* Extra space available at the end */
1448348SEric.Yu@Sun.COM };
1450Sstevel@tonic-gate #endif /* _KERNEL */
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate /*
1480Sstevel@tonic-gate  * N.B.: The following definition is present only for compatibility
1490Sstevel@tonic-gate  * with release 3.0.  It will disappear in later releases.
1500Sstevel@tonic-gate  */
1510Sstevel@tonic-gate #define	SO_DONTLINGER	(~SO_LINGER)	/* ~SO_LINGER */
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * Additional options, not kept in so_options.
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate #define	SO_SNDBUF	0x1001		/* send buffer size */
1570Sstevel@tonic-gate #define	SO_RCVBUF	0x1002		/* receive buffer size */
1580Sstevel@tonic-gate #define	SO_SNDLOWAT	0x1003		/* send low-water mark */
1590Sstevel@tonic-gate #define	SO_RCVLOWAT	0x1004		/* receive low-water mark */
1600Sstevel@tonic-gate #define	SO_SNDTIMEO	0x1005		/* send timeout */
1610Sstevel@tonic-gate #define	SO_RCVTIMEO	0x1006		/* receive timeout */
1620Sstevel@tonic-gate #define	SO_ERROR	0x1007		/* get error status and clear */
1630Sstevel@tonic-gate #define	SO_TYPE		0x1008		/* get socket type */
1640Sstevel@tonic-gate #define	SO_PROTOTYPE	0x1009		/* get/set protocol type */
1651676Sjpk #define	SO_ANON_MLP	0x100a		/* create MLP on anonymous bind */
1661676Sjpk #define	SO_MAC_EXEMPT	0x100b		/* allow dominated unlabeled peers */
1673388Skcpoon #define	SO_DOMAIN	0x100c		/* get socket domain */
1688348SEric.Yu@Sun.COM #define	SO_RCVPSH	0x100d		/* receive interval to push data */
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate /* "Socket"-level control message types: */
1710Sstevel@tonic-gate #define	SCM_RIGHTS	0x1010		/* access rights (array of int) */
1720Sstevel@tonic-gate #define	SO_SECATTR	0x1011		/* socket's security attributes */
1730Sstevel@tonic-gate #define	SCM_UCRED	0x1012		/* sender's ucred */
1741673Sgt145670 #define	SO_TIMESTAMP	0x1013		/* socket-level timestamp option */
1751673Sgt145670 #define	SCM_TIMESTAMP	SO_TIMESTAMP	/* socket control message timestamp */
1762263Ssommerfe #define	SO_ALLZONES	0x1014		/* bind in all zones */
1772429Skcpoon #define	SO_EXCLBIND	0x1015		/* exclusive binding */
17810934Ssommerfeld@sun.com #define	SO_MAC_IMPLICIT	0x1016		/* hide mac labels on wire */
17911076SCathy.Zhou@Sun.COM #define	SO_VRRP		0x1017		/* VRRP control socket */
1802263Ssommerfe 
1810Sstevel@tonic-gate #ifdef	_KERNEL
1820Sstevel@tonic-gate #define	SO_SRCADDR	0x2001		/* Internal: AF_UNIX source address */
1830Sstevel@tonic-gate #define	SO_FILEP	0x2002		/* Internal: AF_UNIX file pointer */
1840Sstevel@tonic-gate #define	SO_UNIX_CLOSE	0x2003		/* Internal: AF_UNIX peer closed */
1850Sstevel@tonic-gate #endif	/* _KERNEL */
1860Sstevel@tonic-gate 
187*12643SAnders.Persson@Sun.COM /*
188*12643SAnders.Persson@Sun.COM  * Socket filter options
189*12643SAnders.Persson@Sun.COM  */
190*12643SAnders.Persson@Sun.COM #define	FIL_ATTACH	0x1		/* attach filter */
191*12643SAnders.Persson@Sun.COM #define	FIL_DETACH	0x2		/* detach filter */
192*12643SAnders.Persson@Sun.COM #define	FIL_LIST	0x3		/* list attached filters */
193*12643SAnders.Persson@Sun.COM 
194*12643SAnders.Persson@Sun.COM #define	FILNAME_MAX	32
195*12643SAnders.Persson@Sun.COM /*
196*12643SAnders.Persson@Sun.COM  * Structure returned by FIL_LIST
197*12643SAnders.Persson@Sun.COM  */
198*12643SAnders.Persson@Sun.COM struct fil_info {
199*12643SAnders.Persson@Sun.COM 	int	fi_flags;		/* see below (FILF_*) */
200*12643SAnders.Persson@Sun.COM 	int	fi_pos;			/* position (0 is bottom) */
201*12643SAnders.Persson@Sun.COM 	char	fi_name[FILNAME_MAX];	/* filter name */
202*12643SAnders.Persson@Sun.COM };
203*12643SAnders.Persson@Sun.COM 
204*12643SAnders.Persson@Sun.COM #define	FILF_PROG	0x1		/* programmatic attach */
205*12643SAnders.Persson@Sun.COM #define	FILF_AUTO	0x2		/* automatic attach */
206*12643SAnders.Persson@Sun.COM #define	FILF_BYPASS	0x4		/* filter is not active */
207*12643SAnders.Persson@Sun.COM 
2080Sstevel@tonic-gate #ifdef	_KERNEL
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate  * new socket open flags to identify socket and acceptor streams
2110Sstevel@tonic-gate  */
2120Sstevel@tonic-gate #define	SO_ACCEPTOR	0x20000		/* acceptor socket */
2130Sstevel@tonic-gate #define	SO_SOCKSTR	0x40000		/* normal socket stream */
2148348SEric.Yu@Sun.COM #define	SO_FALLBACK	0x80000		/* fallback to TPI socket */
2158348SEric.Yu@Sun.COM 
2168348SEric.Yu@Sun.COM /*
2178348SEric.Yu@Sun.COM  * Flags for socket_create() and socket_newconn()
2188348SEric.Yu@Sun.COM  */
2198348SEric.Yu@Sun.COM #define	SOCKET_SLEEP	KM_SLEEP
2208348SEric.Yu@Sun.COM #define	SOCKET_NOSLEEP	KM_NOSLEEP
2218348SEric.Yu@Sun.COM 
2220Sstevel@tonic-gate #endif	/* _KERNEL */
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate /*
2250Sstevel@tonic-gate  * Structure used for manipulating linger option.
2260Sstevel@tonic-gate  */
2270Sstevel@tonic-gate struct	linger {
2280Sstevel@tonic-gate 	int	l_onoff;		/* option on/off */
2290Sstevel@tonic-gate 	int	l_linger;		/* linger time */
2300Sstevel@tonic-gate };
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate /*
2338485SPeter.Memishian@Sun.COM  * Levels for (get/set)sockopt() that don't apply to a specific protocol.
2340Sstevel@tonic-gate  */
2350Sstevel@tonic-gate #define	SOL_SOCKET	0xffff		/* options for socket level */
2368485SPeter.Memishian@Sun.COM #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
2378485SPeter.Memishian@Sun.COM #define	SOL_ROUTE	0xfffe		/* options for routing socket level */
2388485SPeter.Memishian@Sun.COM #endif
23910639SDarren.Reed@Sun.COM #define	SOL_PACKET	0xfffd		/* options for packet level */
240*12643SAnders.Persson@Sun.COM #define	SOL_FILTER	0xfffc		/* options for socket filter level */
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate  * Address families.
2446878Sbrendan  *
2456878Sbrendan  * Some of these constant names are copied for the DTrace IP provider in
2466878Sbrendan  * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
2476878Sbrendan  * in sync.
2480Sstevel@tonic-gate  */
2490Sstevel@tonic-gate #define	AF_UNSPEC	0		/* unspecified */
2500Sstevel@tonic-gate #define	AF_UNIX		1		/* local to host (pipes, portals) */
2517970Spalle@lyckegaard.dk #define	AF_LOCAL	AF_UNIX		/* Synonym for AF_UNIX */
2527970Spalle@lyckegaard.dk #define	AF_FILE		AF_UNIX		/* Synonym for AF_UNIX */
2530Sstevel@tonic-gate #define	AF_INET		2		/* internetwork: UDP, TCP, etc. */
2540Sstevel@tonic-gate #define	AF_IMPLINK	3		/* arpanet imp addresses */
2550Sstevel@tonic-gate #define	AF_PUP		4		/* pup protocols: e.g. BSP */
2560Sstevel@tonic-gate #define	AF_CHAOS	5		/* mit CHAOS protocols */
2570Sstevel@tonic-gate #define	AF_NS		6		/* XEROX NS protocols */
2580Sstevel@tonic-gate #define	AF_NBS		7		/* nbs protocols */
2590Sstevel@tonic-gate #define	AF_ECMA		8		/* european computer manufacturers */
2600Sstevel@tonic-gate #define	AF_DATAKIT	9		/* datakit protocols */
2610Sstevel@tonic-gate #define	AF_CCITT	10		/* CCITT protocols, X.25 etc */
2620Sstevel@tonic-gate #define	AF_SNA		11		/* IBM SNA */
2630Sstevel@tonic-gate #define	AF_DECnet	12		/* DECnet */
2640Sstevel@tonic-gate #define	AF_DLI		13		/* Direct data link interface */
2650Sstevel@tonic-gate #define	AF_LAT		14		/* LAT */
2660Sstevel@tonic-gate #define	AF_HYLINK	15		/* NSC Hyperchannel */
2670Sstevel@tonic-gate #define	AF_APPLETALK	16		/* Apple Talk */
2680Sstevel@tonic-gate #define	AF_NIT		17		/* Network Interface Tap */
2690Sstevel@tonic-gate #define	AF_802		18		/* IEEE 802.2, also ISO 8802 */
2700Sstevel@tonic-gate #define	AF_OSI		19		/* umbrella for all families used */
2710Sstevel@tonic-gate #define	AF_X25		20		/* CCITT X.25 in particular */
2720Sstevel@tonic-gate #define	AF_OSINET	21		/* AFI = 47, IDI = 4 */
2730Sstevel@tonic-gate #define	AF_GOSIP	22		/* U.S. Government OSI */
2740Sstevel@tonic-gate #define	AF_IPX		23		/* Novell Internet Protocol */
2750Sstevel@tonic-gate #define	AF_ROUTE	24		/* Internal Routing Protocol */
2760Sstevel@tonic-gate #define	AF_LINK		25		/* Link-layer interface */
2770Sstevel@tonic-gate #define	AF_INET6	26		/* Internet Protocol, Version 6 */
2780Sstevel@tonic-gate #define	AF_KEY		27		/* Security Association DB socket */
2790Sstevel@tonic-gate #define	AF_NCA		28		/* NCA socket */
2800Sstevel@tonic-gate #define	AF_POLICY	29		/* Security Policy DB socket */
2813302Sagiri #define	AF_INET_OFFLOAD	30		/* Sun private; do not use */
28210491SRishi.Srivatsavai@Sun.COM #define	AF_TRILL	31		/* TRILL interface */
28310639SDarren.Reed@Sun.COM #define	AF_PACKET	32		/* PF_PACKET Linux socket interface */
2840Sstevel@tonic-gate 
28510639SDarren.Reed@Sun.COM #define	AF_MAX		32
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate /*
2880Sstevel@tonic-gate  * Protocol families, same as address families for now.
2890Sstevel@tonic-gate  */
2900Sstevel@tonic-gate #define	PF_UNSPEC	AF_UNSPEC
2910Sstevel@tonic-gate #define	PF_UNIX		AF_UNIX
2927970Spalle@lyckegaard.dk #define	PF_LOCAL	PF_UNIX
2937970Spalle@lyckegaard.dk #define	PF_FILE		PF_UNIX
2940Sstevel@tonic-gate #define	PF_INET		AF_INET
2950Sstevel@tonic-gate #define	PF_IMPLINK	AF_IMPLINK
2960Sstevel@tonic-gate #define	PF_PUP		AF_PUP
2970Sstevel@tonic-gate #define	PF_CHAOS	AF_CHAOS
2980Sstevel@tonic-gate #define	PF_NS		AF_NS
2990Sstevel@tonic-gate #define	PF_NBS		AF_NBS
3000Sstevel@tonic-gate #define	PF_ECMA		AF_ECMA
3010Sstevel@tonic-gate #define	PF_DATAKIT	AF_DATAKIT
3020Sstevel@tonic-gate #define	PF_CCITT	AF_CCITT
3030Sstevel@tonic-gate #define	PF_SNA		AF_SNA
3040Sstevel@tonic-gate #define	PF_DECnet	AF_DECnet
3050Sstevel@tonic-gate #define	PF_DLI		AF_DLI
3060Sstevel@tonic-gate #define	PF_LAT		AF_LAT
3070Sstevel@tonic-gate #define	PF_HYLINK	AF_HYLINK
3080Sstevel@tonic-gate #define	PF_APPLETALK	AF_APPLETALK
3090Sstevel@tonic-gate #define	PF_NIT		AF_NIT
3100Sstevel@tonic-gate #define	PF_802		AF_802
3110Sstevel@tonic-gate #define	PF_OSI		AF_OSI
3120Sstevel@tonic-gate #define	PF_X25		AF_X25
3130Sstevel@tonic-gate #define	PF_OSINET	AF_OSINET
3140Sstevel@tonic-gate #define	PF_GOSIP	AF_GOSIP
3150Sstevel@tonic-gate #define	PF_IPX		AF_IPX
3160Sstevel@tonic-gate #define	PF_ROUTE	AF_ROUTE
3170Sstevel@tonic-gate #define	PF_LINK		AF_LINK
3180Sstevel@tonic-gate #define	PF_INET6	AF_INET6
3190Sstevel@tonic-gate #define	PF_KEY		AF_KEY
3200Sstevel@tonic-gate #define	PF_NCA		AF_NCA
3210Sstevel@tonic-gate #define	PF_POLICY	AF_POLICY
3223302Sagiri #define	PF_INET_OFFLOAD	AF_INET_OFFLOAD	/* Sun private; do not use */
32310491SRishi.Srivatsavai@Sun.COM #define	PF_TRILL	AF_TRILL
32410639SDarren.Reed@Sun.COM #define	PF_PACKET	AF_PACKET
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate #define	PF_MAX		AF_MAX
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate /*
3290Sstevel@tonic-gate  * Maximum queue length specifiable by listen.
3300Sstevel@tonic-gate  */
3310Sstevel@tonic-gate #define	SOMAXCONN	128
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate /*
3340Sstevel@tonic-gate  * Message header for recvmsg and sendmsg calls.
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate struct msghdr {
3370Sstevel@tonic-gate 	void		*msg_name;		/* optional address */
3380Sstevel@tonic-gate 	socklen_t	msg_namelen;		/* size of address */
3390Sstevel@tonic-gate 	struct iovec	*msg_iov;		/* scatter/gather array */
3400Sstevel@tonic-gate 	int		msg_iovlen;		/* # elements in msg_iov */
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_KERNEL)
3430Sstevel@tonic-gate 	void		*msg_control;		/* ancillary data */
3440Sstevel@tonic-gate 	socklen_t	msg_controllen;		/* ancillary data buffer len */
3450Sstevel@tonic-gate 	int		msg_flags;		/* flags on received message */
3460Sstevel@tonic-gate #else
3470Sstevel@tonic-gate 	caddr_t		msg_accrights;	/* access rights sent/received */
3480Sstevel@tonic-gate 	int		msg_accrightslen;
3490Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_KERNEL) */
3500Sstevel@tonic-gate };
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate #if	defined(_KERNEL)
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate /*
3550Sstevel@tonic-gate  *	N.B.:  we assume that omsghdr and nmsghdr are isomorphic, with
3560Sstevel@tonic-gate  *	the sole exception that nmsghdr has the additional msg_flags
3570Sstevel@tonic-gate  *	field at the end.
3580Sstevel@tonic-gate  */
3590Sstevel@tonic-gate struct omsghdr {
3600Sstevel@tonic-gate 	void		*msg_name;	/* optional address */
3610Sstevel@tonic-gate 	socklen_t	msg_namelen;	/* size of address */
3620Sstevel@tonic-gate 	struct	iovec	*msg_iov;	/* scatter/gather array */
3630Sstevel@tonic-gate 	int		msg_iovlen;	/* # elements in msg_iov */
3640Sstevel@tonic-gate 	caddr_t		msg_accrights;	/* access rights sent/received */
3650Sstevel@tonic-gate 	int		msg_accrightslen;
3660Sstevel@tonic-gate };
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate #define	nmsghdr		msghdr
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate #if defined(_SYSCALL32)
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate struct omsghdr32 {
3730Sstevel@tonic-gate 	caddr32_t	msg_name;	/* optional address */
3740Sstevel@tonic-gate 	uint32_t	msg_namelen;	/* size of address */
3750Sstevel@tonic-gate 	caddr32_t	msg_iov;	/* scatter/gather array */
3760Sstevel@tonic-gate 	int32_t		msg_iovlen;	/* # elements in msg_iov */
3770Sstevel@tonic-gate 	caddr32_t	msg_accrights;	/* access rights sent/received */
3780Sstevel@tonic-gate 	uint32_t	msg_accrightslen;
3790Sstevel@tonic-gate };
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate struct msghdr32 {
3820Sstevel@tonic-gate 	caddr32_t	msg_name;	/* optional address */
3830Sstevel@tonic-gate 	uint32_t	msg_namelen;	/* size of address */
3840Sstevel@tonic-gate 	caddr32_t	msg_iov;	/* scatter/gather array */
3850Sstevel@tonic-gate 	int32_t		msg_iovlen;	/* # elements in msg_iov */
3860Sstevel@tonic-gate 	caddr32_t	msg_control;	/* ancillary data */
3870Sstevel@tonic-gate 	uint32_t	msg_controllen;	/* ancillary data buffer len */
3880Sstevel@tonic-gate 	int32_t		msg_flags;	/* flags on received message */
3890Sstevel@tonic-gate };
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate #define	nmsghdr32	msghdr32
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3940Sstevel@tonic-gate #endif	/* _KERNEL */
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate #define	MSG_OOB		0x1		/* process out-of-band data */
3970Sstevel@tonic-gate #define	MSG_PEEK	0x2		/* peek at incoming message */
3980Sstevel@tonic-gate #define	MSG_DONTROUTE	0x4		/* send without using routing tables */
3990Sstevel@tonic-gate /* Added for XPGv2 compliance */
4000Sstevel@tonic-gate #define	MSG_EOR		0x8		/* Terminates a record */
4010Sstevel@tonic-gate #define	MSG_CTRUNC	0x10		/* Control data truncated */
4020Sstevel@tonic-gate #define	MSG_TRUNC	0x20		/* Normal data truncated */
4030Sstevel@tonic-gate #define	MSG_WAITALL	0x40		/* Wait for complete recv or error */
4048348SEric.Yu@Sun.COM #define	MSG_DUPCTRL	0x800		/* Save control message for use with */
4058348SEric.Yu@Sun.COM 					/* with left over data */
4060Sstevel@tonic-gate /* End of XPGv2 compliance */
4070Sstevel@tonic-gate #define	MSG_DONTWAIT	0x80		/* Don't block for this recv */
4080Sstevel@tonic-gate #define	MSG_NOTIFICATION 0x100		/* Notification, not data */
4090Sstevel@tonic-gate #define	MSG_XPG4_2	0x8000		/* Private: XPG4.2 flag */
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate #define	MSG_MAXIOVLEN	16
4120Sstevel@tonic-gate 
4138348SEric.Yu@Sun.COM #ifdef _KERNEL
4148348SEric.Yu@Sun.COM 
4158348SEric.Yu@Sun.COM /*
4168348SEric.Yu@Sun.COM  * for kernel socket only
4178348SEric.Yu@Sun.COM  */
4188348SEric.Yu@Sun.COM #define	MSG_MBLK_QUICKRELE	0x10000000	/* free mblk chain */
4198348SEric.Yu@Sun.COM 						/* in timely manner */
4208348SEric.Yu@Sun.COM #define	MSG_USERSPACE		0x20000000	/* buffer from user space */
4218348SEric.Yu@Sun.COM 
4228348SEric.Yu@Sun.COM #endif /* _KERNEL */
4238348SEric.Yu@Sun.COM 
4248348SEric.Yu@Sun.COM 
4250Sstevel@tonic-gate /* Added for XPGv2 compliance */
4260Sstevel@tonic-gate #define	SHUT_RD		0
4270Sstevel@tonic-gate #define	SHUT_WR		1
4280Sstevel@tonic-gate #define	SHUT_RDWR	2
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate struct cmsghdr {
4310Sstevel@tonic-gate 	socklen_t	cmsg_len;	/* data byte count, including hdr */
4320Sstevel@tonic-gate 	int		cmsg_level;	/* originating protocol */
4330Sstevel@tonic-gate 	int		cmsg_type;	/* protocol-specific type */
4340Sstevel@tonic-gate };
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_KERNEL)
4370Sstevel@tonic-gate #if defined(__sparc)
4380Sstevel@tonic-gate /* To maintain backward compatibility, alignment needs to be 8 on sparc. */
4390Sstevel@tonic-gate #define	_CMSG_HDR_ALIGNMENT	8
4400Sstevel@tonic-gate #else
4410Sstevel@tonic-gate /* for __i386 (and other future architectures) */
4420Sstevel@tonic-gate #define	_CMSG_HDR_ALIGNMENT	4
4430Sstevel@tonic-gate #endif	/* defined(__sparc) */
4440Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_KERNEL) */
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate #if defined(_XPG4_2)
4470Sstevel@tonic-gate /*
4480Sstevel@tonic-gate  * The cmsg headers (and macros dealing with them) were made available as
4490Sstevel@tonic-gate  * part of UNIX95 and hence need to be protected with a _XPG4_2 define.
4500Sstevel@tonic-gate  */
4510Sstevel@tonic-gate #define	_CMSG_DATA_ALIGNMENT	(sizeof (int))
4520Sstevel@tonic-gate #define	_CMSG_HDR_ALIGN(x)	(((uintptr_t)(x) + _CMSG_HDR_ALIGNMENT - 1) & \
4530Sstevel@tonic-gate 				    ~(_CMSG_HDR_ALIGNMENT - 1))
4540Sstevel@tonic-gate #define	_CMSG_DATA_ALIGN(x)	(((uintptr_t)(x) + _CMSG_DATA_ALIGNMENT - 1) & \
4550Sstevel@tonic-gate 				    ~(_CMSG_DATA_ALIGNMENT - 1))
4560Sstevel@tonic-gate #define	CMSG_DATA(c)							\
4570Sstevel@tonic-gate 	((unsigned char *)_CMSG_DATA_ALIGN((struct cmsghdr *)(c) + 1))
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate #define	CMSG_FIRSTHDR(m)						\
4600Sstevel@tonic-gate 	(((m)->msg_controllen < sizeof (struct cmsghdr)) ?		\
4610Sstevel@tonic-gate 	    (struct cmsghdr *)0 : (struct cmsghdr *)((m)->msg_control))
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate #define	CMSG_NXTHDR(m, c)						\
4640Sstevel@tonic-gate 	(((c) == 0) ? CMSG_FIRSTHDR(m) :			\
4650Sstevel@tonic-gate 	((((uintptr_t)_CMSG_HDR_ALIGN((char *)(c) +			\
4660Sstevel@tonic-gate 	((struct cmsghdr *)(c))->cmsg_len) + sizeof (struct cmsghdr)) >	\
4670Sstevel@tonic-gate 	(((uintptr_t)((struct msghdr *)(m))->msg_control) +		\
4680Sstevel@tonic-gate 	((uintptr_t)((struct msghdr *)(m))->msg_controllen))) ?		\
4690Sstevel@tonic-gate 	((struct cmsghdr *)0) :						\
4700Sstevel@tonic-gate 	((struct cmsghdr *)_CMSG_HDR_ALIGN((char *)(c) +		\
4710Sstevel@tonic-gate 	    ((struct cmsghdr *)(c))->cmsg_len))))
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate /* Amount of space + padding needed for a message of length l */
4740Sstevel@tonic-gate #define	CMSG_SPACE(l)							\
4750Sstevel@tonic-gate 	((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate /* Value to be used in cmsg_len, does not include trailing padding */
4780Sstevel@tonic-gate #define	CMSG_LEN(l)							\
4790Sstevel@tonic-gate 	((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate #endif	/* _XPG4_2 */
4820Sstevel@tonic-gate 
4830Sstevel@tonic-gate #ifdef	_XPG4_2
4840Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
4850Sstevel@tonic-gate #pragma redefine_extname bind __xnet_bind
4860Sstevel@tonic-gate #pragma redefine_extname connect __xnet_connect
4870Sstevel@tonic-gate #pragma redefine_extname recvmsg __xnet_recvmsg
4880Sstevel@tonic-gate #pragma redefine_extname sendmsg __xnet_sendmsg
4890Sstevel@tonic-gate #pragma redefine_extname sendto __xnet_sendto
4900Sstevel@tonic-gate #pragma redefine_extname socket __xnet_socket
4910Sstevel@tonic-gate #pragma redefine_extname socketpair __xnet_socketpair
4920Sstevel@tonic-gate #pragma redefine_extname getsockopt __xnet_getsockopt
4930Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
4940Sstevel@tonic-gate #define	bind	__xnet_bind
4950Sstevel@tonic-gate #define	connect	__xnet_connect
4960Sstevel@tonic-gate #define	recvmsg	__xnet_recvmsg
4970Sstevel@tonic-gate #define	sendmsg	__xnet_sendmsg
4980Sstevel@tonic-gate #define	sendto	__xnet_sendto
4990Sstevel@tonic-gate #define	socket	__xnet_socket
5000Sstevel@tonic-gate #define	socketpair	__xnet_socketpair
5010Sstevel@tonic-gate #define	getsockopt	__xnet_getsockopt
5020Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate #endif	/* _XPG4_2 */
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5)
5070Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
5080Sstevel@tonic-gate #pragma redefine_extname listen __xnet_listen
5090Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
5100Sstevel@tonic-gate #define	listen	__xnet_listen
5110Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
5120Sstevel@tonic-gate #endif /* (_XPG4_2) && !defined(_XPG5) */
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate #if !defined(_KERNEL) || defined(_BOOT)
5150Sstevel@tonic-gate #ifdef	__STDC__
5160Sstevel@tonic-gate extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
5170Sstevel@tonic-gate extern int bind(int, const struct sockaddr *, socklen_t);
5180Sstevel@tonic-gate extern int connect(int, const struct sockaddr *, socklen_t);
5190Sstevel@tonic-gate extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
5200Sstevel@tonic-gate extern int getsockname(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
5210Sstevel@tonic-gate extern int getsockopt(int, int, int, void *_RESTRICT_KYWD, Psocklen_t);
5220Sstevel@tonic-gate extern int listen(int, int);	/* XXX - fixme???  where do I go */
5230Sstevel@tonic-gate extern int socketpair(int, int, int, int *);
5240Sstevel@tonic-gate extern ssize_t recv(int, void *, size_t, int);
5250Sstevel@tonic-gate extern ssize_t recvfrom(int, void *_RESTRICT_KYWD, size_t, int,
5260Sstevel@tonic-gate 	struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
5270Sstevel@tonic-gate extern ssize_t recvmsg(int, struct msghdr *, int);
5280Sstevel@tonic-gate extern ssize_t send(int, const void *, size_t, int);
5290Sstevel@tonic-gate extern ssize_t sendmsg(int, const struct msghdr *, int);
5300Sstevel@tonic-gate extern ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
5310Sstevel@tonic-gate 	socklen_t);
5320Sstevel@tonic-gate extern int setsockopt(int, int, int, const void *, socklen_t);
5330Sstevel@tonic-gate extern int shutdown(int, int);
5340Sstevel@tonic-gate extern int socket(int, int, int);
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
5370Sstevel@tonic-gate extern int sockatmark(int);
5380Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
5390Sstevel@tonic-gate #else	/* __STDC__ */
5400Sstevel@tonic-gate extern int accept();
5410Sstevel@tonic-gate extern int bind();
5420Sstevel@tonic-gate extern int connect();
5430Sstevel@tonic-gate extern int getpeername();
5440Sstevel@tonic-gate extern int getsockname();
5450Sstevel@tonic-gate extern int getsockopt();
5460Sstevel@tonic-gate extern int listen();
5470Sstevel@tonic-gate extern int recv();
5480Sstevel@tonic-gate extern int recvfrom();
5490Sstevel@tonic-gate extern int send();
5500Sstevel@tonic-gate extern int sendto();
5510Sstevel@tonic-gate extern int setsockopt();
5520Sstevel@tonic-gate extern int sockatmark();
5530Sstevel@tonic-gate extern int socket();
5540Sstevel@tonic-gate extern int recvmsg();
5550Sstevel@tonic-gate extern int sendmsg();
5560Sstevel@tonic-gate extern int shutdown();
5570Sstevel@tonic-gate extern int socketpair();
5580Sstevel@tonic-gate #endif	/* __STDC__ */
5590Sstevel@tonic-gate #endif	/* !defined(_KERNEL) || defined(_BOOT) */
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate #ifdef	__cplusplus
5620Sstevel@tonic-gate }
5630Sstevel@tonic-gate #endif
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate #endif	/* _SYS_SOCKET_H */
566