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