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