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