xref: /titanic_50/usr/src/uts/common/netinet/in.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate /*
6*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1982, 1986 Regents of the University of California.
7*7c478bd9Sstevel@tonic-gate  * All rights reserved.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
10*7c478bd9Sstevel@tonic-gate  * provided that this notice is preserved and that due credit is given
11*7c478bd9Sstevel@tonic-gate  * to the University of California at Berkeley. The name of the University
12*7c478bd9Sstevel@tonic-gate  * may not be used to endorse or promote products derived from this
13*7c478bd9Sstevel@tonic-gate  * software without specific prior written permission. This software
14*7c478bd9Sstevel@tonic-gate  * is provided ``as is'' without express or implied warranty.
15*7c478bd9Sstevel@tonic-gate  */
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate /*
18*7c478bd9Sstevel@tonic-gate  * Constants and structures defined by the internet system,
19*7c478bd9Sstevel@tonic-gate  * according to following documents
20*7c478bd9Sstevel@tonic-gate  *
21*7c478bd9Sstevel@tonic-gate  * Internet ASSIGNED NUMBERS (RFC1700) and its successors
22*7c478bd9Sstevel@tonic-gate  *	and other assignments at ftp://ftp.isi.edu/in-notes/iana/assignments
23*7c478bd9Sstevel@tonic-gate  * Basic Socket Interface Extensions for IPv6 (RFC2133 and its successors)
24*7c478bd9Sstevel@tonic-gate  *
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _NETINET_IN_H
28*7c478bd9Sstevel@tonic-gate #define	_NETINET_IN_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
41*7c478bd9Sstevel@tonic-gate #include <sys/socket_impl.h>
42*7c478bd9Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #ifndef _SOCKLEN_T
45*7c478bd9Sstevel@tonic-gate #define	_SOCKLEN_T
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate  * The socklen definitions are reproduced here from sys/socket.h so as to
49*7c478bd9Sstevel@tonic-gate  * not introduce that namespace into existing users of netinet/in.h.
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64)
52*7c478bd9Sstevel@tonic-gate typedef	size_t		socklen_t;
53*7c478bd9Sstevel@tonic-gate #else
54*7c478bd9Sstevel@tonic-gate typedef	uint32_t	socklen_t;
55*7c478bd9Sstevel@tonic-gate #endif	/* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_BOOT)
58*7c478bd9Sstevel@tonic-gate typedef	socklen_t	*Psocklen_t;
59*7c478bd9Sstevel@tonic-gate #else
60*7c478bd9Sstevel@tonic-gate typedef	void		*Psocklen_t;
61*7c478bd9Sstevel@tonic-gate #endif	/* defined(_XPG4_2) || defined(_BOOT) */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #endif /* _SOCKLEN_T */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
66*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
67*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate  * Symbols such as htonl() are required to be exposed through this file,
70*7c478bd9Sstevel@tonic-gate  * per XNS Issue 5. This is achieved by inclusion of <sys/byteorder.h>
71*7c478bd9Sstevel@tonic-gate  */
72*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5)
73*7c478bd9Sstevel@tonic-gate #include <sys/byteorder.h>
74*7c478bd9Sstevel@tonic-gate #endif
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate #ifndef _IN_PORT_T
77*7c478bd9Sstevel@tonic-gate #define	_IN_PORT_T
78*7c478bd9Sstevel@tonic-gate typedef	uint16_t	in_port_t;
79*7c478bd9Sstevel@tonic-gate #endif
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate /*
82*7c478bd9Sstevel@tonic-gate  * Note: IPv4 address data structures usage conventions.
83*7c478bd9Sstevel@tonic-gate  * The "in_addr_t" type below (required by Unix standards)
84*7c478bd9Sstevel@tonic-gate  * is NOT a typedef of "struct in_addr" and violates the usual
85*7c478bd9Sstevel@tonic-gate  * conventions where "struct <name>" and <name>_t are corresponding
86*7c478bd9Sstevel@tonic-gate  * typedefs.
87*7c478bd9Sstevel@tonic-gate  * To minimize confusion, kernel data structures/usage prefers use
88*7c478bd9Sstevel@tonic-gate  * of "ipaddr_t" as atomic uint32_t type and avoid using "in_addr_t"
89*7c478bd9Sstevel@tonic-gate  * The user level APIs continue to follow the historic popular
90*7c478bd9Sstevel@tonic-gate  * practice of using "struct in_addr".
91*7c478bd9Sstevel@tonic-gate  */
92*7c478bd9Sstevel@tonic-gate #ifndef _IN_ADDR_T
93*7c478bd9Sstevel@tonic-gate #define	_IN_ADDR_T
94*7c478bd9Sstevel@tonic-gate typedef	uint32_t	in_addr_t;
95*7c478bd9Sstevel@tonic-gate #endif
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate #ifndef _IPADDR_T
98*7c478bd9Sstevel@tonic-gate #define	_IPADDR_T
99*7c478bd9Sstevel@tonic-gate typedef uint32_t ipaddr_t;
100*7c478bd9Sstevel@tonic-gate #endif
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate struct in6_addr {
105*7c478bd9Sstevel@tonic-gate 	union {
106*7c478bd9Sstevel@tonic-gate 		/*
107*7c478bd9Sstevel@tonic-gate 		 * Note: Static initalizers of "union" type assume
108*7c478bd9Sstevel@tonic-gate 		 * the constant on the RHS is the type of the first member
109*7c478bd9Sstevel@tonic-gate 		 * of union.
110*7c478bd9Sstevel@tonic-gate 		 * To make static initializers (and efficient usage) work,
111*7c478bd9Sstevel@tonic-gate 		 * the order of members exposed to user and kernel view of
112*7c478bd9Sstevel@tonic-gate 		 * this data structure is different.
113*7c478bd9Sstevel@tonic-gate 		 * User environment sees specified uint8_t type as first
114*7c478bd9Sstevel@tonic-gate 		 * member whereas kernel sees most efficient type as
115*7c478bd9Sstevel@tonic-gate 		 * first member.
116*7c478bd9Sstevel@tonic-gate 		 */
117*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
118*7c478bd9Sstevel@tonic-gate 		uint32_t	_S6_u32[4];	/* IPv6 address */
119*7c478bd9Sstevel@tonic-gate 		uint8_t		_S6_u8[16];	/* IPv6 address */
120*7c478bd9Sstevel@tonic-gate #else
121*7c478bd9Sstevel@tonic-gate 		uint8_t		_S6_u8[16];	/* IPv6 address */
122*7c478bd9Sstevel@tonic-gate 		uint32_t	_S6_u32[4];	/* IPv6 address */
123*7c478bd9Sstevel@tonic-gate #endif
124*7c478bd9Sstevel@tonic-gate 		uint32_t	__S6_align;	/* Align on 32 bit boundary */
125*7c478bd9Sstevel@tonic-gate 	} _S6_un;
126*7c478bd9Sstevel@tonic-gate };
127*7c478bd9Sstevel@tonic-gate #define	s6_addr		_S6_un._S6_u8
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
130*7c478bd9Sstevel@tonic-gate #define	s6_addr8	_S6_un._S6_u8
131*7c478bd9Sstevel@tonic-gate #define	s6_addr32	_S6_un._S6_u32
132*7c478bd9Sstevel@tonic-gate #endif
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate typedef struct in6_addr in6_addr_t;
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate #ifndef _SA_FAMILY_T
139*7c478bd9Sstevel@tonic-gate #define	_SA_FAMILY_T
140*7c478bd9Sstevel@tonic-gate typedef	uint16_t	sa_family_t;
141*7c478bd9Sstevel@tonic-gate #endif
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * Protocols
145*7c478bd9Sstevel@tonic-gate  */
146*7c478bd9Sstevel@tonic-gate #define	IPPROTO_IP		0		/* dummy for IP */
147*7c478bd9Sstevel@tonic-gate #define	IPPROTO_HOPOPTS		0		/* Hop by hop header for IPv6 */
148*7c478bd9Sstevel@tonic-gate #define	IPPROTO_ICMP		1		/* control message protocol */
149*7c478bd9Sstevel@tonic-gate #define	IPPROTO_IGMP		2		/* group control protocol */
150*7c478bd9Sstevel@tonic-gate #define	IPPROTO_GGP		3		/* gateway^2 (deprecated) */
151*7c478bd9Sstevel@tonic-gate #define	IPPROTO_ENCAP		4		/* IP in IP encapsulation */
152*7c478bd9Sstevel@tonic-gate #define	IPPROTO_TCP		6		/* tcp */
153*7c478bd9Sstevel@tonic-gate #define	IPPROTO_EGP		8		/* exterior gateway protocol */
154*7c478bd9Sstevel@tonic-gate #define	IPPROTO_PUP		12		/* pup */
155*7c478bd9Sstevel@tonic-gate #define	IPPROTO_UDP		17		/* user datagram protocol */
156*7c478bd9Sstevel@tonic-gate #define	IPPROTO_IDP		22		/* xns idp */
157*7c478bd9Sstevel@tonic-gate #define	IPPROTO_IPV6		41		/* IPv6 encapsulated in IP */
158*7c478bd9Sstevel@tonic-gate #define	IPPROTO_ROUTING		43		/* Routing header for IPv6 */
159*7c478bd9Sstevel@tonic-gate #define	IPPROTO_FRAGMENT	44		/* Fragment header for IPv6 */
160*7c478bd9Sstevel@tonic-gate #define	IPPROTO_RSVP		46		/* rsvp */
161*7c478bd9Sstevel@tonic-gate #define	IPPROTO_ESP		50		/* IPsec Encap. Sec. Payload */
162*7c478bd9Sstevel@tonic-gate #define	IPPROTO_AH		51		/* IPsec Authentication Hdr. */
163*7c478bd9Sstevel@tonic-gate #define	IPPROTO_ICMPV6		58		/* ICMP for IPv6 */
164*7c478bd9Sstevel@tonic-gate #define	IPPROTO_NONE		59		/* No next header for IPv6 */
165*7c478bd9Sstevel@tonic-gate #define	IPPROTO_DSTOPTS		60		/* Destination options */
166*7c478bd9Sstevel@tonic-gate #define	IPPROTO_HELLO		63		/* "hello" routing protocol */
167*7c478bd9Sstevel@tonic-gate #define	IPPROTO_ND		77		/* UNOFFICIAL net disk proto */
168*7c478bd9Sstevel@tonic-gate #define	IPPROTO_EON		80		/* ISO clnp */
169*7c478bd9Sstevel@tonic-gate #define	IPPROTO_OSPF		89		/* OSPF */
170*7c478bd9Sstevel@tonic-gate #define	IPPROTO_PIM		103		/* PIM routing protocol */
171*7c478bd9Sstevel@tonic-gate #define	IPPROTO_SCTP		132		/* Stream Control */
172*7c478bd9Sstevel@tonic-gate 						/* Transmission Protocol */
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate #define	IPPROTO_RAW		255		/* raw IP packet */
175*7c478bd9Sstevel@tonic-gate #define	IPPROTO_MAX		256
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate /*
178*7c478bd9Sstevel@tonic-gate  * Port/socket numbers: network standard functions
179*7c478bd9Sstevel@tonic-gate  */
180*7c478bd9Sstevel@tonic-gate #define	IPPORT_ECHO		7
181*7c478bd9Sstevel@tonic-gate #define	IPPORT_DISCARD		9
182*7c478bd9Sstevel@tonic-gate #define	IPPORT_SYSTAT		11
183*7c478bd9Sstevel@tonic-gate #define	IPPORT_DAYTIME		13
184*7c478bd9Sstevel@tonic-gate #define	IPPORT_NETSTAT		15
185*7c478bd9Sstevel@tonic-gate #define	IPPORT_CHARGEN		19
186*7c478bd9Sstevel@tonic-gate #define	IPPORT_FTP		21
187*7c478bd9Sstevel@tonic-gate #define	IPPORT_TELNET		23
188*7c478bd9Sstevel@tonic-gate #define	IPPORT_SMTP		25
189*7c478bd9Sstevel@tonic-gate #define	IPPORT_TIMESERVER	37
190*7c478bd9Sstevel@tonic-gate #define	IPPORT_NAMESERVER	42
191*7c478bd9Sstevel@tonic-gate #define	IPPORT_WHOIS		43
192*7c478bd9Sstevel@tonic-gate #define	IPPORT_MTP		57
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate  * Port/socket numbers: host specific functions
196*7c478bd9Sstevel@tonic-gate  */
197*7c478bd9Sstevel@tonic-gate #define	IPPORT_BOOTPS		67
198*7c478bd9Sstevel@tonic-gate #define	IPPORT_BOOTPC		68
199*7c478bd9Sstevel@tonic-gate #define	IPPORT_TFTP		69
200*7c478bd9Sstevel@tonic-gate #define	IPPORT_RJE		77
201*7c478bd9Sstevel@tonic-gate #define	IPPORT_FINGER		79
202*7c478bd9Sstevel@tonic-gate #define	IPPORT_TTYLINK		87
203*7c478bd9Sstevel@tonic-gate #define	IPPORT_SUPDUP		95
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate /*
206*7c478bd9Sstevel@tonic-gate  * Internet Key Exchange (IKE) ports
207*7c478bd9Sstevel@tonic-gate  */
208*7c478bd9Sstevel@tonic-gate #define	IPPORT_IKE		500
209*7c478bd9Sstevel@tonic-gate #define	IPPORT_IKE_NATT		4500
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate /*
212*7c478bd9Sstevel@tonic-gate  * UNIX TCP sockets
213*7c478bd9Sstevel@tonic-gate  */
214*7c478bd9Sstevel@tonic-gate #define	IPPORT_EXECSERVER	512
215*7c478bd9Sstevel@tonic-gate #define	IPPORT_LOGINSERVER	513
216*7c478bd9Sstevel@tonic-gate #define	IPPORT_CMDSERVER	514
217*7c478bd9Sstevel@tonic-gate #define	IPPORT_EFSSERVER	520
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate /*
220*7c478bd9Sstevel@tonic-gate  * UNIX UDP sockets
221*7c478bd9Sstevel@tonic-gate  */
222*7c478bd9Sstevel@tonic-gate #define	IPPORT_BIFFUDP		512
223*7c478bd9Sstevel@tonic-gate #define	IPPORT_WHOSERVER	513
224*7c478bd9Sstevel@tonic-gate #define	IPPORT_ROUTESERVER	520	/* 520+1 also used */
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate /*
227*7c478bd9Sstevel@tonic-gate  * Ports < IPPORT_RESERVED are reserved for
228*7c478bd9Sstevel@tonic-gate  * privileged processes (e.g. root).
229*7c478bd9Sstevel@tonic-gate  * Ports > IPPORT_USERRESERVED are reserved
230*7c478bd9Sstevel@tonic-gate  * for servers, not necessarily privileged.
231*7c478bd9Sstevel@tonic-gate  */
232*7c478bd9Sstevel@tonic-gate #define	IPPORT_RESERVED		1024
233*7c478bd9Sstevel@tonic-gate #define	IPPORT_USERRESERVED	5000
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate /*
236*7c478bd9Sstevel@tonic-gate  * Link numbers
237*7c478bd9Sstevel@tonic-gate  */
238*7c478bd9Sstevel@tonic-gate #define	IMPLINK_IP		155
239*7c478bd9Sstevel@tonic-gate #define	IMPLINK_LOWEXPER	156
240*7c478bd9Sstevel@tonic-gate #define	IMPLINK_HIGHEXPER	158
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate /*
243*7c478bd9Sstevel@tonic-gate  * IPv4 Internet address
244*7c478bd9Sstevel@tonic-gate  *	This definition contains obsolete fields for compatibility
245*7c478bd9Sstevel@tonic-gate  *	with SunOS 3.x and 4.2bsd.  The presence of subnets renders
246*7c478bd9Sstevel@tonic-gate  *	divisions into fixed fields misleading at best.  New code
247*7c478bd9Sstevel@tonic-gate  *	should use only the s_addr field.
248*7c478bd9Sstevel@tonic-gate  */
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
251*7c478bd9Sstevel@tonic-gate #define	_S_un_b	S_un_b
252*7c478bd9Sstevel@tonic-gate #define	_S_un_w	S_un_w
253*7c478bd9Sstevel@tonic-gate #define	_S_addr	S_addr
254*7c478bd9Sstevel@tonic-gate #define	_S_un	S_un
255*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate struct in_addr {
258*7c478bd9Sstevel@tonic-gate 	union {
259*7c478bd9Sstevel@tonic-gate 		struct { uint8_t s_b1, s_b2, s_b3, s_b4; } _S_un_b;
260*7c478bd9Sstevel@tonic-gate 		struct { uint16_t s_w1, s_w2; } _S_un_w;
261*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
262*7c478bd9Sstevel@tonic-gate 		uint32_t _S_addr;
263*7c478bd9Sstevel@tonic-gate #else
264*7c478bd9Sstevel@tonic-gate 		in_addr_t _S_addr;
265*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
266*7c478bd9Sstevel@tonic-gate 	} _S_un;
267*7c478bd9Sstevel@tonic-gate #define	s_addr	_S_un._S_addr		/* should be used for all code */
268*7c478bd9Sstevel@tonic-gate #define	s_host	_S_un._S_un_b.s_b2	/* OBSOLETE: host on imp */
269*7c478bd9Sstevel@tonic-gate #define	s_net	_S_un._S_un_b.s_b1	/* OBSOLETE: network */
270*7c478bd9Sstevel@tonic-gate #define	s_imp	_S_un._S_un_w.s_w2	/* OBSOLETE: imp */
271*7c478bd9Sstevel@tonic-gate #define	s_impno	_S_un._S_un_b.s_b4	/* OBSOLETE: imp # */
272*7c478bd9Sstevel@tonic-gate #define	s_lh	_S_un._S_un_b.s_b3	/* OBSOLETE: logical host */
273*7c478bd9Sstevel@tonic-gate };
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate /*
276*7c478bd9Sstevel@tonic-gate  * Definitions of bits in internet address integers.
277*7c478bd9Sstevel@tonic-gate  * On subnets, the decomposition of addresses to host and net parts
278*7c478bd9Sstevel@tonic-gate  * is done according to subnet mask, not the masks here.
279*7c478bd9Sstevel@tonic-gate  */
280*7c478bd9Sstevel@tonic-gate #define	IN_CLASSA(i)		(((i) & 0x80000000U) == 0)
281*7c478bd9Sstevel@tonic-gate #define	IN_CLASSA_NET		0xff000000U
282*7c478bd9Sstevel@tonic-gate #define	IN_CLASSA_NSHIFT	24
283*7c478bd9Sstevel@tonic-gate #define	IN_CLASSA_HOST		0x00ffffffU
284*7c478bd9Sstevel@tonic-gate #define	IN_CLASSA_MAX		128
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate #define	IN_CLASSB(i)		(((i) & 0xc0000000U) == 0x80000000U)
287*7c478bd9Sstevel@tonic-gate #define	IN_CLASSB_NET		0xffff0000U
288*7c478bd9Sstevel@tonic-gate #define	IN_CLASSB_NSHIFT	16
289*7c478bd9Sstevel@tonic-gate #define	IN_CLASSB_HOST		0x0000ffffU
290*7c478bd9Sstevel@tonic-gate #define	IN_CLASSB_MAX		65536
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate #define	IN_CLASSC(i)		(((i) & 0xe0000000U) == 0xc0000000U)
293*7c478bd9Sstevel@tonic-gate #define	IN_CLASSC_NET		0xffffff00U
294*7c478bd9Sstevel@tonic-gate #define	IN_CLASSC_NSHIFT	8
295*7c478bd9Sstevel@tonic-gate #define	IN_CLASSC_HOST		0x000000ffU
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate #define	IN_CLASSD(i)		(((i) & 0xf0000000U) == 0xe0000000U)
298*7c478bd9Sstevel@tonic-gate #define	IN_CLASSD_NET		0xf0000000U	/* These aren't really  */
299*7c478bd9Sstevel@tonic-gate #define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */
300*7c478bd9Sstevel@tonic-gate #define	IN_CLASSD_HOST		0x0fffffffU	/* routing needn't know */
301*7c478bd9Sstevel@tonic-gate #define	IN_MULTICAST(i)		IN_CLASSD(i)
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate #define	IN_EXPERIMENTAL(i)	(((i) & 0xe0000000U) == 0xe0000000U)
304*7c478bd9Sstevel@tonic-gate #define	IN_BADCLASS(i)		(((i) & 0xf0000000U) == 0xf0000000U)
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate #define	INADDR_ANY		0x00000000U
307*7c478bd9Sstevel@tonic-gate #define	INADDR_LOOPBACK		0x7F000001U
308*7c478bd9Sstevel@tonic-gate #define	INADDR_BROADCAST	0xffffffffU	/* must be masked */
309*7c478bd9Sstevel@tonic-gate #define	INADDR_NONE		0xffffffffU
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate #define	INADDR_UNSPEC_GROUP	0xe0000000U	/* 224.0.0.0   */
312*7c478bd9Sstevel@tonic-gate #define	INADDR_ALLHOSTS_GROUP	0xe0000001U	/* 224.0.0.1   */
313*7c478bd9Sstevel@tonic-gate #define	INADDR_ALLRTRS_GROUP	0xe0000002U	/* 224.0.0.2   */
314*7c478bd9Sstevel@tonic-gate #define	INADDR_ALLRPTS_GROUP	0xe0000016U	/* 224.0.0.22, IGMPv3 */
315*7c478bd9Sstevel@tonic-gate #define	INADDR_MAX_LOCAL_GROUP	0xe00000ffU	/* 224.0.0.255 */
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate /* Scoped IPv4 prefixes (in host byte-order) */
318*7c478bd9Sstevel@tonic-gate #define	IN_AUTOCONF_NET		0xa9fe0000U	/* 169.254/16 */
319*7c478bd9Sstevel@tonic-gate #define	IN_AUTOCONF_MASK	0xffff0000U
320*7c478bd9Sstevel@tonic-gate #define	IN_PRIVATE8_NET		0x0a000000U	/* 10/8 */
321*7c478bd9Sstevel@tonic-gate #define	IN_PRIVATE8_MASK	0xff000000U
322*7c478bd9Sstevel@tonic-gate #define	IN_PRIVATE12_NET	0xac100000U	/* 172.16/12 */
323*7c478bd9Sstevel@tonic-gate #define	IN_PRIVATE12_MASK	0xfff00000U
324*7c478bd9Sstevel@tonic-gate #define	IN_PRIVATE16_NET	0xc0a80000U	/* 192.168/16 */
325*7c478bd9Sstevel@tonic-gate #define	IN_PRIVATE16_MASK	0xffff0000U
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate /* Well known 6to4 Relay Router Anycast address defined in RFC 3068 */
328*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || !defined(__EXTENSIONS__)
329*7c478bd9Sstevel@tonic-gate #define	INADDR_6TO4RRANYCAST	0xc0586301U 	/* 192.88.99.1 */
330*7c478bd9Sstevel@tonic-gate #endif	/* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate #define	IN_LOOPBACKNET		127			/* official! */
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate /*
335*7c478bd9Sstevel@tonic-gate  * Define a macro to stuff the loopback address into an Internet address
336*7c478bd9Sstevel@tonic-gate  */
337*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || !defined(__EXTENSIONS__)
338*7c478bd9Sstevel@tonic-gate #define	IN_SET_LOOPBACK_ADDR(a) \
339*7c478bd9Sstevel@tonic-gate 	{ (a)->sin_addr.s_addr  = htonl(INADDR_LOOPBACK); \
340*7c478bd9Sstevel@tonic-gate 	(a)->sin_family = AF_INET; }
341*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate /*
344*7c478bd9Sstevel@tonic-gate  * IPv4 Socket address.
345*7c478bd9Sstevel@tonic-gate  */
346*7c478bd9Sstevel@tonic-gate struct sockaddr_in {
347*7c478bd9Sstevel@tonic-gate 	sa_family_t	sin_family;
348*7c478bd9Sstevel@tonic-gate 	in_port_t	sin_port;
349*7c478bd9Sstevel@tonic-gate 	struct	in_addr sin_addr;
350*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
351*7c478bd9Sstevel@tonic-gate 	char		sin_zero[8];
352*7c478bd9Sstevel@tonic-gate #else
353*7c478bd9Sstevel@tonic-gate 	unsigned char	sin_zero[8];
354*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
355*7c478bd9Sstevel@tonic-gate };
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
358*7c478bd9Sstevel@tonic-gate /*
359*7c478bd9Sstevel@tonic-gate  * IPv6 socket address.
360*7c478bd9Sstevel@tonic-gate  */
361*7c478bd9Sstevel@tonic-gate struct sockaddr_in6 {
362*7c478bd9Sstevel@tonic-gate 	sa_family_t	sin6_family;
363*7c478bd9Sstevel@tonic-gate 	in_port_t	sin6_port;
364*7c478bd9Sstevel@tonic-gate 	uint32_t	sin6_flowinfo;
365*7c478bd9Sstevel@tonic-gate 	struct in6_addr	sin6_addr;
366*7c478bd9Sstevel@tonic-gate 	uint32_t	sin6_scope_id;  /* Depends on scope of sin6_addr */
367*7c478bd9Sstevel@tonic-gate 	uint32_t	__sin6_src_id;	/* Impl. specific - UDP replies */
368*7c478bd9Sstevel@tonic-gate };
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate /*
371*7c478bd9Sstevel@tonic-gate  * Macros for accessing the traffic class and flow label fields from
372*7c478bd9Sstevel@tonic-gate  * sin6_flowinfo.
373*7c478bd9Sstevel@tonic-gate  * These are designed to be applied to a 32-bit value.
374*7c478bd9Sstevel@tonic-gate  */
375*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate /* masks */
378*7c478bd9Sstevel@tonic-gate #define	IPV6_FLOWINFO_FLOWLABEL			0x000fffffU
379*7c478bd9Sstevel@tonic-gate #define	IPV6_FLOWINFO_TCLASS			0x0ff00000U
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate /* masks */
384*7c478bd9Sstevel@tonic-gate #define	IPV6_FLOWINFO_FLOWLABEL			0xffff0f00U
385*7c478bd9Sstevel@tonic-gate #define	IPV6_FLOWINFO_TCLASS			0x0000f00fU
386*7c478bd9Sstevel@tonic-gate 
387*7c478bd9Sstevel@tonic-gate #endif	/* _BIG_ENDIAN */
388*7c478bd9Sstevel@tonic-gate 
389*7c478bd9Sstevel@tonic-gate /*
390*7c478bd9Sstevel@tonic-gate  * Note: Macros IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT are for
391*7c478bd9Sstevel@tonic-gate  * use as RHS of Static initializers of "struct in6_addr" (or in6_addr_t)
392*7c478bd9Sstevel@tonic-gate  * only. They need to be different for User/Kernel versions because union
393*7c478bd9Sstevel@tonic-gate  * component data structure is defined differently (it is identical at
394*7c478bd9Sstevel@tonic-gate  * binary representation level).
395*7c478bd9Sstevel@tonic-gate  *
396*7c478bd9Sstevel@tonic-gate  * const struct in6_addr IN6ADDR_ANY_INIT;
397*7c478bd9Sstevel@tonic-gate  * const struct in6_addr IN6ADDR_LOOPBACK_INIT;
398*7c478bd9Sstevel@tonic-gate  */
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 
401*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
402*7c478bd9Sstevel@tonic-gate #define	IN6ADDR_ANY_INIT		{ 0, 0, 0, 0 }
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
405*7c478bd9Sstevel@tonic-gate #define	IN6ADDR_LOOPBACK_INIT		{ 0, 0, 0, 0x00000001U }
406*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
407*7c478bd9Sstevel@tonic-gate #define	IN6ADDR_LOOPBACK_INIT		{ 0, 0, 0, 0x01000000U }
408*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
409*7c478bd9Sstevel@tonic-gate 
410*7c478bd9Sstevel@tonic-gate #else
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate #define	IN6ADDR_ANY_INIT	    {	0, 0, 0, 0,	\
413*7c478bd9Sstevel@tonic-gate 					0, 0, 0, 0,	\
414*7c478bd9Sstevel@tonic-gate 					0, 0, 0, 0, 	\
415*7c478bd9Sstevel@tonic-gate 					0, 0, 0, 0 }
416*7c478bd9Sstevel@tonic-gate 
417*7c478bd9Sstevel@tonic-gate #define	IN6ADDR_LOOPBACK_INIT	    {	0, 0, 0, 0,	\
418*7c478bd9Sstevel@tonic-gate 					0, 0, 0, 0,	\
419*7c478bd9Sstevel@tonic-gate 					0, 0, 0, 0,	\
420*7c478bd9Sstevel@tonic-gate 					0, 0, 0, 0x1U }
421*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
422*7c478bd9Sstevel@tonic-gate 
423*7c478bd9Sstevel@tonic-gate /*
424*7c478bd9Sstevel@tonic-gate  * RFC 2553 specifies the following macros. Their type is defined
425*7c478bd9Sstevel@tonic-gate  * as "int" in the RFC but they only have boolean significance
426*7c478bd9Sstevel@tonic-gate  * (zero or non-zero). For the purposes of our comment notation,
427*7c478bd9Sstevel@tonic-gate  * we assume a hypothetical type "bool" defined as follows to
428*7c478bd9Sstevel@tonic-gate  * write the prototypes assumed for macros in our comments better.
429*7c478bd9Sstevel@tonic-gate  *
430*7c478bd9Sstevel@tonic-gate  * typedef int bool;
431*7c478bd9Sstevel@tonic-gate  */
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate /*
434*7c478bd9Sstevel@tonic-gate  * IN6 macros used to test for special IPv6 addresses
435*7c478bd9Sstevel@tonic-gate  * (Mostly from spec)
436*7c478bd9Sstevel@tonic-gate  *
437*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_UNSPECIFIED (const struct in6_addr *);
438*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_LOOPBACK    (const struct in6_addr *);
439*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MULTICAST   (const struct in6_addr *);
440*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_LINKLOCAL   (const struct in6_addr *);
441*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_SITELOCAL   (const struct in6_addr *);
442*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_V4MAPPED    (const struct in6_addr *);
443*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_V4MAPPED_ANY(const struct in6_addr *); -- Not from RFC2553
444*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_V4COMPAT    (const struct in6_addr *);
445*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MC_RESERVED (const struct in6_addr *); -- Not from RFC2553
446*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *);
447*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *);
448*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *);
449*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MC_ORGLOCAL (const struct in6_addr *);
450*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_MC_GLOBAL   (const struct in6_addr *);
451*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_6TO4	 (const struct in6_addr *); -- Not from RFC2553
452*7c478bd9Sstevel@tonic-gate  * bool  IN6_ARE_6TO4_PREFIX_EQUAL(const struct in6_addr *,
453*7c478bd9Sstevel@tonic-gate  *	     const struct in6_addr *);			    -- Not from RFC2553
454*7c478bd9Sstevel@tonic-gate  * bool  IN6_IS_ADDR_LINKSCOPE	 (const struct in6addr  *); -- Not from RFC2553
455*7c478bd9Sstevel@tonic-gate  */
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_UNSPECIFIED(addr) \
458*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[3] == 0) && \
459*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[2] == 0) && \
460*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
461*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
462*7c478bd9Sstevel@tonic-gate 
463*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
464*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_LOOPBACK(addr) \
465*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[3] == 0x00000001) && \
466*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[2] == 0) && \
467*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
468*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
469*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
470*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_LOOPBACK(addr) \
471*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[3] == 0x01000000) && \
472*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[2] == 0) && \
473*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
474*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
475*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
476*7c478bd9Sstevel@tonic-gate 
477*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
478*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MULTICAST(addr) \
479*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff000000) == 0xff000000)
480*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
481*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MULTICAST(addr) \
482*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x000000ff) == 0x000000ff)
483*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
484*7c478bd9Sstevel@tonic-gate 
485*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
486*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_LINKLOCAL(addr) \
487*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfe800000)
488*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
489*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_LINKLOCAL(addr) \
490*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x000080fe)
491*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
492*7c478bd9Sstevel@tonic-gate 
493*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
494*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_SITELOCAL(addr) \
495*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfec00000)
496*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
497*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_SITELOCAL(addr) \
498*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x0000c0fe)
499*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
500*7c478bd9Sstevel@tonic-gate 
501*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
502*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4MAPPED(addr) \
503*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
504*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
505*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
506*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
507*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4MAPPED(addr) \
508*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
509*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
510*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
511*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate /*
514*7c478bd9Sstevel@tonic-gate  * IN6_IS_ADDR_V4MAPPED - A IPv4 mapped INADDR_ANY
515*7c478bd9Sstevel@tonic-gate  * Note: This macro is currently NOT defined in RFC2553 specification
516*7c478bd9Sstevel@tonic-gate  * and not a standard macro that portable applications should use.
517*7c478bd9Sstevel@tonic-gate  */
518*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
519*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4MAPPED_ANY(addr) \
520*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[3] == 0) && \
521*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \
522*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
523*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
524*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
525*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4MAPPED_ANY(addr) \
526*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[3] == 0) && \
527*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \
528*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
529*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0))
530*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
531*7c478bd9Sstevel@tonic-gate 
532*7c478bd9Sstevel@tonic-gate /* Exclude loopback and unspecified address */
533*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
534*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4COMPAT(addr) \
535*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[2] == 0) && \
536*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
537*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0) && \
538*7c478bd9Sstevel@tonic-gate 	!((addr)->_S6_un._S6_u32[3] == 0) && \
539*7c478bd9Sstevel@tonic-gate 	!((addr)->_S6_un._S6_u32[3] == 0x00000001))
540*7c478bd9Sstevel@tonic-gate 
541*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
542*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_V4COMPAT(addr) \
543*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[2] == 0) && \
544*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[1] == 0) && \
545*7c478bd9Sstevel@tonic-gate 	((addr)->_S6_un._S6_u32[0] == 0) && \
546*7c478bd9Sstevel@tonic-gate 	!((addr)->_S6_un._S6_u32[3] == 0) && \
547*7c478bd9Sstevel@tonic-gate 	!((addr)->_S6_un._S6_u32[3] == 0x01000000))
548*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
549*7c478bd9Sstevel@tonic-gate 
550*7c478bd9Sstevel@tonic-gate /*
551*7c478bd9Sstevel@tonic-gate  * Note:
552*7c478bd9Sstevel@tonic-gate  * IN6_IS_ADDR_MC_RESERVED macro is currently NOT defined in RFC2553
553*7c478bd9Sstevel@tonic-gate  * specification and not a standard macro that portable applications
554*7c478bd9Sstevel@tonic-gate  * should use.
555*7c478bd9Sstevel@tonic-gate  */
556*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
557*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_RESERVED(addr) \
558*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff000000)
559*7c478bd9Sstevel@tonic-gate 
560*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
561*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_RESERVED(addr) \
562*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000000ff)
563*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
564*7c478bd9Sstevel@tonic-gate 
565*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
566*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_NODELOCAL(addr) \
567*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff010000)
568*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
569*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_NODELOCAL(addr) \
570*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000001ff)
571*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
572*7c478bd9Sstevel@tonic-gate 
573*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
574*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_LINKLOCAL(addr) \
575*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff020000)
576*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
577*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_LINKLOCAL(addr) \
578*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000002ff)
579*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
580*7c478bd9Sstevel@tonic-gate 
581*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
582*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_SITELOCAL(addr) \
583*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff050000)
584*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
585*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_SITELOCAL(addr) \
586*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000005ff)
587*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
588*7c478bd9Sstevel@tonic-gate 
589*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
590*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_ORGLOCAL(addr) \
591*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff080000)
592*7c478bd9Sstevel@tonic-gate #else  /* _BIG_ENDIAN */
593*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_ORGLOCAL(addr) \
594*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000008ff)
595*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
596*7c478bd9Sstevel@tonic-gate 
597*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
598*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_GLOBAL(addr) \
599*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff0e0000)
600*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
601*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_MC_GLOBAL(addr) \
602*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x00000eff)
603*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
604*7c478bd9Sstevel@tonic-gate 
605*7c478bd9Sstevel@tonic-gate /*
606*7c478bd9Sstevel@tonic-gate  * Macros to a) test for 6to4 IPv6 address, and b) to test if two
607*7c478bd9Sstevel@tonic-gate  * 6to4 addresses have the same /48 prefix, and, hence, are from the
608*7c478bd9Sstevel@tonic-gate  * same 6to4 site.
609*7c478bd9Sstevel@tonic-gate  */
610*7c478bd9Sstevel@tonic-gate 
611*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
612*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_6TO4(addr) \
613*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0xffff0000) == 0x20020000)
614*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
615*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_6TO4(addr) \
616*7c478bd9Sstevel@tonic-gate 	(((addr)->_S6_un._S6_u32[0] & 0x0000ffff) == 0x00000220)
617*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate #define	IN6_ARE_6TO4_PREFIX_EQUAL(addr1, addr2) \
620*7c478bd9Sstevel@tonic-gate 	(((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0]) && \
621*7c478bd9Sstevel@tonic-gate 	((addr1)->_S6_un._S6_u8[4] == (addr2)->_S6_un._S6_u8[4]) && \
622*7c478bd9Sstevel@tonic-gate 	((addr1)->_S6_un._S6_u8[5] == (addr2)->_S6_un._S6_u8[5]))
623*7c478bd9Sstevel@tonic-gate 
624*7c478bd9Sstevel@tonic-gate /*
625*7c478bd9Sstevel@tonic-gate  * IN6_IS_ADDR_LINKSCOPE
626*7c478bd9Sstevel@tonic-gate  * Identifies an address as being either link-local, link-local multicast or
627*7c478bd9Sstevel@tonic-gate  * node-local multicast.  All types of addresses are considered to be unique
628*7c478bd9Sstevel@tonic-gate  * within the scope of a given link.
629*7c478bd9Sstevel@tonic-gate  */
630*7c478bd9Sstevel@tonic-gate #define	IN6_IS_ADDR_LINKSCOPE(addr) \
631*7c478bd9Sstevel@tonic-gate 	(IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr) || \
632*7c478bd9Sstevel@tonic-gate 	IN6_IS_ADDR_MC_NODELOCAL(addr))
633*7c478bd9Sstevel@tonic-gate 
634*7c478bd9Sstevel@tonic-gate /*
635*7c478bd9Sstevel@tonic-gate  * Useful utility macros for operations with IPv6 addresses
636*7c478bd9Sstevel@tonic-gate  * Note: These macros are NOT defined in the RFC2553 or any other
637*7c478bd9Sstevel@tonic-gate  * standard specification and are not standard macros that portable
638*7c478bd9Sstevel@tonic-gate  * applications should use.
639*7c478bd9Sstevel@tonic-gate  */
640*7c478bd9Sstevel@tonic-gate 
641*7c478bd9Sstevel@tonic-gate /*
642*7c478bd9Sstevel@tonic-gate  * IN6_V4MAPPED_TO_INADDR
643*7c478bd9Sstevel@tonic-gate  * IN6_V4MAPPED_TO_IPADDR
644*7c478bd9Sstevel@tonic-gate  *	Assign a IPv4-Mapped IPv6 address to an IPv4 address.
645*7c478bd9Sstevel@tonic-gate  *	Note: These macros are NOT defined in RFC2553 or any other standard
646*7c478bd9Sstevel@tonic-gate  *	specification and are not macros that portable applications should
647*7c478bd9Sstevel@tonic-gate  *	use.
648*7c478bd9Sstevel@tonic-gate  *
649*7c478bd9Sstevel@tonic-gate  * void IN6_V4MAPPED_TO_INADDR(const in6_addr_t *v6, struct in_addr *v4);
650*7c478bd9Sstevel@tonic-gate  * void IN6_V4MAPPED_TO_IPADDR(const in6_addr_t *v6, ipaddr_t v4);
651*7c478bd9Sstevel@tonic-gate  *
652*7c478bd9Sstevel@tonic-gate  */
653*7c478bd9Sstevel@tonic-gate #define	IN6_V4MAPPED_TO_INADDR(v6, v4) \
654*7c478bd9Sstevel@tonic-gate 	((v4)->s_addr = (v6)->_S6_un._S6_u32[3])
655*7c478bd9Sstevel@tonic-gate #define	IN6_V4MAPPED_TO_IPADDR(v6, v4) \
656*7c478bd9Sstevel@tonic-gate 	((v4) = (v6)->_S6_un._S6_u32[3])
657*7c478bd9Sstevel@tonic-gate 
658*7c478bd9Sstevel@tonic-gate /*
659*7c478bd9Sstevel@tonic-gate  * IN6_INADDR_TO_V4MAPPED
660*7c478bd9Sstevel@tonic-gate  * IN6_IPADDR_TO_V4MAPPED
661*7c478bd9Sstevel@tonic-gate  *	Assign a IPv4 address address to an IPv6 address as a IPv4-mapped
662*7c478bd9Sstevel@tonic-gate  *	address.
663*7c478bd9Sstevel@tonic-gate  *	Note: These macros are NOT defined in RFC2553 or any other standard
664*7c478bd9Sstevel@tonic-gate  *	specification and are not macros that portable applications should
665*7c478bd9Sstevel@tonic-gate  *	use.
666*7c478bd9Sstevel@tonic-gate  *
667*7c478bd9Sstevel@tonic-gate  * void IN6_INADDR_TO_V4MAPPED(const struct in_addr *v4, in6_addr_t *v6);
668*7c478bd9Sstevel@tonic-gate  * void IN6_IPADDR_TO_V4MAPPED(const ipaddr_t v4, in6_addr_t *v6);
669*7c478bd9Sstevel@tonic-gate  *
670*7c478bd9Sstevel@tonic-gate  */
671*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
672*7c478bd9Sstevel@tonic-gate #define	IN6_INADDR_TO_V4MAPPED(v4, v6) \
673*7c478bd9Sstevel@tonic-gate 	((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \
674*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[2] = 0x0000ffff, \
675*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[1] = 0, \
676*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[0] = 0)
677*7c478bd9Sstevel@tonic-gate #define	IN6_IPADDR_TO_V4MAPPED(v4, v6) \
678*7c478bd9Sstevel@tonic-gate 	((v6)->_S6_un._S6_u32[3] = (v4), \
679*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[2] = 0x0000ffff, \
680*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[1] = 0, \
681*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[0] = 0)
682*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
683*7c478bd9Sstevel@tonic-gate #define	IN6_INADDR_TO_V4MAPPED(v4, v6) \
684*7c478bd9Sstevel@tonic-gate 	((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \
685*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[2] = 0xffff0000U, \
686*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[1] = 0, \
687*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[0] = 0)
688*7c478bd9Sstevel@tonic-gate #define	IN6_IPADDR_TO_V4MAPPED(v4, v6) \
689*7c478bd9Sstevel@tonic-gate 	((v6)->_S6_un._S6_u32[3] = (v4), \
690*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[2] = 0xffff0000U, \
691*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[1] = 0, \
692*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[0] = 0)
693*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
694*7c478bd9Sstevel@tonic-gate 
695*7c478bd9Sstevel@tonic-gate /*
696*7c478bd9Sstevel@tonic-gate  * IN6_6TO4_TO_V4ADDR
697*7c478bd9Sstevel@tonic-gate  *	Extract the embedded IPv4 address from the prefix to a 6to4 IPv6
698*7c478bd9Sstevel@tonic-gate  *      address.
699*7c478bd9Sstevel@tonic-gate  *	Note: This macro is NOT defined in RFC2553 or any other standard
700*7c478bd9Sstevel@tonic-gate  *	specification and is not a macro that portable applications should
701*7c478bd9Sstevel@tonic-gate  *	use.
702*7c478bd9Sstevel@tonic-gate  *	Note: we don't use the IPADDR form of the macro because we need
703*7c478bd9Sstevel@tonic-gate  *	to do a bytewise copy; the V4ADDR in the 6to4 address is not
704*7c478bd9Sstevel@tonic-gate  *	32-bit aligned.
705*7c478bd9Sstevel@tonic-gate  *
706*7c478bd9Sstevel@tonic-gate  * void IN6_6TO4_TO_V4ADDR(const in6_addr_t *v6, struct in_addr *v4);
707*7c478bd9Sstevel@tonic-gate  *
708*7c478bd9Sstevel@tonic-gate  */
709*7c478bd9Sstevel@tonic-gate #define	IN6_6TO4_TO_V4ADDR(v6, v4) \
710*7c478bd9Sstevel@tonic-gate 	((v4)->_S_un._S_un_b.s_b1 = (v6)->_S6_un._S6_u8[2], \
711*7c478bd9Sstevel@tonic-gate 	(v4)->_S_un._S_un_b.s_b2 = (v6)->_S6_un._S6_u8[3],  \
712*7c478bd9Sstevel@tonic-gate 	(v4)->_S_un._S_un_b.s_b3 = (v6)->_S6_un._S6_u8[4],  \
713*7c478bd9Sstevel@tonic-gate 	(v4)->_S_un._S_un_b.s_b4 = (v6)->_S6_un._S6_u8[5])
714*7c478bd9Sstevel@tonic-gate 
715*7c478bd9Sstevel@tonic-gate /*
716*7c478bd9Sstevel@tonic-gate  * IN6_V4ADDR_TO_6TO4
717*7c478bd9Sstevel@tonic-gate  *	Given an IPv4 address and an IPv6 address for output, a 6to4 address
718*7c478bd9Sstevel@tonic-gate  *	will be created from the IPv4 Address.
719*7c478bd9Sstevel@tonic-gate  *	Note:  This method for creating 6to4 addresses is not standardized
720*7c478bd9Sstevel@tonic-gate  *	outside of Solaris.  The newly created 6to4 address will be of the form
721*7c478bd9Sstevel@tonic-gate  *	2002:<V4ADDR>:<SUBNETID>::<HOSTID>, where SUBNETID will equal 0 and
722*7c478bd9Sstevel@tonic-gate  *	HOSTID will equal 1.
723*7c478bd9Sstevel@tonic-gate  *
724*7c478bd9Sstevel@tonic-gate  * void IN6_V4ADDR_TO_6TO4(const struct in_addr *v4, in6_addr_t *v6)
725*7c478bd9Sstevel@tonic-gate  *
726*7c478bd9Sstevel@tonic-gate  */
727*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
728*7c478bd9Sstevel@tonic-gate #define	IN6_V4ADDR_TO_6TO4(v4, v6) \
729*7c478bd9Sstevel@tonic-gate 	((v6)->_S6_un._S6_u8[0] = 0x20, \
730*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[1] = 0x02, \
731*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \
732*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \
733*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \
734*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \
735*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[6] = 0, \
736*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[7] = 0, \
737*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[2] = 0, \
738*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[3] = 0x00000001U)
739*7c478bd9Sstevel@tonic-gate #else
740*7c478bd9Sstevel@tonic-gate #define	IN6_V4ADDR_TO_6TO4(v4, v6) \
741*7c478bd9Sstevel@tonic-gate 	((v6)->_S6_un._S6_u8[0] = 0x20, \
742*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[1] = 0x02, \
743*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \
744*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \
745*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \
746*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \
747*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[6] = 0, \
748*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u8[7] = 0, \
749*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[2] = 0, \
750*7c478bd9Sstevel@tonic-gate 	(v6)->_S6_un._S6_u32[3] = 0x01000000U)
751*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
752*7c478bd9Sstevel@tonic-gate 
753*7c478bd9Sstevel@tonic-gate /*
754*7c478bd9Sstevel@tonic-gate  * IN6_ARE_ADDR_EQUAL (defined in RFC2292)
755*7c478bd9Sstevel@tonic-gate  *	 Compares if IPv6 addresses are equal.
756*7c478bd9Sstevel@tonic-gate  * Note: Compares in order of high likelyhood of a miss so we minimize
757*7c478bd9Sstevel@tonic-gate  * compares. (Current heuristic order, compare in reverse order of
758*7c478bd9Sstevel@tonic-gate  * uint32_t units)
759*7c478bd9Sstevel@tonic-gate  *
760*7c478bd9Sstevel@tonic-gate  * bool  IN6_ARE_ADDR_EQUAL(const struct in6_addr *,
761*7c478bd9Sstevel@tonic-gate  *			    const struct in6_addr *);
762*7c478bd9Sstevel@tonic-gate  */
763*7c478bd9Sstevel@tonic-gate #define	IN6_ARE_ADDR_EQUAL(addr1, addr2) \
764*7c478bd9Sstevel@tonic-gate 	(((addr1)->_S6_un._S6_u32[3] == (addr2)->_S6_un._S6_u32[3]) && \
765*7c478bd9Sstevel@tonic-gate 	((addr1)->_S6_un._S6_u32[2] == (addr2)->_S6_un._S6_u32[2]) && \
766*7c478bd9Sstevel@tonic-gate 	((addr1)->_S6_un._S6_u32[1] == (addr2)->_S6_un._S6_u32[1]) && \
767*7c478bd9Sstevel@tonic-gate 	((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0]))
768*7c478bd9Sstevel@tonic-gate 
769*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
770*7c478bd9Sstevel@tonic-gate 
771*7c478bd9Sstevel@tonic-gate 
772*7c478bd9Sstevel@tonic-gate /*
773*7c478bd9Sstevel@tonic-gate  * Options for use with [gs]etsockopt at the IP level.
774*7c478bd9Sstevel@tonic-gate  *
775*7c478bd9Sstevel@tonic-gate  * Note: Some of the IP_ namespace has conflict with and
776*7c478bd9Sstevel@tonic-gate  * and is exposed through <xti.h>. (It also requires exposing
777*7c478bd9Sstevel@tonic-gate  * options not implemented). The options with potential
778*7c478bd9Sstevel@tonic-gate  * for conflicts use #ifndef guards.
779*7c478bd9Sstevel@tonic-gate  */
780*7c478bd9Sstevel@tonic-gate #ifndef IP_OPTIONS
781*7c478bd9Sstevel@tonic-gate #define	IP_OPTIONS	1	/* set/get IP per-packet options   */
782*7c478bd9Sstevel@tonic-gate #endif
783*7c478bd9Sstevel@tonic-gate 
784*7c478bd9Sstevel@tonic-gate #define	IP_HDRINCL	2	/* int; header is included with data (raw) */
785*7c478bd9Sstevel@tonic-gate 
786*7c478bd9Sstevel@tonic-gate #ifndef IP_TOS
787*7c478bd9Sstevel@tonic-gate #define	IP_TOS		3	/* int; IP type of service and precedence */
788*7c478bd9Sstevel@tonic-gate #endif
789*7c478bd9Sstevel@tonic-gate 
790*7c478bd9Sstevel@tonic-gate #ifndef IP_TTL
791*7c478bd9Sstevel@tonic-gate #define	IP_TTL		4	/* int; IP time to live */
792*7c478bd9Sstevel@tonic-gate #endif
793*7c478bd9Sstevel@tonic-gate 
794*7c478bd9Sstevel@tonic-gate #define	IP_RECVOPTS	0x5	/* int; receive all IP options w/datagram */
795*7c478bd9Sstevel@tonic-gate #define	IP_RECVRETOPTS	0x6	/* int; receive IP options for response */
796*7c478bd9Sstevel@tonic-gate #define	IP_RECVDSTADDR	0x7	/* int; receive IP dst addr w/datagram */
797*7c478bd9Sstevel@tonic-gate #define	IP_RETOPTS	0x8	/* ip_opts; set/get IP per-packet options */
798*7c478bd9Sstevel@tonic-gate #define	IP_RECVIF	0x9	/* int; receive the inbound interface index */
799*7c478bd9Sstevel@tonic-gate #define	IP_RECVSLLA	0xa	/* sockaddr_dl; get source link layer address */
800*7c478bd9Sstevel@tonic-gate #define	IP_RECVTTL	0xb	/* uint8_t; get TTL for inbound packet */
801*7c478bd9Sstevel@tonic-gate 
802*7c478bd9Sstevel@tonic-gate #define	IP_MULTICAST_IF		0x10	/* set/get IP multicast interface  */
803*7c478bd9Sstevel@tonic-gate #define	IP_MULTICAST_TTL	0x11	/* set/get IP multicast timetolive */
804*7c478bd9Sstevel@tonic-gate #define	IP_MULTICAST_LOOP	0x12	/* set/get IP multicast loopback   */
805*7c478bd9Sstevel@tonic-gate #define	IP_ADD_MEMBERSHIP	0x13	/* add	an IP group membership	   */
806*7c478bd9Sstevel@tonic-gate #define	IP_DROP_MEMBERSHIP	0x14	/* drop an IP group membership	   */
807*7c478bd9Sstevel@tonic-gate #define	IP_BLOCK_SOURCE		0x15	/* block   mcast pkts from source  */
808*7c478bd9Sstevel@tonic-gate #define	IP_UNBLOCK_SOURCE	0x16	/* unblock mcast pkts from source  */
809*7c478bd9Sstevel@tonic-gate #define	IP_ADD_SOURCE_MEMBERSHIP  0x17	/* add  mcast group/source pair	   */
810*7c478bd9Sstevel@tonic-gate #define	IP_DROP_SOURCE_MEMBERSHIP 0x18	/* drop mcast gruop/source pair	   */
811*7c478bd9Sstevel@tonic-gate 
812*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
813*7c478bd9Sstevel@tonic-gate /*
814*7c478bd9Sstevel@tonic-gate  * Different preferences that can be requested from IPSEC protocols.
815*7c478bd9Sstevel@tonic-gate  */
816*7c478bd9Sstevel@tonic-gate #define	IP_SEC_OPT		0x22	/* Used to set IPSEC options */
817*7c478bd9Sstevel@tonic-gate #define	IPSEC_PREF_NEVER	0x01
818*7c478bd9Sstevel@tonic-gate #define	IPSEC_PREF_REQUIRED	0x02
819*7c478bd9Sstevel@tonic-gate #define	IPSEC_PREF_UNIQUE	0x04
820*7c478bd9Sstevel@tonic-gate /*
821*7c478bd9Sstevel@tonic-gate  * This can be used with the setsockopt() call to set per socket security
822*7c478bd9Sstevel@tonic-gate  * options. When the application uses per-socket API, we will reflect
823*7c478bd9Sstevel@tonic-gate  * the request on both outbound and inbound packets.
824*7c478bd9Sstevel@tonic-gate  */
825*7c478bd9Sstevel@tonic-gate 
826*7c478bd9Sstevel@tonic-gate typedef struct ipsec_req {
827*7c478bd9Sstevel@tonic-gate 	uint_t 		ipsr_ah_req;		/* AH request */
828*7c478bd9Sstevel@tonic-gate 	uint_t 		ipsr_esp_req;		/* ESP request */
829*7c478bd9Sstevel@tonic-gate 	uint_t		ipsr_self_encap_req;	/* Self-Encap request */
830*7c478bd9Sstevel@tonic-gate 	uint8_t		ipsr_auth_alg;		/* Auth algs for AH */
831*7c478bd9Sstevel@tonic-gate 	uint8_t		ipsr_esp_alg;		/* Encr algs for ESP */
832*7c478bd9Sstevel@tonic-gate 	uint8_t		ipsr_esp_auth_alg;	/* Auth algs for ESP */
833*7c478bd9Sstevel@tonic-gate } ipsec_req_t;
834*7c478bd9Sstevel@tonic-gate 
835*7c478bd9Sstevel@tonic-gate /*
836*7c478bd9Sstevel@tonic-gate  * MCAST_* options are protocol-independent.  The actual definitions
837*7c478bd9Sstevel@tonic-gate  * are with the v6 options below; this comment is here to note the
838*7c478bd9Sstevel@tonic-gate  * namespace usage.
839*7c478bd9Sstevel@tonic-gate  *
840*7c478bd9Sstevel@tonic-gate  * #define	MCAST_JOIN_GROUP	0x29
841*7c478bd9Sstevel@tonic-gate  * #define	MCAST_LEAVE_GROUP	0x2a
842*7c478bd9Sstevel@tonic-gate  * #define	MCAST_BLOCK_SOURCE	0x2b
843*7c478bd9Sstevel@tonic-gate  * #define	MCAST_UNBLOCK_SOURCE	0x2c
844*7c478bd9Sstevel@tonic-gate  * #define	MCAST_JOIN_SOURCE_GROUP	0x2d
845*7c478bd9Sstevel@tonic-gate  * #define	MCAST_LEAVE_SOURCE_GROUP 0x2e
846*7c478bd9Sstevel@tonic-gate  */
847*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
848*7c478bd9Sstevel@tonic-gate 
849*7c478bd9Sstevel@tonic-gate /*
850*7c478bd9Sstevel@tonic-gate  * SunOS private (potentially not portable) IP_ option names
851*7c478bd9Sstevel@tonic-gate  */
852*7c478bd9Sstevel@tonic-gate #define	IP_BOUND_IF		0x41	/* bind socket to an ifindex	   */
853*7c478bd9Sstevel@tonic-gate #define	IP_UNSPEC_SRC		0x42	/* use unspecified source address   */
854*7c478bd9Sstevel@tonic-gate /*
855*7c478bd9Sstevel@tonic-gate  * IP_XMIT_IF is used to send unicast/multicast packets through the specified
856*7c478bd9Sstevel@tonic-gate  * interface without looking at the routing table entries.
857*7c478bd9Sstevel@tonic-gate  * This is a Sun private interface.
858*7c478bd9Sstevel@tonic-gate  */
859*7c478bd9Sstevel@tonic-gate #define	IP_XMIT_IF		0x43	/* use specified outgoing interface */
860*7c478bd9Sstevel@tonic-gate /*
861*7c478bd9Sstevel@tonic-gate  * IP_DONTFAILOVER_IF option is used to indicate that outbound unicast and
862*7c478bd9Sstevel@tonic-gate  * multicast packets go through the specified interface, no load spreading,
863*7c478bd9Sstevel@tonic-gate  * no failover.
864*7c478bd9Sstevel@tonic-gate  * This is a Sun private interface.
865*7c478bd9Sstevel@tonic-gate  */
866*7c478bd9Sstevel@tonic-gate #define	IP_DONTFAILOVER_IF	0x44
867*7c478bd9Sstevel@tonic-gate 
868*7c478bd9Sstevel@tonic-gate /*
869*7c478bd9Sstevel@tonic-gate  * Option values and names (when !_XPG5) shared with <xti_inet.h>
870*7c478bd9Sstevel@tonic-gate  */
871*7c478bd9Sstevel@tonic-gate #ifndef IP_REUSEADDR
872*7c478bd9Sstevel@tonic-gate #define	IP_REUSEADDR		0x104
873*7c478bd9Sstevel@tonic-gate #endif
874*7c478bd9Sstevel@tonic-gate 
875*7c478bd9Sstevel@tonic-gate #ifndef IP_DONTROUTE
876*7c478bd9Sstevel@tonic-gate #define	IP_DONTROUTE		0x105
877*7c478bd9Sstevel@tonic-gate #endif
878*7c478bd9Sstevel@tonic-gate 
879*7c478bd9Sstevel@tonic-gate #ifndef IP_BROADCAST
880*7c478bd9Sstevel@tonic-gate #define	IP_BROADCAST		0x106
881*7c478bd9Sstevel@tonic-gate #endif
882*7c478bd9Sstevel@tonic-gate 
883*7c478bd9Sstevel@tonic-gate /*
884*7c478bd9Sstevel@tonic-gate  * The following option values are reserved by <xti_inet.h>
885*7c478bd9Sstevel@tonic-gate  *
886*7c478bd9Sstevel@tonic-gate  * T_IP_OPTIONS	0x107	 -  IP per-packet options
887*7c478bd9Sstevel@tonic-gate  * T_IP_TOS	0x108	 -  IP per packet type of service
888*7c478bd9Sstevel@tonic-gate  */
889*7c478bd9Sstevel@tonic-gate 
890*7c478bd9Sstevel@tonic-gate /*
891*7c478bd9Sstevel@tonic-gate  * Default value constants for multicast attributes controlled by
892*7c478bd9Sstevel@tonic-gate  * IP*_MULTICAST_LOOP and IP*_MULTICAST_{TTL,HOPS} options.
893*7c478bd9Sstevel@tonic-gate  */
894*7c478bd9Sstevel@tonic-gate #define	IP_DEFAULT_MULTICAST_TTL  1	/* normally limit m'casts to 1 hop */
895*7c478bd9Sstevel@tonic-gate #define	IP_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member */
896*7c478bd9Sstevel@tonic-gate 
897*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
898*7c478bd9Sstevel@tonic-gate /*
899*7c478bd9Sstevel@tonic-gate  * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
900*7c478bd9Sstevel@tonic-gate  */
901*7c478bd9Sstevel@tonic-gate struct ip_mreq {
902*7c478bd9Sstevel@tonic-gate 	struct in_addr	imr_multiaddr;	/* IP multicast address of group */
903*7c478bd9Sstevel@tonic-gate 	struct in_addr	imr_interface;	/* local IP address of interface */
904*7c478bd9Sstevel@tonic-gate };
905*7c478bd9Sstevel@tonic-gate 
906*7c478bd9Sstevel@tonic-gate /*
907*7c478bd9Sstevel@tonic-gate  * Argument structure for IP_BLOCK_SOURCE, IP_UNBLOCK_SOURCE,
908*7c478bd9Sstevel@tonic-gate  * IP_ADD_SOURCE_MEMBERSHIP, and IP_DROP_SOURCE_MEMBERSHIP.
909*7c478bd9Sstevel@tonic-gate  */
910*7c478bd9Sstevel@tonic-gate struct ip_mreq_source {
911*7c478bd9Sstevel@tonic-gate 	struct in_addr	imr_multiaddr;	/* IP address of group */
912*7c478bd9Sstevel@tonic-gate 	struct in_addr	imr_sourceaddr;	/* IP address of source */
913*7c478bd9Sstevel@tonic-gate 	struct in_addr	imr_interface;	/* IP address of interface */
914*7c478bd9Sstevel@tonic-gate };
915*7c478bd9Sstevel@tonic-gate 
916*7c478bd9Sstevel@tonic-gate /*
917*7c478bd9Sstevel@tonic-gate  * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP on
918*7c478bd9Sstevel@tonic-gate  * IPv6 addresses.
919*7c478bd9Sstevel@tonic-gate  */
920*7c478bd9Sstevel@tonic-gate struct ipv6_mreq {
921*7c478bd9Sstevel@tonic-gate 	struct in6_addr	ipv6mr_multiaddr;	/* IPv6 multicast addr */
922*7c478bd9Sstevel@tonic-gate 	unsigned int	ipv6mr_interface;	/* interface index */
923*7c478bd9Sstevel@tonic-gate };
924*7c478bd9Sstevel@tonic-gate 
925*7c478bd9Sstevel@tonic-gate /*
926*7c478bd9Sstevel@tonic-gate  * Use #pragma pack() construct to force 32-bit alignment on amd64.
927*7c478bd9Sstevel@tonic-gate  * This is needed to keep the structure size and offsets consistent
928*7c478bd9Sstevel@tonic-gate  * between a 32-bit app and the 64-bit amd64 kernel in structures
929*7c478bd9Sstevel@tonic-gate  * where 64-bit alignment would create gaps (in this case, structures
930*7c478bd9Sstevel@tonic-gate  * which have a uint32_t followed by a struct sockaddr_storage).
931*7c478bd9Sstevel@tonic-gate  */
932*7c478bd9Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
933*7c478bd9Sstevel@tonic-gate #pragma pack(4)
934*7c478bd9Sstevel@tonic-gate #endif
935*7c478bd9Sstevel@tonic-gate 
936*7c478bd9Sstevel@tonic-gate /*
937*7c478bd9Sstevel@tonic-gate  * Argument structure for MCAST_JOIN_GROUP and MCAST_LEAVE_GROUP.
938*7c478bd9Sstevel@tonic-gate  */
939*7c478bd9Sstevel@tonic-gate struct group_req {
940*7c478bd9Sstevel@tonic-gate 	uint32_t		gr_interface;	/* interface index */
941*7c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	gr_group;	/* group address */
942*7c478bd9Sstevel@tonic-gate };
943*7c478bd9Sstevel@tonic-gate 
944*7c478bd9Sstevel@tonic-gate /*
945*7c478bd9Sstevel@tonic-gate  * Argument structure for MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE,
946*7c478bd9Sstevel@tonic-gate  * MCAST_JOIN_SOURCE_GROUP, MCAST_LEAVE_SOURCE_GROUP.
947*7c478bd9Sstevel@tonic-gate  */
948*7c478bd9Sstevel@tonic-gate struct group_source_req {
949*7c478bd9Sstevel@tonic-gate 	uint32_t		gsr_interface;	/* interface index */
950*7c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	gsr_group;	/* group address */
951*7c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	gsr_source;	/* source address */
952*7c478bd9Sstevel@tonic-gate };
953*7c478bd9Sstevel@tonic-gate 
954*7c478bd9Sstevel@tonic-gate /*
955*7c478bd9Sstevel@tonic-gate  * Argument for SIOC[GS]MSFILTER ioctls
956*7c478bd9Sstevel@tonic-gate  */
957*7c478bd9Sstevel@tonic-gate struct group_filter {
958*7c478bd9Sstevel@tonic-gate 	uint32_t		gf_interface;	/* interface index */
959*7c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	gf_group;	/* multicast address */
960*7c478bd9Sstevel@tonic-gate 	uint32_t		gf_fmode;	/* filter mode */
961*7c478bd9Sstevel@tonic-gate 	uint32_t		gf_numsrc;	/* number of sources */
962*7c478bd9Sstevel@tonic-gate 	struct sockaddr_storage	gf_slist[1];	/* source address */
963*7c478bd9Sstevel@tonic-gate };
964*7c478bd9Sstevel@tonic-gate 
965*7c478bd9Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
966*7c478bd9Sstevel@tonic-gate #pragma pack()
967*7c478bd9Sstevel@tonic-gate #endif
968*7c478bd9Sstevel@tonic-gate 
969*7c478bd9Sstevel@tonic-gate #define	GROUP_FILTER_SIZE(numsrc) \
970*7c478bd9Sstevel@tonic-gate 	(sizeof (struct group_filter) - sizeof (struct sockaddr_storage) \
971*7c478bd9Sstevel@tonic-gate 	+ (numsrc) * sizeof (struct sockaddr_storage))
972*7c478bd9Sstevel@tonic-gate 
973*7c478bd9Sstevel@tonic-gate /*
974*7c478bd9Sstevel@tonic-gate  * Argument for SIOC[GS]IPMSFILTER ioctls (IPv4-specific)
975*7c478bd9Sstevel@tonic-gate  */
976*7c478bd9Sstevel@tonic-gate struct ip_msfilter {
977*7c478bd9Sstevel@tonic-gate 	struct in_addr	imsf_multiaddr;	/* IP multicast address of group */
978*7c478bd9Sstevel@tonic-gate 	struct in_addr	imsf_interface;	/* local IP address of interface */
979*7c478bd9Sstevel@tonic-gate 	uint32_t	imsf_fmode;	/* filter mode */
980*7c478bd9Sstevel@tonic-gate 	uint32_t	imsf_numsrc;	/* number of sources in src_list */
981*7c478bd9Sstevel@tonic-gate 	struct in_addr	imsf_slist[1];	/* start of source list */
982*7c478bd9Sstevel@tonic-gate };
983*7c478bd9Sstevel@tonic-gate 
984*7c478bd9Sstevel@tonic-gate #define	IP_MSFILTER_SIZE(numsrc) \
985*7c478bd9Sstevel@tonic-gate 	(sizeof (struct ip_msfilter) - sizeof (struct in_addr) \
986*7c478bd9Sstevel@tonic-gate 	+ (numsrc) * sizeof (struct in_addr))
987*7c478bd9Sstevel@tonic-gate 
988*7c478bd9Sstevel@tonic-gate /*
989*7c478bd9Sstevel@tonic-gate  * Multicast source filter manipulation functions in libsocket;
990*7c478bd9Sstevel@tonic-gate  * defined in RFC 3678.
991*7c478bd9Sstevel@tonic-gate  */
992*7c478bd9Sstevel@tonic-gate int setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t,
993*7c478bd9Sstevel@tonic-gate 			uint_t, struct sockaddr_storage *);
994*7c478bd9Sstevel@tonic-gate 
995*7c478bd9Sstevel@tonic-gate int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t *,
996*7c478bd9Sstevel@tonic-gate 			uint_t *, struct sockaddr_storage *);
997*7c478bd9Sstevel@tonic-gate 
998*7c478bd9Sstevel@tonic-gate int setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t,
999*7c478bd9Sstevel@tonic-gate 			uint32_t, struct in_addr *);
1000*7c478bd9Sstevel@tonic-gate 
1001*7c478bd9Sstevel@tonic-gate int getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *,
1002*7c478bd9Sstevel@tonic-gate 			uint32_t *, struct in_addr *);
1003*7c478bd9Sstevel@tonic-gate 
1004*7c478bd9Sstevel@tonic-gate /*
1005*7c478bd9Sstevel@tonic-gate  * Definitions needed for [gs]etsourcefilter(), [gs]etipv4sourcefilter()
1006*7c478bd9Sstevel@tonic-gate  */
1007*7c478bd9Sstevel@tonic-gate #define	MCAST_INCLUDE	1
1008*7c478bd9Sstevel@tonic-gate #define	MCAST_EXCLUDE	2
1009*7c478bd9Sstevel@tonic-gate 
1010*7c478bd9Sstevel@tonic-gate /*
1011*7c478bd9Sstevel@tonic-gate  * Argument struct for IPV6_PKTINFO option
1012*7c478bd9Sstevel@tonic-gate  */
1013*7c478bd9Sstevel@tonic-gate struct in6_pktinfo {
1014*7c478bd9Sstevel@tonic-gate 	struct in6_addr		ipi6_addr;	/* src/dst IPv6 address */
1015*7c478bd9Sstevel@tonic-gate 	unsigned int		ipi6_ifindex;	/* send/recv interface index */
1016*7c478bd9Sstevel@tonic-gate };
1017*7c478bd9Sstevel@tonic-gate 
1018*7c478bd9Sstevel@tonic-gate /*
1019*7c478bd9Sstevel@tonic-gate  * Argument struct for IPV6_MTUINFO option
1020*7c478bd9Sstevel@tonic-gate  */
1021*7c478bd9Sstevel@tonic-gate struct ip6_mtuinfo {
1022*7c478bd9Sstevel@tonic-gate 	struct sockaddr_in6	ip6m_addr; /* dst address including zone ID */
1023*7c478bd9Sstevel@tonic-gate 	uint32_t		ip6m_mtu;  /* path MTU in host byte order */
1024*7c478bd9Sstevel@tonic-gate };
1025*7c478bd9Sstevel@tonic-gate 
1026*7c478bd9Sstevel@tonic-gate /*
1027*7c478bd9Sstevel@tonic-gate  * IPv6 routing header types
1028*7c478bd9Sstevel@tonic-gate  */
1029*7c478bd9Sstevel@tonic-gate #define	IPV6_RTHDR_TYPE_0	0
1030*7c478bd9Sstevel@tonic-gate 
1031*7c478bd9Sstevel@tonic-gate extern socklen_t inet6_rth_space(int type, int segments);
1032*7c478bd9Sstevel@tonic-gate extern void *inet6_rth_init(void *bp, socklen_t bp_len, int type, int segments);
1033*7c478bd9Sstevel@tonic-gate extern int inet6_rth_add(void *bp, const struct in6_addr *addr);
1034*7c478bd9Sstevel@tonic-gate extern int inet6_rth_reverse(const void *in, void *out);
1035*7c478bd9Sstevel@tonic-gate extern int inet6_rth_segments(const void *bp);
1036*7c478bd9Sstevel@tonic-gate extern struct in6_addr *inet6_rth_getaddr(const void *bp, int index);
1037*7c478bd9Sstevel@tonic-gate 
1038*7c478bd9Sstevel@tonic-gate extern int inet6_opt_init(void *extbuf, socklen_t extlen);
1039*7c478bd9Sstevel@tonic-gate extern int inet6_opt_append(void *extbuf, socklen_t extlen, int offset,
1040*7c478bd9Sstevel@tonic-gate 	uint8_t type, socklen_t len, uint_t align, void **databufp);
1041*7c478bd9Sstevel@tonic-gate extern int inet6_opt_finish(void *extbuf, socklen_t extlen, int offset);
1042*7c478bd9Sstevel@tonic-gate extern int inet6_opt_set_val(void *databuf, int offset, void *val,
1043*7c478bd9Sstevel@tonic-gate 	socklen_t vallen);
1044*7c478bd9Sstevel@tonic-gate extern int inet6_opt_next(void *extbuf, socklen_t extlen, int offset,
1045*7c478bd9Sstevel@tonic-gate 	uint8_t *typep, socklen_t *lenp, void **databufp);
1046*7c478bd9Sstevel@tonic-gate extern int inet6_opt_find(void *extbufp, socklen_t extlen, int offset,
1047*7c478bd9Sstevel@tonic-gate 	uint8_t type, socklen_t *lenp, void **databufp);
1048*7c478bd9Sstevel@tonic-gate extern int inet6_opt_get_val(void *databuf, int offset, void *val,
1049*7c478bd9Sstevel@tonic-gate 	socklen_t vallen);
1050*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1051*7c478bd9Sstevel@tonic-gate 
1052*7c478bd9Sstevel@tonic-gate /*
1053*7c478bd9Sstevel@tonic-gate  * Argument structure for IP_ADD_PROXY_ADDR.
1054*7c478bd9Sstevel@tonic-gate  * Note that this is an unstable, experimental interface. It may change
1055*7c478bd9Sstevel@tonic-gate  * later. Don't use it unless you know what it is.
1056*7c478bd9Sstevel@tonic-gate  */
1057*7c478bd9Sstevel@tonic-gate typedef struct {
1058*7c478bd9Sstevel@tonic-gate 	struct in_addr	in_prefix_addr;
1059*7c478bd9Sstevel@tonic-gate 	unsigned int	in_prefix_len;
1060*7c478bd9Sstevel@tonic-gate } in_prefix_t;
1061*7c478bd9Sstevel@tonic-gate 
1062*7c478bd9Sstevel@tonic-gate 
1063*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1064*7c478bd9Sstevel@tonic-gate /*
1065*7c478bd9Sstevel@tonic-gate  * IPv6 options
1066*7c478bd9Sstevel@tonic-gate  */
1067*7c478bd9Sstevel@tonic-gate #define	IPV6_UNICAST_HOPS	0x5	/* hop limit value for unicast */
1068*7c478bd9Sstevel@tonic-gate 					/* packets. */
1069*7c478bd9Sstevel@tonic-gate 					/* argument type: uint_t */
1070*7c478bd9Sstevel@tonic-gate #define	IPV6_MULTICAST_IF	0x6	/* outgoing interface for */
1071*7c478bd9Sstevel@tonic-gate 					/* multicast packets. */
1072*7c478bd9Sstevel@tonic-gate 					/* argument type: struct in6_addr */
1073*7c478bd9Sstevel@tonic-gate #define	IPV6_MULTICAST_HOPS	0x7	/* hop limit value to use for */
1074*7c478bd9Sstevel@tonic-gate 					/* multicast packets. */
1075*7c478bd9Sstevel@tonic-gate 					/* argument type: uint_t */
1076*7c478bd9Sstevel@tonic-gate #define	IPV6_MULTICAST_LOOP	0x8	/* enable/disable delivery of */
1077*7c478bd9Sstevel@tonic-gate 					/* multicast packets on same socket. */
1078*7c478bd9Sstevel@tonic-gate 					/* argument type: uint_t */
1079*7c478bd9Sstevel@tonic-gate #define	IPV6_JOIN_GROUP		0x9	/* join an IPv6 multicast group. */
1080*7c478bd9Sstevel@tonic-gate 					/* argument type: struct ipv6_mreq */
1081*7c478bd9Sstevel@tonic-gate #define	IPV6_LEAVE_GROUP	0xa	/* leave an IPv6 multicast group */
1082*7c478bd9Sstevel@tonic-gate 					/* argument type: struct ipv6_mreq */
1083*7c478bd9Sstevel@tonic-gate /*
1084*7c478bd9Sstevel@tonic-gate  * IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP are being kept
1085*7c478bd9Sstevel@tonic-gate  * for backward compatibility. They have the same meaning as IPV6_JOIN_GROUP
1086*7c478bd9Sstevel@tonic-gate  * and IPV6_LEAVE_GROUP respectively.
1087*7c478bd9Sstevel@tonic-gate  */
1088*7c478bd9Sstevel@tonic-gate #define	IPV6_ADD_MEMBERSHIP	0x9	/* join an IPv6 multicast group. */
1089*7c478bd9Sstevel@tonic-gate 					/* argument type: struct ipv6_mreq */
1090*7c478bd9Sstevel@tonic-gate #define	IPV6_DROP_MEMBERSHIP	0xa	/* leave an IPv6 multicast group */
1091*7c478bd9Sstevel@tonic-gate 					/* argument type: struct ipv6_mreq */
1092*7c478bd9Sstevel@tonic-gate 
1093*7c478bd9Sstevel@tonic-gate #define	IPV6_PKTINFO		0xb	/* addr plus interface index */
1094*7c478bd9Sstevel@tonic-gate 					/* arg type: "struct in6_pktingo" - */
1095*7c478bd9Sstevel@tonic-gate #define	IPV6_HOPLIMIT		0xc	/* hoplimit for datagram */
1096*7c478bd9Sstevel@tonic-gate #define	IPV6_NEXTHOP		0xd	/* next hop address  */
1097*7c478bd9Sstevel@tonic-gate #define	IPV6_HOPOPTS		0xe	/* hop by hop options */
1098*7c478bd9Sstevel@tonic-gate #define	IPV6_DSTOPTS		0xf	/* destination options - after */
1099*7c478bd9Sstevel@tonic-gate 					/* the routing header */
1100*7c478bd9Sstevel@tonic-gate #define	IPV6_RTHDR		0x10	/* routing header  */
1101*7c478bd9Sstevel@tonic-gate #define	IPV6_RTHDRDSTOPTS	0x11	/* destination options - before */
1102*7c478bd9Sstevel@tonic-gate 					/* the routing header */
1103*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVPKTINFO	0x12	/* enable/disable IPV6_PKTINFO */
1104*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVHOPLIMIT	0x13	/* enable/disable IPV6_HOPLIMIT */
1105*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVHOPOPTS	0x14	/* enable/disable IPV6_HOPOPTS */
1106*7c478bd9Sstevel@tonic-gate 
1107*7c478bd9Sstevel@tonic-gate /*
1108*7c478bd9Sstevel@tonic-gate  * This options exists for backwards compatability and should no longer be
1109*7c478bd9Sstevel@tonic-gate  * used.  Use IPV6_RECVDSTOPTS instead.
1110*7c478bd9Sstevel@tonic-gate  */
1111*7c478bd9Sstevel@tonic-gate #define	_OLD_IPV6_RECVDSTOPTS	0x15
1112*7c478bd9Sstevel@tonic-gate 
1113*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVRTHDR		0x16	/* enable/disable IPV6_RTHDR */
1114*7c478bd9Sstevel@tonic-gate 
1115*7c478bd9Sstevel@tonic-gate /*
1116*7c478bd9Sstevel@tonic-gate  * enable/disable IPV6_RTHDRDSTOPTS.  Now obsolete.  IPV6_RECVDSTOPTS enables
1117*7c478bd9Sstevel@tonic-gate  * the receipt of both headers.
1118*7c478bd9Sstevel@tonic-gate  */
1119*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVRTHDRDSTOPTS	0x17
1120*7c478bd9Sstevel@tonic-gate 
1121*7c478bd9Sstevel@tonic-gate #define	IPV6_CHECKSUM		0x18	/* Control checksum on raw sockets */
1122*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVTCLASS		0x19	/* enable/disable IPV6_CLASS */
1123*7c478bd9Sstevel@tonic-gate #define	IPV6_USE_MIN_MTU	0x20	/* send packets with minimum MTU */
1124*7c478bd9Sstevel@tonic-gate #define	IPV6_DONTFRAG		0x21	/* don't fragment packets */
1125*7c478bd9Sstevel@tonic-gate #define	IPV6_SEC_OPT		0x22	/* Used to set IPSEC options */
1126*7c478bd9Sstevel@tonic-gate #define	IPV6_SRC_PREFERENCES	0x23	/* Control socket's src addr select */
1127*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVPATHMTU	0x24	/* receive PMTU info */
1128*7c478bd9Sstevel@tonic-gate #define	IPV6_PATHMTU		0x25	/* get the PMTU */
1129*7c478bd9Sstevel@tonic-gate #define	IPV6_TCLASS		0x26	/* traffic class */
1130*7c478bd9Sstevel@tonic-gate #define	IPV6_V6ONLY		0x27	/* v6 only socket option */
1131*7c478bd9Sstevel@tonic-gate 
1132*7c478bd9Sstevel@tonic-gate /*
1133*7c478bd9Sstevel@tonic-gate  * enable/disable receipt of both both IPV6_DSTOPTS headers.
1134*7c478bd9Sstevel@tonic-gate  */
1135*7c478bd9Sstevel@tonic-gate #define	IPV6_RECVDSTOPTS	0x28
1136*7c478bd9Sstevel@tonic-gate 
1137*7c478bd9Sstevel@tonic-gate /*
1138*7c478bd9Sstevel@tonic-gate  * protocol-independent multicast membership options.
1139*7c478bd9Sstevel@tonic-gate  */
1140*7c478bd9Sstevel@tonic-gate #define	MCAST_JOIN_GROUP	0x29	/* join group for all sources */
1141*7c478bd9Sstevel@tonic-gate #define	MCAST_LEAVE_GROUP	0x2a	/* leave group */
1142*7c478bd9Sstevel@tonic-gate #define	MCAST_BLOCK_SOURCE	0x2b	/* block specified source */
1143*7c478bd9Sstevel@tonic-gate #define	MCAST_UNBLOCK_SOURCE	0x2c	/* unblock specified source */
1144*7c478bd9Sstevel@tonic-gate #define	MCAST_JOIN_SOURCE_GROUP	0x2d	/* join group for specified source */
1145*7c478bd9Sstevel@tonic-gate #define	MCAST_LEAVE_SOURCE_GROUP 0x2e	/* leave source/group pair */
1146*7c478bd9Sstevel@tonic-gate 
1147*7c478bd9Sstevel@tonic-gate /* 32Bit field for IPV6_SRC_PREFERENCES */
1148*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_HOME		0x00000001
1149*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_COA		0x00000002
1150*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_PUBLIC		0x00000004
1151*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_TMP		0x00000008
1152*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_NONCGA		0x00000010
1153*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_CGA		0x00000020
1154*7c478bd9Sstevel@tonic-gate 
1155*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_MIPMASK	(IPV6_PREFER_SRC_HOME | IPV6_PREFER_SRC_COA)
1156*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_MIPDEFAULT	IPV6_PREFER_SRC_HOME
1157*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_TMPMASK	(IPV6_PREFER_SRC_PUBLIC | IPV6_PREFER_SRC_TMP)
1158*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_TMPDEFAULT	IPV6_PREFER_SRC_PUBLIC
1159*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_CGAMASK	(IPV6_PREFER_SRC_NONCGA | IPV6_PREFER_SRC_CGA)
1160*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_CGADEFAULT	IPV6_PREFER_SRC_NONCGA
1161*7c478bd9Sstevel@tonic-gate 
1162*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_MASK (IPV6_PREFER_SRC_MIPMASK |\
1163*7c478bd9Sstevel@tonic-gate 	IPV6_PREFER_SRC_TMPMASK | IPV6_PREFER_SRC_CGAMASK)
1164*7c478bd9Sstevel@tonic-gate 
1165*7c478bd9Sstevel@tonic-gate #define	IPV6_PREFER_SRC_DEFAULT	(IPV6_PREFER_SRC_MIPDEFAULT |\
1166*7c478bd9Sstevel@tonic-gate 	IPV6_PREFER_SRC_TMPDEFAULT | IPV6_PREFER_SRC_CGADEFAULT)
1167*7c478bd9Sstevel@tonic-gate 
1168*7c478bd9Sstevel@tonic-gate /*
1169*7c478bd9Sstevel@tonic-gate  * SunOS private (potentially not portable) IPV6_ option names
1170*7c478bd9Sstevel@tonic-gate  */
1171*7c478bd9Sstevel@tonic-gate #define	IPV6_BOUND_IF		0x41	/* bind to an ifindex */
1172*7c478bd9Sstevel@tonic-gate #define	IPV6_UNSPEC_SRC		0x42	/* source of packets set to */
1173*7c478bd9Sstevel@tonic-gate 					/* unspecified (all zeros) */
1174*7c478bd9Sstevel@tonic-gate #define	IPV6_BOUND_PIF		0x43	/* Bind to Physical interface */
1175*7c478bd9Sstevel@tonic-gate 					/* No load balancing or failover */
1176*7c478bd9Sstevel@tonic-gate /*
1177*7c478bd9Sstevel@tonic-gate  * IPV6_DONTFAILOVER_IF option is used to indicate that outbound unicast and
1178*7c478bd9Sstevel@tonic-gate  * multicast packets go through the specified interface, no load spreading,
1179*7c478bd9Sstevel@tonic-gate  * no failover.
1180*7c478bd9Sstevel@tonic-gate  * This is a Sun private interface.
1181*7c478bd9Sstevel@tonic-gate  */
1182*7c478bd9Sstevel@tonic-gate #define	IPV6_DONTFAILOVER_IF	0x44
1183*7c478bd9Sstevel@tonic-gate 
1184*7c478bd9Sstevel@tonic-gate /*
1185*7c478bd9Sstevel@tonic-gate  * Miscellaneous IPv6 constants.
1186*7c478bd9Sstevel@tonic-gate  */
1187*7c478bd9Sstevel@tonic-gate #define	INET_ADDRSTRLEN		16	/* max len IPv4 addr in ascii dotted */
1188*7c478bd9Sstevel@tonic-gate 					/* decimal notation. */
1189*7c478bd9Sstevel@tonic-gate #define	INET6_ADDRSTRLEN	46	/* max len of IPv6 addr in ascii */
1190*7c478bd9Sstevel@tonic-gate 					/* standard colon-hex notation. */
1191*7c478bd9Sstevel@tonic-gate #define	IPV6_PAD1_OPT		0	/* pad byte in IPv6 extension hdrs */
1192*7c478bd9Sstevel@tonic-gate 
1193*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1194*7c478bd9Sstevel@tonic-gate 
1195*7c478bd9Sstevel@tonic-gate /*
1196*7c478bd9Sstevel@tonic-gate  * Extern declarations for pre-defined global const variables
1197*7c478bd9Sstevel@tonic-gate  */
1198*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1199*7c478bd9Sstevel@tonic-gate #ifndef _KERNEL
1200*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
1201*7c478bd9Sstevel@tonic-gate extern const struct in6_addr in6addr_any;
1202*7c478bd9Sstevel@tonic-gate extern const struct in6_addr in6addr_loopback;
1203*7c478bd9Sstevel@tonic-gate #else
1204*7c478bd9Sstevel@tonic-gate extern struct in6_addr in6addr_any;
1205*7c478bd9Sstevel@tonic-gate extern struct in6_addr in6addr_loopback;
1206*7c478bd9Sstevel@tonic-gate #endif
1207*7c478bd9Sstevel@tonic-gate #endif
1208*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1209*7c478bd9Sstevel@tonic-gate 
1210*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1211*7c478bd9Sstevel@tonic-gate }
1212*7c478bd9Sstevel@tonic-gate #endif
1213*7c478bd9Sstevel@tonic-gate 
1214*7c478bd9Sstevel@tonic-gate #endif	/* _NETINET_IN_H */
1215