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