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