17c478bd9Sstevel@tonic-gate /* 2e11c3f44Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 49b241b4eSYuri Pankov * 59b241b4eSYuri Pankov * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 67c478bd9Sstevel@tonic-gate */ 77c478bd9Sstevel@tonic-gate /* 87c478bd9Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 97c478bd9Sstevel@tonic-gate * All rights reserved. 107c478bd9Sstevel@tonic-gate * 117c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms are permitted 127c478bd9Sstevel@tonic-gate * provided that this notice is preserved and that due credit is given 137c478bd9Sstevel@tonic-gate * to the University of California at Berkeley. The name of the University 147c478bd9Sstevel@tonic-gate * may not be used to endorse or promote products derived from this 157c478bd9Sstevel@tonic-gate * software without specific prior written permission. This software 167c478bd9Sstevel@tonic-gate * is provided ``as is'' without express or implied warranty. 177c478bd9Sstevel@tonic-gate */ 187c478bd9Sstevel@tonic-gate 197c478bd9Sstevel@tonic-gate /* 207c478bd9Sstevel@tonic-gate * Constants and structures defined by the internet system, 217c478bd9Sstevel@tonic-gate * according to following documents 227c478bd9Sstevel@tonic-gate * 237962806fSGordon Ross * Internet ASSIGNED NUMBERS (RFC1700) and its successors: 247962806fSGordon Ross * http://www.iana.org/assignments/protocol-numbers 257962806fSGordon Ross * http://www.iana.org/assignments/port-numbers 267c478bd9Sstevel@tonic-gate * Basic Socket Interface Extensions for IPv6 (RFC2133 and its successors) 277c478bd9Sstevel@tonic-gate * 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _NETINET_IN_H 317c478bd9Sstevel@tonic-gate #define _NETINET_IN_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 427c478bd9Sstevel@tonic-gate #include <sys/socket_impl.h> 437c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifndef _SOCKLEN_T 467c478bd9Sstevel@tonic-gate #define _SOCKLEN_T 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * The socklen definitions are reproduced here from sys/socket.h so as to 507c478bd9Sstevel@tonic-gate * not introduce that namespace into existing users of netinet/in.h. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) 537c478bd9Sstevel@tonic-gate typedef size_t socklen_t; 547c478bd9Sstevel@tonic-gate #else 557c478bd9Sstevel@tonic-gate typedef uint32_t socklen_t; 567c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) && !defined(_XPG5) && !defined(_LP64) */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #if defined(_XPG4_2) || defined(_BOOT) 597c478bd9Sstevel@tonic-gate typedef socklen_t *Psocklen_t; 607c478bd9Sstevel@tonic-gate #else 617c478bd9Sstevel@tonic-gate typedef void *Psocklen_t; 627c478bd9Sstevel@tonic-gate #endif /* defined(_XPG4_2) || defined(_BOOT) */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #endif /* _SOCKLEN_T */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 677c478bd9Sstevel@tonic-gate #include <sys/stream.h> 687c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * Symbols such as htonl() are required to be exposed through this file, 717c478bd9Sstevel@tonic-gate * per XNS Issue 5. This is achieved by inclusion of <sys/byteorder.h> 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) || defined(_XPG5) 747c478bd9Sstevel@tonic-gate #include <sys/byteorder.h> 757c478bd9Sstevel@tonic-gate #endif 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #ifndef _IN_PORT_T 787c478bd9Sstevel@tonic-gate #define _IN_PORT_T 797c478bd9Sstevel@tonic-gate typedef uint16_t in_port_t; 807c478bd9Sstevel@tonic-gate #endif 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * Note: IPv4 address data structures usage conventions. 847c478bd9Sstevel@tonic-gate * The "in_addr_t" type below (required by Unix standards) 857c478bd9Sstevel@tonic-gate * is NOT a typedef of "struct in_addr" and violates the usual 867c478bd9Sstevel@tonic-gate * conventions where "struct <name>" and <name>_t are corresponding 877c478bd9Sstevel@tonic-gate * typedefs. 887c478bd9Sstevel@tonic-gate * To minimize confusion, kernel data structures/usage prefers use 897c478bd9Sstevel@tonic-gate * of "ipaddr_t" as atomic uint32_t type and avoid using "in_addr_t" 907c478bd9Sstevel@tonic-gate * The user level APIs continue to follow the historic popular 917c478bd9Sstevel@tonic-gate * practice of using "struct in_addr". 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate #ifndef _IN_ADDR_T 947c478bd9Sstevel@tonic-gate #define _IN_ADDR_T 957c478bd9Sstevel@tonic-gate typedef uint32_t in_addr_t; 967c478bd9Sstevel@tonic-gate #endif 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #ifndef _IPADDR_T 997c478bd9Sstevel@tonic-gate #define _IPADDR_T 1007c478bd9Sstevel@tonic-gate typedef uint32_t ipaddr_t; 1017c478bd9Sstevel@tonic-gate #endif 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate struct in6_addr { 1067c478bd9Sstevel@tonic-gate union { 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * Note: Static initalizers of "union" type assume 1097c478bd9Sstevel@tonic-gate * the constant on the RHS is the type of the first member 1107c478bd9Sstevel@tonic-gate * of union. 1117c478bd9Sstevel@tonic-gate * To make static initializers (and efficient usage) work, 1127c478bd9Sstevel@tonic-gate * the order of members exposed to user and kernel view of 1137c478bd9Sstevel@tonic-gate * this data structure is different. 1147c478bd9Sstevel@tonic-gate * User environment sees specified uint8_t type as first 1157c478bd9Sstevel@tonic-gate * member whereas kernel sees most efficient type as 1167c478bd9Sstevel@tonic-gate * first member. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1197c478bd9Sstevel@tonic-gate uint32_t _S6_u32[4]; /* IPv6 address */ 1207c478bd9Sstevel@tonic-gate uint8_t _S6_u8[16]; /* IPv6 address */ 1217c478bd9Sstevel@tonic-gate #else 1227c478bd9Sstevel@tonic-gate uint8_t _S6_u8[16]; /* IPv6 address */ 1237c478bd9Sstevel@tonic-gate uint32_t _S6_u32[4]; /* IPv6 address */ 1247c478bd9Sstevel@tonic-gate #endif 1257c478bd9Sstevel@tonic-gate uint32_t __S6_align; /* Align on 32 bit boundary */ 1267c478bd9Sstevel@tonic-gate } _S6_un; 1277c478bd9Sstevel@tonic-gate }; 1287c478bd9Sstevel@tonic-gate #define s6_addr _S6_un._S6_u8 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1317c478bd9Sstevel@tonic-gate #define s6_addr8 _S6_un._S6_u8 1327c478bd9Sstevel@tonic-gate #define s6_addr32 _S6_un._S6_u32 1337c478bd9Sstevel@tonic-gate #endif 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate typedef struct in6_addr in6_addr_t; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate #ifndef _SA_FAMILY_T 1407c478bd9Sstevel@tonic-gate #define _SA_FAMILY_T 1417c478bd9Sstevel@tonic-gate typedef uint16_t sa_family_t; 1427c478bd9Sstevel@tonic-gate #endif 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * Protocols 14610e6dadfSbrendan * 14710e6dadfSbrendan * Some of these constant names are copied for the DTrace IP provider in 14810e6dadfSbrendan * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept 14910e6dadfSbrendan * in sync. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate #define IPPROTO_IP 0 /* dummy for IP */ 1527c478bd9Sstevel@tonic-gate #define IPPROTO_HOPOPTS 0 /* Hop by hop header for IPv6 */ 1537c478bd9Sstevel@tonic-gate #define IPPROTO_ICMP 1 /* control message protocol */ 1547c478bd9Sstevel@tonic-gate #define IPPROTO_IGMP 2 /* group control protocol */ 1557c478bd9Sstevel@tonic-gate #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 1567c478bd9Sstevel@tonic-gate #define IPPROTO_ENCAP 4 /* IP in IP encapsulation */ 1577c478bd9Sstevel@tonic-gate #define IPPROTO_TCP 6 /* tcp */ 1587c478bd9Sstevel@tonic-gate #define IPPROTO_EGP 8 /* exterior gateway protocol */ 1597c478bd9Sstevel@tonic-gate #define IPPROTO_PUP 12 /* pup */ 1607c478bd9Sstevel@tonic-gate #define IPPROTO_UDP 17 /* user datagram protocol */ 1617c478bd9Sstevel@tonic-gate #define IPPROTO_IDP 22 /* xns idp */ 1627c478bd9Sstevel@tonic-gate #define IPPROTO_IPV6 41 /* IPv6 encapsulated in IP */ 1637c478bd9Sstevel@tonic-gate #define IPPROTO_ROUTING 43 /* Routing header for IPv6 */ 1647c478bd9Sstevel@tonic-gate #define IPPROTO_FRAGMENT 44 /* Fragment header for IPv6 */ 1657c478bd9Sstevel@tonic-gate #define IPPROTO_RSVP 46 /* rsvp */ 1667c478bd9Sstevel@tonic-gate #define IPPROTO_ESP 50 /* IPsec Encap. Sec. Payload */ 1677c478bd9Sstevel@tonic-gate #define IPPROTO_AH 51 /* IPsec Authentication Hdr. */ 1687c478bd9Sstevel@tonic-gate #define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */ 1697c478bd9Sstevel@tonic-gate #define IPPROTO_NONE 59 /* No next header for IPv6 */ 1707c478bd9Sstevel@tonic-gate #define IPPROTO_DSTOPTS 60 /* Destination options */ 1717c478bd9Sstevel@tonic-gate #define IPPROTO_HELLO 63 /* "hello" routing protocol */ 1727c478bd9Sstevel@tonic-gate #define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */ 1737c478bd9Sstevel@tonic-gate #define IPPROTO_EON 80 /* ISO clnp */ 1747c478bd9Sstevel@tonic-gate #define IPPROTO_OSPF 89 /* OSPF */ 1757c478bd9Sstevel@tonic-gate #define IPPROTO_PIM 103 /* PIM routing protocol */ 1767c478bd9Sstevel@tonic-gate #define IPPROTO_SCTP 132 /* Stream Control */ 1777c478bd9Sstevel@tonic-gate /* Transmission Protocol */ 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #define IPPROTO_RAW 255 /* raw IP packet */ 1807c478bd9Sstevel@tonic-gate #define IPPROTO_MAX 256 1817c478bd9Sstevel@tonic-gate 182a8d26fb6Snh145002 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 18374e20cfeSnh145002 #define PROTO_SDP 257 /* Sockets Direct Protocol */ 184a8d26fb6Snh145002 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 18574e20cfeSnh145002 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * Port/socket numbers: network standard functions 188d04ccbb3Scarlsonj * 189d04ccbb3Scarlsonj * Entries should exist here for each port number compiled into an ON 190d04ccbb3Scarlsonj * component, such as snoop. 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate #define IPPORT_ECHO 7 1937c478bd9Sstevel@tonic-gate #define IPPORT_DISCARD 9 1947c478bd9Sstevel@tonic-gate #define IPPORT_SYSTAT 11 1957c478bd9Sstevel@tonic-gate #define IPPORT_DAYTIME 13 1967c478bd9Sstevel@tonic-gate #define IPPORT_NETSTAT 15 1977c478bd9Sstevel@tonic-gate #define IPPORT_CHARGEN 19 1987c478bd9Sstevel@tonic-gate #define IPPORT_FTP 21 1997c478bd9Sstevel@tonic-gate #define IPPORT_TELNET 23 2007c478bd9Sstevel@tonic-gate #define IPPORT_SMTP 25 2017c478bd9Sstevel@tonic-gate #define IPPORT_TIMESERVER 37 2027c478bd9Sstevel@tonic-gate #define IPPORT_NAMESERVER 42 2037c478bd9Sstevel@tonic-gate #define IPPORT_WHOIS 43 204d04ccbb3Scarlsonj #define IPPORT_DOMAIN 53 2054b22b933Srs200217 #define IPPORT_MDNS 5353 2067c478bd9Sstevel@tonic-gate #define IPPORT_MTP 57 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * Port/socket numbers: host specific functions 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate #define IPPORT_BOOTPS 67 2127c478bd9Sstevel@tonic-gate #define IPPORT_BOOTPC 68 2137c478bd9Sstevel@tonic-gate #define IPPORT_TFTP 69 2147c478bd9Sstevel@tonic-gate #define IPPORT_RJE 77 2157c478bd9Sstevel@tonic-gate #define IPPORT_FINGER 79 216d04ccbb3Scarlsonj #define IPPORT_HTTP 80 217d04ccbb3Scarlsonj #define IPPORT_HTTP_ALT 8080 2187c478bd9Sstevel@tonic-gate #define IPPORT_TTYLINK 87 2197c478bd9Sstevel@tonic-gate #define IPPORT_SUPDUP 95 220d04ccbb3Scarlsonj #define IPPORT_NTP 123 221d04ccbb3Scarlsonj #define IPPORT_NETBIOS_NS 137 222d04ccbb3Scarlsonj #define IPPORT_NETBIOS_DGM 138 223d04ccbb3Scarlsonj #define IPPORT_NETBIOS_SSN 139 224d04ccbb3Scarlsonj #define IPPORT_LDAP 389 225d04ccbb3Scarlsonj #define IPPORT_SLP 427 226d04ccbb3Scarlsonj #define IPPORT_MIP 434 2277962806fSGordon Ross #define IPPORT_SMB 445 /* a.k.a. microsoft-ds */ 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * Internet Key Exchange (IKE) ports 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate #define IPPORT_IKE 500 2337c478bd9Sstevel@tonic-gate #define IPPORT_IKE_NATT 4500 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * UNIX TCP sockets 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate #define IPPORT_EXECSERVER 512 2397c478bd9Sstevel@tonic-gate #define IPPORT_LOGINSERVER 513 2407c478bd9Sstevel@tonic-gate #define IPPORT_CMDSERVER 514 241d04ccbb3Scarlsonj #define IPPORT_PRINTER 515 2427c478bd9Sstevel@tonic-gate #define IPPORT_EFSSERVER 520 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* 2457c478bd9Sstevel@tonic-gate * UNIX UDP sockets 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate #define IPPORT_BIFFUDP 512 2487c478bd9Sstevel@tonic-gate #define IPPORT_WHOSERVER 513 249d04ccbb3Scarlsonj #define IPPORT_SYSLOG 514 250d04ccbb3Scarlsonj #define IPPORT_TALK 517 251d04ccbb3Scarlsonj #define IPPORT_ROUTESERVER 520 252d04ccbb3Scarlsonj #define IPPORT_RIPNG 521 253d04ccbb3Scarlsonj 254d04ccbb3Scarlsonj /* 255d04ccbb3Scarlsonj * DHCPv6 UDP ports 256d04ccbb3Scarlsonj */ 257d04ccbb3Scarlsonj #define IPPORT_DHCPV6C 546 258d04ccbb3Scarlsonj #define IPPORT_DHCPV6S 547 259d04ccbb3Scarlsonj 260d04ccbb3Scarlsonj #define IPPORT_SOCKS 1080 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate /* 2637c478bd9Sstevel@tonic-gate * Ports < IPPORT_RESERVED are reserved for 2647c478bd9Sstevel@tonic-gate * privileged processes (e.g. root). 2657c478bd9Sstevel@tonic-gate * Ports > IPPORT_USERRESERVED are reserved 2667c478bd9Sstevel@tonic-gate * for servers, not necessarily privileged. 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate #define IPPORT_RESERVED 1024 2697c478bd9Sstevel@tonic-gate #define IPPORT_USERRESERVED 5000 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* 2727c478bd9Sstevel@tonic-gate * Link numbers 2737c478bd9Sstevel@tonic-gate */ 2747c478bd9Sstevel@tonic-gate #define IMPLINK_IP 155 2757c478bd9Sstevel@tonic-gate #define IMPLINK_LOWEXPER 156 2767c478bd9Sstevel@tonic-gate #define IMPLINK_HIGHEXPER 158 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * IPv4 Internet address 2807c478bd9Sstevel@tonic-gate * This definition contains obsolete fields for compatibility 2817c478bd9Sstevel@tonic-gate * with SunOS 3.x and 4.2bsd. The presence of subnets renders 2827c478bd9Sstevel@tonic-gate * divisions into fixed fields misleading at best. New code 2837c478bd9Sstevel@tonic-gate * should use only the s_addr field. 2847c478bd9Sstevel@tonic-gate */ 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 2877c478bd9Sstevel@tonic-gate #define _S_un_b S_un_b 2887c478bd9Sstevel@tonic-gate #define _S_un_w S_un_w 2897c478bd9Sstevel@tonic-gate #define _S_addr S_addr 2907c478bd9Sstevel@tonic-gate #define _S_un S_un 2917c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate struct in_addr { 2947c478bd9Sstevel@tonic-gate union { 2957c478bd9Sstevel@tonic-gate struct { uint8_t s_b1, s_b2, s_b3, s_b4; } _S_un_b; 2967c478bd9Sstevel@tonic-gate struct { uint16_t s_w1, s_w2; } _S_un_w; 2977c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 2987c478bd9Sstevel@tonic-gate uint32_t _S_addr; 2997c478bd9Sstevel@tonic-gate #else 3007c478bd9Sstevel@tonic-gate in_addr_t _S_addr; 3017c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 3027c478bd9Sstevel@tonic-gate } _S_un; 3037c478bd9Sstevel@tonic-gate #define s_addr _S_un._S_addr /* should be used for all code */ 3047c478bd9Sstevel@tonic-gate #define s_host _S_un._S_un_b.s_b2 /* OBSOLETE: host on imp */ 3057c478bd9Sstevel@tonic-gate #define s_net _S_un._S_un_b.s_b1 /* OBSOLETE: network */ 3067c478bd9Sstevel@tonic-gate #define s_imp _S_un._S_un_w.s_w2 /* OBSOLETE: imp */ 3077c478bd9Sstevel@tonic-gate #define s_impno _S_un._S_un_b.s_b4 /* OBSOLETE: imp # */ 3087c478bd9Sstevel@tonic-gate #define s_lh _S_un._S_un_b.s_b3 /* OBSOLETE: logical host */ 3097c478bd9Sstevel@tonic-gate }; 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* 3127c478bd9Sstevel@tonic-gate * Definitions of bits in internet address integers. 3137c478bd9Sstevel@tonic-gate * On subnets, the decomposition of addresses to host and net parts 3147c478bd9Sstevel@tonic-gate * is done according to subnet mask, not the masks here. 3152a9459bdSsangeeta * 3162a9459bdSsangeeta * Note that with the introduction of CIDR, IN_CLASSA, IN_CLASSB, 3172a9459bdSsangeeta * IN_CLASSC, IN_CLASSD and IN_CLASSE macros have become "de-facto 3182a9459bdSsangeeta * obsolete". IN_MULTICAST macro should be used to test if a address 3192a9459bdSsangeeta * is a multicast address. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate #define IN_CLASSA(i) (((i) & 0x80000000U) == 0) 3227c478bd9Sstevel@tonic-gate #define IN_CLASSA_NET 0xff000000U 3237c478bd9Sstevel@tonic-gate #define IN_CLASSA_NSHIFT 24 3247c478bd9Sstevel@tonic-gate #define IN_CLASSA_HOST 0x00ffffffU 3257c478bd9Sstevel@tonic-gate #define IN_CLASSA_MAX 128 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate #define IN_CLASSB(i) (((i) & 0xc0000000U) == 0x80000000U) 3287c478bd9Sstevel@tonic-gate #define IN_CLASSB_NET 0xffff0000U 3297c478bd9Sstevel@tonic-gate #define IN_CLASSB_NSHIFT 16 3307c478bd9Sstevel@tonic-gate #define IN_CLASSB_HOST 0x0000ffffU 3317c478bd9Sstevel@tonic-gate #define IN_CLASSB_MAX 65536 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate #define IN_CLASSC(i) (((i) & 0xe0000000U) == 0xc0000000U) 3347c478bd9Sstevel@tonic-gate #define IN_CLASSC_NET 0xffffff00U 3357c478bd9Sstevel@tonic-gate #define IN_CLASSC_NSHIFT 8 3367c478bd9Sstevel@tonic-gate #define IN_CLASSC_HOST 0x000000ffU 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate #define IN_CLASSD(i) (((i) & 0xf0000000U) == 0xe0000000U) 3397c478bd9Sstevel@tonic-gate #define IN_CLASSD_NET 0xf0000000U /* These aren't really */ 3407c478bd9Sstevel@tonic-gate #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 3417c478bd9Sstevel@tonic-gate #define IN_CLASSD_HOST 0x0fffffffU /* routing needn't know */ 3422a9459bdSsangeeta 3432a9459bdSsangeeta #define IN_CLASSE(i) (((i) & 0xf0000000U) == 0xf0000000U) 3442a9459bdSsangeeta #define IN_CLASSE_NET 0xffffffffU 3452a9459bdSsangeeta 3467c478bd9Sstevel@tonic-gate #define IN_MULTICAST(i) IN_CLASSD(i) 3477c478bd9Sstevel@tonic-gate 3482a9459bdSsangeeta /* 3492a9459bdSsangeeta * We have removed CLASS E checks from the kernel 3502a9459bdSsangeeta * But we preserve these defines for userland in order 3512a9459bdSsangeeta * to avoid compile breakage of some 3rd party piece of software 3522a9459bdSsangeeta */ 3532a9459bdSsangeeta #ifndef _KERNEL 3547c478bd9Sstevel@tonic-gate #define IN_EXPERIMENTAL(i) (((i) & 0xe0000000U) == 0xe0000000U) 3557c478bd9Sstevel@tonic-gate #define IN_BADCLASS(i) (((i) & 0xf0000000U) == 0xf0000000U) 3562a9459bdSsangeeta #endif 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate #define INADDR_ANY 0x00000000U 3597c478bd9Sstevel@tonic-gate #define INADDR_LOOPBACK 0x7F000001U 3607c478bd9Sstevel@tonic-gate #define INADDR_BROADCAST 0xffffffffU /* must be masked */ 3617c478bd9Sstevel@tonic-gate #define INADDR_NONE 0xffffffffU 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate #define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */ 3647c478bd9Sstevel@tonic-gate #define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */ 3657c478bd9Sstevel@tonic-gate #define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */ 3667c478bd9Sstevel@tonic-gate #define INADDR_ALLRPTS_GROUP 0xe0000016U /* 224.0.0.22, IGMPv3 */ 3677c478bd9Sstevel@tonic-gate #define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */ 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate /* Scoped IPv4 prefixes (in host byte-order) */ 3707c478bd9Sstevel@tonic-gate #define IN_AUTOCONF_NET 0xa9fe0000U /* 169.254/16 */ 3717c478bd9Sstevel@tonic-gate #define IN_AUTOCONF_MASK 0xffff0000U 3727c478bd9Sstevel@tonic-gate #define IN_PRIVATE8_NET 0x0a000000U /* 10/8 */ 3737c478bd9Sstevel@tonic-gate #define IN_PRIVATE8_MASK 0xff000000U 3747c478bd9Sstevel@tonic-gate #define IN_PRIVATE12_NET 0xac100000U /* 172.16/12 */ 3757c478bd9Sstevel@tonic-gate #define IN_PRIVATE12_MASK 0xfff00000U 3767c478bd9Sstevel@tonic-gate #define IN_PRIVATE16_NET 0xc0a80000U /* 192.168/16 */ 3777c478bd9Sstevel@tonic-gate #define IN_PRIVATE16_MASK 0xffff0000U 3787c478bd9Sstevel@tonic-gate 379f9aa3e1eSkcpoon /* RFC 3927 IPv4 link local address (i in host byte-order) */ 380f9aa3e1eSkcpoon #define IN_LINKLOCAL(i) (((i) & IN_AUTOCONF_MASK) == IN_AUTOCONF_NET) 381f9aa3e1eSkcpoon 3827c478bd9Sstevel@tonic-gate /* Well known 6to4 Relay Router Anycast address defined in RFC 3068 */ 3837c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || !defined(__EXTENSIONS__) 3847c478bd9Sstevel@tonic-gate #define INADDR_6TO4RRANYCAST 0xc0586301U /* 192.88.99.1 */ 3857c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */ 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate #define IN_LOOPBACKNET 127 /* official! */ 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate /* 3907c478bd9Sstevel@tonic-gate * Define a macro to stuff the loopback address into an Internet address 3917c478bd9Sstevel@tonic-gate */ 3927c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || !defined(__EXTENSIONS__) 3937c478bd9Sstevel@tonic-gate #define IN_SET_LOOPBACK_ADDR(a) \ 3947c478bd9Sstevel@tonic-gate { (a)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); \ 3957c478bd9Sstevel@tonic-gate (a)->sin_family = AF_INET; } 3967c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || !defined(__EXTENSIONS__) */ 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate /* 3997c478bd9Sstevel@tonic-gate * IPv4 Socket address. 4007c478bd9Sstevel@tonic-gate */ 4017c478bd9Sstevel@tonic-gate struct sockaddr_in { 4027c478bd9Sstevel@tonic-gate sa_family_t sin_family; 4037c478bd9Sstevel@tonic-gate in_port_t sin_port; 4047c478bd9Sstevel@tonic-gate struct in_addr sin_addr; 4057c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 4067c478bd9Sstevel@tonic-gate char sin_zero[8]; 4077c478bd9Sstevel@tonic-gate #else 4087c478bd9Sstevel@tonic-gate unsigned char sin_zero[8]; 4097c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 4107c478bd9Sstevel@tonic-gate }; 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 4137c478bd9Sstevel@tonic-gate /* 4147c478bd9Sstevel@tonic-gate * IPv6 socket address. 4157c478bd9Sstevel@tonic-gate */ 4167c478bd9Sstevel@tonic-gate struct sockaddr_in6 { 4177c478bd9Sstevel@tonic-gate sa_family_t sin6_family; 4187c478bd9Sstevel@tonic-gate in_port_t sin6_port; 4197c478bd9Sstevel@tonic-gate uint32_t sin6_flowinfo; 4207c478bd9Sstevel@tonic-gate struct in6_addr sin6_addr; 4217c478bd9Sstevel@tonic-gate uint32_t sin6_scope_id; /* Depends on scope of sin6_addr */ 4227c478bd9Sstevel@tonic-gate uint32_t __sin6_src_id; /* Impl. specific - UDP replies */ 4237c478bd9Sstevel@tonic-gate }; 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate /* 4267c478bd9Sstevel@tonic-gate * Macros for accessing the traffic class and flow label fields from 4277c478bd9Sstevel@tonic-gate * sin6_flowinfo. 4287c478bd9Sstevel@tonic-gate * These are designed to be applied to a 32-bit value. 4297c478bd9Sstevel@tonic-gate */ 4307c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate /* masks */ 4337c478bd9Sstevel@tonic-gate #define IPV6_FLOWINFO_FLOWLABEL 0x000fffffU 4347c478bd9Sstevel@tonic-gate #define IPV6_FLOWINFO_TCLASS 0x0ff00000U 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* masks */ 4397c478bd9Sstevel@tonic-gate #define IPV6_FLOWINFO_FLOWLABEL 0xffff0f00U 4407c478bd9Sstevel@tonic-gate #define IPV6_FLOWINFO_TCLASS 0x0000f00fU 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate /* 4457c478bd9Sstevel@tonic-gate * Note: Macros IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT are for 4467c478bd9Sstevel@tonic-gate * use as RHS of Static initializers of "struct in6_addr" (or in6_addr_t) 4477c478bd9Sstevel@tonic-gate * only. They need to be different for User/Kernel versions because union 4487c478bd9Sstevel@tonic-gate * component data structure is defined differently (it is identical at 4497c478bd9Sstevel@tonic-gate * binary representation level). 4507c478bd9Sstevel@tonic-gate * 4517c478bd9Sstevel@tonic-gate * const struct in6_addr IN6ADDR_ANY_INIT; 4527c478bd9Sstevel@tonic-gate * const struct in6_addr IN6ADDR_LOOPBACK_INIT; 4537c478bd9Sstevel@tonic-gate */ 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate #ifdef _KERNEL 4577c478bd9Sstevel@tonic-gate #define IN6ADDR_ANY_INIT { 0, 0, 0, 0 } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 4607c478bd9Sstevel@tonic-gate #define IN6ADDR_LOOPBACK_INIT { 0, 0, 0, 0x00000001U } 4617c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 4627c478bd9Sstevel@tonic-gate #define IN6ADDR_LOOPBACK_INIT { 0, 0, 0, 0x01000000U } 4637c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate #else 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate #define IN6ADDR_ANY_INIT { 0, 0, 0, 0, \ 4687c478bd9Sstevel@tonic-gate 0, 0, 0, 0, \ 4697c478bd9Sstevel@tonic-gate 0, 0, 0, 0, \ 4707c478bd9Sstevel@tonic-gate 0, 0, 0, 0 } 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate #define IN6ADDR_LOOPBACK_INIT { 0, 0, 0, 0, \ 4737c478bd9Sstevel@tonic-gate 0, 0, 0, 0, \ 4747c478bd9Sstevel@tonic-gate 0, 0, 0, 0, \ 4757c478bd9Sstevel@tonic-gate 0, 0, 0, 0x1U } 4767c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* 4797c478bd9Sstevel@tonic-gate * RFC 2553 specifies the following macros. Their type is defined 4807c478bd9Sstevel@tonic-gate * as "int" in the RFC but they only have boolean significance 4817c478bd9Sstevel@tonic-gate * (zero or non-zero). For the purposes of our comment notation, 4827c478bd9Sstevel@tonic-gate * we assume a hypothetical type "bool" defined as follows to 4837c478bd9Sstevel@tonic-gate * write the prototypes assumed for macros in our comments better. 4847c478bd9Sstevel@tonic-gate * 4857c478bd9Sstevel@tonic-gate * typedef int bool; 4867c478bd9Sstevel@tonic-gate */ 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate /* 4897c478bd9Sstevel@tonic-gate * IN6 macros used to test for special IPv6 addresses 4907c478bd9Sstevel@tonic-gate * (Mostly from spec) 4917c478bd9Sstevel@tonic-gate * 4927c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_UNSPECIFIED (const struct in6_addr *); 4937c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_LOOPBACK (const struct in6_addr *); 4947c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MULTICAST (const struct in6_addr *); 4957c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_LINKLOCAL (const struct in6_addr *); 4967c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_SITELOCAL (const struct in6_addr *); 4977c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_V4MAPPED (const struct in6_addr *); 4987c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_V4MAPPED_ANY(const struct in6_addr *); -- Not from RFC2553 4997c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_V4COMPAT (const struct in6_addr *); 5007c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MC_RESERVED (const struct in6_addr *); -- Not from RFC2553 5017c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MC_NODELOCAL(const struct in6_addr *); 5027c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MC_LINKLOCAL(const struct in6_addr *); 5037c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MC_SITELOCAL(const struct in6_addr *); 5047c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MC_ORGLOCAL (const struct in6_addr *); 5057c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_MC_GLOBAL (const struct in6_addr *); 5067c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_6TO4 (const struct in6_addr *); -- Not from RFC2553 5077c478bd9Sstevel@tonic-gate * bool IN6_ARE_6TO4_PREFIX_EQUAL(const struct in6_addr *, 5087c478bd9Sstevel@tonic-gate * const struct in6_addr *); -- Not from RFC2553 5097c478bd9Sstevel@tonic-gate * bool IN6_IS_ADDR_LINKSCOPE (const struct in6addr *); -- Not from RFC2553 5107c478bd9Sstevel@tonic-gate */ 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_UNSPECIFIED(addr) \ 5137c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[3] == 0) && \ 5147c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[2] == 0) && \ 5157c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5167c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5177c478bd9Sstevel@tonic-gate 5187c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5197c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_LOOPBACK(addr) \ 5207c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[3] == 0x00000001) && \ 5217c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[2] == 0) && \ 5227c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5237c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5247c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5257c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_LOOPBACK(addr) \ 5267c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[3] == 0x01000000) && \ 5277c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[2] == 0) && \ 5287c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5297c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5307c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5337c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MULTICAST(addr) \ 5347c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff000000) == 0xff000000) 5357c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5367c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MULTICAST(addr) \ 5377c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x000000ff) == 0x000000ff) 5387c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5417c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_LINKLOCAL(addr) \ 5427c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfe800000) 5437c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5447c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_LINKLOCAL(addr) \ 5457c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x000080fe) 5467c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5497c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_SITELOCAL(addr) \ 5507c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xffc00000) == 0xfec00000) 5517c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5527c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_SITELOCAL(addr) \ 5537c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x0000c0ff) == 0x0000c0fe) 5547c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5577c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_V4MAPPED(addr) \ 5587c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \ 5597c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5607c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5617c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5627c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_V4MAPPED(addr) \ 5637c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \ 5647c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5657c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5667c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate /* 5697c478bd9Sstevel@tonic-gate * IN6_IS_ADDR_V4MAPPED - A IPv4 mapped INADDR_ANY 5707c478bd9Sstevel@tonic-gate * Note: This macro is currently NOT defined in RFC2553 specification 5717c478bd9Sstevel@tonic-gate * and not a standard macro that portable applications should use. 5727c478bd9Sstevel@tonic-gate */ 5737c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5747c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_V4MAPPED_ANY(addr) \ 5757c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[3] == 0) && \ 5767c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[2] == 0x0000ffff) && \ 5777c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5787c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5797c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5807c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_V4MAPPED_ANY(addr) \ 5817c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[3] == 0) && \ 5827c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[2] == 0xffff0000U) && \ 5837c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5847c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0)) 5857c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate /* Exclude loopback and unspecified address */ 5887c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 5897c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_V4COMPAT(addr) \ 5907c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[2] == 0) && \ 5917c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 5927c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0) && \ 5937c478bd9Sstevel@tonic-gate !((addr)->_S6_un._S6_u32[3] == 0) && \ 5947c478bd9Sstevel@tonic-gate !((addr)->_S6_un._S6_u32[3] == 0x00000001)) 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 5977c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_V4COMPAT(addr) \ 5987c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[2] == 0) && \ 5997c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[1] == 0) && \ 6007c478bd9Sstevel@tonic-gate ((addr)->_S6_un._S6_u32[0] == 0) && \ 6017c478bd9Sstevel@tonic-gate !((addr)->_S6_un._S6_u32[3] == 0) && \ 6027c478bd9Sstevel@tonic-gate !((addr)->_S6_un._S6_u32[3] == 0x01000000)) 6037c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate /* 6067c478bd9Sstevel@tonic-gate * Note: 6077c478bd9Sstevel@tonic-gate * IN6_IS_ADDR_MC_RESERVED macro is currently NOT defined in RFC2553 6087c478bd9Sstevel@tonic-gate * specification and not a standard macro that portable applications 6097c478bd9Sstevel@tonic-gate * should use. 6107c478bd9Sstevel@tonic-gate */ 6117c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6127c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_RESERVED(addr) \ 6137c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff000000) 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6167c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_RESERVED(addr) \ 6177c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000000ff) 6187c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6217c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_NODELOCAL(addr) \ 6227c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff010000) 6237c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6247c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_NODELOCAL(addr) \ 6257c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000001ff) 6267c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6297c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_LINKLOCAL(addr) \ 6307c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff020000) 6317c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6327c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_LINKLOCAL(addr) \ 6337c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000002ff) 6347c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6377c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_SITELOCAL(addr) \ 6387c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff050000) 6397c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6407c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_SITELOCAL(addr) \ 6417c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000005ff) 6427c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6457c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_ORGLOCAL(addr) \ 6467c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff080000) 6477c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6487c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_ORGLOCAL(addr) \ 6497c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x000008ff) 6507c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6537c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_GLOBAL(addr) \ 6547c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xff0f0000) == 0xff0e0000) 6557c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6567c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_MC_GLOBAL(addr) \ 6577c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x00000fff) == 0x00000eff) 6587c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate /* 661b94bb0f0Sdd193516 * The IN6_IS_ADDR_MC_SOLICITEDNODE macro is not defined in any standard or 662b94bb0f0Sdd193516 * RFC, and shouldn't be used by portable applications. It is used to see 663b94bb0f0Sdd193516 * if an address is a solicited-node multicast address, which is prefixed 664b94bb0f0Sdd193516 * with ff02:0:0:0:0:1:ff00::/104. 665b94bb0f0Sdd193516 */ 666b94bb0f0Sdd193516 #ifdef _BIG_ENDIAN 667b94bb0f0Sdd193516 #define IN6_IS_ADDR_MC_SOLICITEDNODE(addr) \ 668b94bb0f0Sdd193516 (((addr)->_S6_un._S6_u32[0] == 0xff020000) && \ 669b94bb0f0Sdd193516 ((addr)->_S6_un._S6_u32[1] == 0x00000000) && \ 670b94bb0f0Sdd193516 ((addr)->_S6_un._S6_u32[2] == 0x00000001) && \ 671b94bb0f0Sdd193516 (((addr)->_S6_un._S6_u32[3] & 0xff000000) == 0xff000000)) 672b94bb0f0Sdd193516 #else 673b94bb0f0Sdd193516 #define IN6_IS_ADDR_MC_SOLICITEDNODE(addr) \ 674b94bb0f0Sdd193516 (((addr)->_S6_un._S6_u32[0] == 0x000002ff) && \ 675b94bb0f0Sdd193516 ((addr)->_S6_un._S6_u32[1] == 0x00000000) && \ 676b94bb0f0Sdd193516 ((addr)->_S6_un._S6_u32[2] == 0x01000000) && \ 677b94bb0f0Sdd193516 (((addr)->_S6_un._S6_u32[3] & 0x000000ff) == 0x000000ff)) 678b94bb0f0Sdd193516 #endif 679b94bb0f0Sdd193516 680b94bb0f0Sdd193516 /* 6817c478bd9Sstevel@tonic-gate * Macros to a) test for 6to4 IPv6 address, and b) to test if two 6827c478bd9Sstevel@tonic-gate * 6to4 addresses have the same /48 prefix, and, hence, are from the 6837c478bd9Sstevel@tonic-gate * same 6to4 site. 6847c478bd9Sstevel@tonic-gate */ 6857c478bd9Sstevel@tonic-gate 6867c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 6877c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_6TO4(addr) \ 6887c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0xffff0000) == 0x20020000) 6897c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 6907c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_6TO4(addr) \ 6917c478bd9Sstevel@tonic-gate (((addr)->_S6_un._S6_u32[0] & 0x0000ffff) == 0x00000220) 6927c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate #define IN6_ARE_6TO4_PREFIX_EQUAL(addr1, addr2) \ 6957c478bd9Sstevel@tonic-gate (((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0]) && \ 6967c478bd9Sstevel@tonic-gate ((addr1)->_S6_un._S6_u8[4] == (addr2)->_S6_un._S6_u8[4]) && \ 6977c478bd9Sstevel@tonic-gate ((addr1)->_S6_un._S6_u8[5] == (addr2)->_S6_un._S6_u8[5])) 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate /* 7007c478bd9Sstevel@tonic-gate * IN6_IS_ADDR_LINKSCOPE 7017c478bd9Sstevel@tonic-gate * Identifies an address as being either link-local, link-local multicast or 7027c478bd9Sstevel@tonic-gate * node-local multicast. All types of addresses are considered to be unique 7037c478bd9Sstevel@tonic-gate * within the scope of a given link. 7047c478bd9Sstevel@tonic-gate */ 7057c478bd9Sstevel@tonic-gate #define IN6_IS_ADDR_LINKSCOPE(addr) \ 7067c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr) || \ 7077c478bd9Sstevel@tonic-gate IN6_IS_ADDR_MC_NODELOCAL(addr)) 7087c478bd9Sstevel@tonic-gate 7097c478bd9Sstevel@tonic-gate /* 7107c478bd9Sstevel@tonic-gate * Useful utility macros for operations with IPv6 addresses 7117c478bd9Sstevel@tonic-gate * Note: These macros are NOT defined in the RFC2553 or any other 7127c478bd9Sstevel@tonic-gate * standard specification and are not standard macros that portable 7137c478bd9Sstevel@tonic-gate * applications should use. 7147c478bd9Sstevel@tonic-gate */ 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate /* 7177c478bd9Sstevel@tonic-gate * IN6_V4MAPPED_TO_INADDR 7187c478bd9Sstevel@tonic-gate * IN6_V4MAPPED_TO_IPADDR 7197c478bd9Sstevel@tonic-gate * Assign a IPv4-Mapped IPv6 address to an IPv4 address. 7207c478bd9Sstevel@tonic-gate * Note: These macros are NOT defined in RFC2553 or any other standard 7217c478bd9Sstevel@tonic-gate * specification and are not macros that portable applications should 7227c478bd9Sstevel@tonic-gate * use. 7237c478bd9Sstevel@tonic-gate * 7247c478bd9Sstevel@tonic-gate * void IN6_V4MAPPED_TO_INADDR(const in6_addr_t *v6, struct in_addr *v4); 7257c478bd9Sstevel@tonic-gate * void IN6_V4MAPPED_TO_IPADDR(const in6_addr_t *v6, ipaddr_t v4); 7267c478bd9Sstevel@tonic-gate * 7277c478bd9Sstevel@tonic-gate */ 7287c478bd9Sstevel@tonic-gate #define IN6_V4MAPPED_TO_INADDR(v6, v4) \ 7297c478bd9Sstevel@tonic-gate ((v4)->s_addr = (v6)->_S6_un._S6_u32[3]) 7307c478bd9Sstevel@tonic-gate #define IN6_V4MAPPED_TO_IPADDR(v6, v4) \ 7317c478bd9Sstevel@tonic-gate ((v4) = (v6)->_S6_un._S6_u32[3]) 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate /* 7347c478bd9Sstevel@tonic-gate * IN6_INADDR_TO_V4MAPPED 7357c478bd9Sstevel@tonic-gate * IN6_IPADDR_TO_V4MAPPED 7367c478bd9Sstevel@tonic-gate * Assign a IPv4 address address to an IPv6 address as a IPv4-mapped 7377c478bd9Sstevel@tonic-gate * address. 7387c478bd9Sstevel@tonic-gate * Note: These macros are NOT defined in RFC2553 or any other standard 7397c478bd9Sstevel@tonic-gate * specification and are not macros that portable applications should 7407c478bd9Sstevel@tonic-gate * use. 7417c478bd9Sstevel@tonic-gate * 7427c478bd9Sstevel@tonic-gate * void IN6_INADDR_TO_V4MAPPED(const struct in_addr *v4, in6_addr_t *v6); 7437c478bd9Sstevel@tonic-gate * void IN6_IPADDR_TO_V4MAPPED(const ipaddr_t v4, in6_addr_t *v6); 7447c478bd9Sstevel@tonic-gate * 7457c478bd9Sstevel@tonic-gate */ 7467c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 7477c478bd9Sstevel@tonic-gate #define IN6_INADDR_TO_V4MAPPED(v4, v6) \ 7487c478bd9Sstevel@tonic-gate ((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \ 7497c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[2] = 0x0000ffff, \ 7507c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[1] = 0, \ 7517c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[0] = 0) 7527c478bd9Sstevel@tonic-gate #define IN6_IPADDR_TO_V4MAPPED(v4, v6) \ 7537c478bd9Sstevel@tonic-gate ((v6)->_S6_un._S6_u32[3] = (v4), \ 7547c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[2] = 0x0000ffff, \ 7557c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[1] = 0, \ 7567c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[0] = 0) 7577c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 7587c478bd9Sstevel@tonic-gate #define IN6_INADDR_TO_V4MAPPED(v4, v6) \ 7597c478bd9Sstevel@tonic-gate ((v6)->_S6_un._S6_u32[3] = (v4)->s_addr, \ 7607c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[2] = 0xffff0000U, \ 7617c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[1] = 0, \ 7627c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[0] = 0) 7637c478bd9Sstevel@tonic-gate #define IN6_IPADDR_TO_V4MAPPED(v4, v6) \ 7647c478bd9Sstevel@tonic-gate ((v6)->_S6_un._S6_u32[3] = (v4), \ 7657c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[2] = 0xffff0000U, \ 7667c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[1] = 0, \ 7677c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[0] = 0) 7687c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate /* 7717c478bd9Sstevel@tonic-gate * IN6_6TO4_TO_V4ADDR 7727c478bd9Sstevel@tonic-gate * Extract the embedded IPv4 address from the prefix to a 6to4 IPv6 7737c478bd9Sstevel@tonic-gate * address. 7747c478bd9Sstevel@tonic-gate * Note: This macro is NOT defined in RFC2553 or any other standard 7757c478bd9Sstevel@tonic-gate * specification and is not a macro that portable applications should 7767c478bd9Sstevel@tonic-gate * use. 7777c478bd9Sstevel@tonic-gate * Note: we don't use the IPADDR form of the macro because we need 7787c478bd9Sstevel@tonic-gate * to do a bytewise copy; the V4ADDR in the 6to4 address is not 7797c478bd9Sstevel@tonic-gate * 32-bit aligned. 7807c478bd9Sstevel@tonic-gate * 7817c478bd9Sstevel@tonic-gate * void IN6_6TO4_TO_V4ADDR(const in6_addr_t *v6, struct in_addr *v4); 7827c478bd9Sstevel@tonic-gate * 7837c478bd9Sstevel@tonic-gate */ 7847c478bd9Sstevel@tonic-gate #define IN6_6TO4_TO_V4ADDR(v6, v4) \ 7857c478bd9Sstevel@tonic-gate ((v4)->_S_un._S_un_b.s_b1 = (v6)->_S6_un._S6_u8[2], \ 7867c478bd9Sstevel@tonic-gate (v4)->_S_un._S_un_b.s_b2 = (v6)->_S6_un._S6_u8[3], \ 7877c478bd9Sstevel@tonic-gate (v4)->_S_un._S_un_b.s_b3 = (v6)->_S6_un._S6_u8[4], \ 7887c478bd9Sstevel@tonic-gate (v4)->_S_un._S_un_b.s_b4 = (v6)->_S6_un._S6_u8[5]) 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate /* 7917c478bd9Sstevel@tonic-gate * IN6_V4ADDR_TO_6TO4 7927c478bd9Sstevel@tonic-gate * Given an IPv4 address and an IPv6 address for output, a 6to4 address 7937c478bd9Sstevel@tonic-gate * will be created from the IPv4 Address. 7947c478bd9Sstevel@tonic-gate * Note: This method for creating 6to4 addresses is not standardized 7957c478bd9Sstevel@tonic-gate * outside of Solaris. The newly created 6to4 address will be of the form 7967c478bd9Sstevel@tonic-gate * 2002:<V4ADDR>:<SUBNETID>::<HOSTID>, where SUBNETID will equal 0 and 7977c478bd9Sstevel@tonic-gate * HOSTID will equal 1. 7987c478bd9Sstevel@tonic-gate * 7997c478bd9Sstevel@tonic-gate * void IN6_V4ADDR_TO_6TO4(const struct in_addr *v4, in6_addr_t *v6) 8007c478bd9Sstevel@tonic-gate * 8017c478bd9Sstevel@tonic-gate */ 8027c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 8037c478bd9Sstevel@tonic-gate #define IN6_V4ADDR_TO_6TO4(v4, v6) \ 8047c478bd9Sstevel@tonic-gate ((v6)->_S6_un._S6_u8[0] = 0x20, \ 8057c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[1] = 0x02, \ 8067c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \ 8077c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \ 8087c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \ 8097c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \ 8107c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[6] = 0, \ 8117c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[7] = 0, \ 8127c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[2] = 0, \ 8137c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[3] = 0x00000001U) 8147c478bd9Sstevel@tonic-gate #else 8157c478bd9Sstevel@tonic-gate #define IN6_V4ADDR_TO_6TO4(v4, v6) \ 8167c478bd9Sstevel@tonic-gate ((v6)->_S6_un._S6_u8[0] = 0x20, \ 8177c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[1] = 0x02, \ 8187c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[2] = (v4)->_S_un._S_un_b.s_b1, \ 8197c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[3] = (v4)->_S_un._S_un_b.s_b2, \ 8207c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[4] = (v4)->_S_un._S_un_b.s_b3, \ 8217c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[5] = (v4)->_S_un._S_un_b.s_b4, \ 8227c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[6] = 0, \ 8237c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u8[7] = 0, \ 8247c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[2] = 0, \ 8257c478bd9Sstevel@tonic-gate (v6)->_S6_un._S6_u32[3] = 0x01000000U) 8267c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate /* 8297c478bd9Sstevel@tonic-gate * IN6_ARE_ADDR_EQUAL (defined in RFC2292) 8307c478bd9Sstevel@tonic-gate * Compares if IPv6 addresses are equal. 8317c478bd9Sstevel@tonic-gate * Note: Compares in order of high likelyhood of a miss so we minimize 8327c478bd9Sstevel@tonic-gate * compares. (Current heuristic order, compare in reverse order of 8337c478bd9Sstevel@tonic-gate * uint32_t units) 8347c478bd9Sstevel@tonic-gate * 8357c478bd9Sstevel@tonic-gate * bool IN6_ARE_ADDR_EQUAL(const struct in6_addr *, 8367c478bd9Sstevel@tonic-gate * const struct in6_addr *); 8377c478bd9Sstevel@tonic-gate */ 8387c478bd9Sstevel@tonic-gate #define IN6_ARE_ADDR_EQUAL(addr1, addr2) \ 8397c478bd9Sstevel@tonic-gate (((addr1)->_S6_un._S6_u32[3] == (addr2)->_S6_un._S6_u32[3]) && \ 8407c478bd9Sstevel@tonic-gate ((addr1)->_S6_un._S6_u32[2] == (addr2)->_S6_un._S6_u32[2]) && \ 8417c478bd9Sstevel@tonic-gate ((addr1)->_S6_un._S6_u32[1] == (addr2)->_S6_un._S6_u32[1]) && \ 8427c478bd9Sstevel@tonic-gate ((addr1)->_S6_un._S6_u32[0] == (addr2)->_S6_un._S6_u32[0])) 8437c478bd9Sstevel@tonic-gate 8449b241b4eSYuri Pankov /* 8459b241b4eSYuri Pankov * IN6_ARE_PREFIXEDADDR_EQUAL (not defined in RFCs) 8469b241b4eSYuri Pankov * Compares if prefixed parts of IPv6 addresses are equal. 8479b241b4eSYuri Pankov * 8489b241b4eSYuri Pankov * uint32_t IN6_MASK_FROM_PREFIX(int, int); 8499b241b4eSYuri Pankov * bool IN6_ARE_PREFIXEDADDR_EQUAL(const struct in6_addr *, 8509b241b4eSYuri Pankov * const struct in6_addr *, 8519b241b4eSYuri Pankov * int); 8529b241b4eSYuri Pankov */ 8539b241b4eSYuri Pankov #define IN6_MASK_FROM_PREFIX(qoctet, prefix) \ 8549b241b4eSYuri Pankov ((((qoctet) + 1) * 32 < (prefix)) ? 0xFFFFFFFFu : \ 8559b241b4eSYuri Pankov ((((qoctet) * 32) >= (prefix)) ? 0x00000000u : \ 8569b241b4eSYuri Pankov 0xFFFFFFFFu << (((qoctet) + 1) * 32 - (prefix)))) 8579b241b4eSYuri Pankov 8589b241b4eSYuri Pankov #define IN6_ARE_PREFIXEDADDR_EQUAL(addr1, addr2, prefix) \ 8599b241b4eSYuri Pankov (((ntohl((addr1)->_S6_un._S6_u32[0]) & \ 8609b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(0, prefix)) == \ 8619b241b4eSYuri Pankov (ntohl((addr2)->_S6_un._S6_u32[0]) & \ 8629b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(0, prefix))) && \ 8639b241b4eSYuri Pankov ((ntohl((addr1)->_S6_un._S6_u32[1]) & \ 8649b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(1, prefix)) == \ 8659b241b4eSYuri Pankov (ntohl((addr2)->_S6_un._S6_u32[1]) & \ 8669b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(1, prefix))) && \ 8679b241b4eSYuri Pankov ((ntohl((addr1)->_S6_un._S6_u32[2]) & \ 8689b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(2, prefix)) == \ 8699b241b4eSYuri Pankov (ntohl((addr2)->_S6_un._S6_u32[2]) & \ 8709b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(2, prefix))) && \ 8719b241b4eSYuri Pankov ((ntohl((addr1)->_S6_un._S6_u32[3]) & \ 8729b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(3, prefix)) == \ 8739b241b4eSYuri Pankov (ntohl((addr2)->_S6_un._S6_u32[3]) & \ 8749b241b4eSYuri Pankov IN6_MASK_FROM_PREFIX(3, prefix)))) 8759b241b4eSYuri Pankov 8767c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate /* 8807c478bd9Sstevel@tonic-gate * Options for use with [gs]etsockopt at the IP level. 8817c478bd9Sstevel@tonic-gate * 8827c478bd9Sstevel@tonic-gate * Note: Some of the IP_ namespace has conflict with and 8837c478bd9Sstevel@tonic-gate * and is exposed through <xti.h>. (It also requires exposing 8847c478bd9Sstevel@tonic-gate * options not implemented). The options with potential 8857c478bd9Sstevel@tonic-gate * for conflicts use #ifndef guards. 8867c478bd9Sstevel@tonic-gate */ 8877c478bd9Sstevel@tonic-gate #ifndef IP_OPTIONS 8887c478bd9Sstevel@tonic-gate #define IP_OPTIONS 1 /* set/get IP per-packet options */ 8897c478bd9Sstevel@tonic-gate #endif 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate #define IP_HDRINCL 2 /* int; header is included with data (raw) */ 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate #ifndef IP_TOS 8947c478bd9Sstevel@tonic-gate #define IP_TOS 3 /* int; IP type of service and precedence */ 8957c478bd9Sstevel@tonic-gate #endif 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate #ifndef IP_TTL 8987c478bd9Sstevel@tonic-gate #define IP_TTL 4 /* int; IP time to live */ 8997c478bd9Sstevel@tonic-gate #endif 9007c478bd9Sstevel@tonic-gate 9017c478bd9Sstevel@tonic-gate #define IP_RECVOPTS 0x5 /* int; receive all IP options w/datagram */ 9027c478bd9Sstevel@tonic-gate #define IP_RECVRETOPTS 0x6 /* int; receive IP options for response */ 9037c478bd9Sstevel@tonic-gate #define IP_RECVDSTADDR 0x7 /* int; receive IP dst addr w/datagram */ 9047c478bd9Sstevel@tonic-gate #define IP_RETOPTS 0x8 /* ip_opts; set/get IP per-packet options */ 9057c478bd9Sstevel@tonic-gate #define IP_RECVIF 0x9 /* int; receive the inbound interface index */ 9067c478bd9Sstevel@tonic-gate #define IP_RECVSLLA 0xa /* sockaddr_dl; get source link layer address */ 9077c478bd9Sstevel@tonic-gate #define IP_RECVTTL 0xb /* uint8_t; get TTL for inbound packet */ 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate #define IP_MULTICAST_IF 0x10 /* set/get IP multicast interface */ 9107c478bd9Sstevel@tonic-gate #define IP_MULTICAST_TTL 0x11 /* set/get IP multicast timetolive */ 9117c478bd9Sstevel@tonic-gate #define IP_MULTICAST_LOOP 0x12 /* set/get IP multicast loopback */ 9127c478bd9Sstevel@tonic-gate #define IP_ADD_MEMBERSHIP 0x13 /* add an IP group membership */ 9137c478bd9Sstevel@tonic-gate #define IP_DROP_MEMBERSHIP 0x14 /* drop an IP group membership */ 9147c478bd9Sstevel@tonic-gate #define IP_BLOCK_SOURCE 0x15 /* block mcast pkts from source */ 9157c478bd9Sstevel@tonic-gate #define IP_UNBLOCK_SOURCE 0x16 /* unblock mcast pkts from source */ 9167c478bd9Sstevel@tonic-gate #define IP_ADD_SOURCE_MEMBERSHIP 0x17 /* add mcast group/source pair */ 91743d18f1cSpriyanka #define IP_DROP_SOURCE_MEMBERSHIP 0x18 /* drop mcast group/source pair */ 91843d18f1cSpriyanka #define IP_NEXTHOP 0x19 /* send directly to next hop */ 91919a30e1aSrshoaib /* 92019a30e1aSrshoaib * IP_PKTINFO and IP_RECVPKTINFO have same value. Size of argument passed in 92119a30e1aSrshoaib * is used to differentiate b/w the two. 92219a30e1aSrshoaib */ 92319a30e1aSrshoaib #define IP_PKTINFO 0x1a /* specify src address and/or index */ 92419a30e1aSrshoaib #define IP_RECVPKTINFO 0x1a /* recv dest/matched addr and index */ 925bd670b35SErik Nordmark #define IP_DONTFRAG 0x1b /* don't fragment packets */ 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 9287c478bd9Sstevel@tonic-gate /* 9297c478bd9Sstevel@tonic-gate * Different preferences that can be requested from IPSEC protocols. 9307c478bd9Sstevel@tonic-gate */ 9317c478bd9Sstevel@tonic-gate #define IP_SEC_OPT 0x22 /* Used to set IPSEC options */ 9327c478bd9Sstevel@tonic-gate #define IPSEC_PREF_NEVER 0x01 9337c478bd9Sstevel@tonic-gate #define IPSEC_PREF_REQUIRED 0x02 9347c478bd9Sstevel@tonic-gate #define IPSEC_PREF_UNIQUE 0x04 9357c478bd9Sstevel@tonic-gate /* 9367c478bd9Sstevel@tonic-gate * This can be used with the setsockopt() call to set per socket security 9377c478bd9Sstevel@tonic-gate * options. When the application uses per-socket API, we will reflect 9387c478bd9Sstevel@tonic-gate * the request on both outbound and inbound packets. 9397c478bd9Sstevel@tonic-gate */ 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate typedef struct ipsec_req { 9427c478bd9Sstevel@tonic-gate uint_t ipsr_ah_req; /* AH request */ 9437c478bd9Sstevel@tonic-gate uint_t ipsr_esp_req; /* ESP request */ 9447c478bd9Sstevel@tonic-gate uint_t ipsr_self_encap_req; /* Self-Encap request */ 9457c478bd9Sstevel@tonic-gate uint8_t ipsr_auth_alg; /* Auth algs for AH */ 9467c478bd9Sstevel@tonic-gate uint8_t ipsr_esp_alg; /* Encr algs for ESP */ 9477c478bd9Sstevel@tonic-gate uint8_t ipsr_esp_auth_alg; /* Auth algs for ESP */ 9487c478bd9Sstevel@tonic-gate } ipsec_req_t; 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate /* 9517c478bd9Sstevel@tonic-gate * MCAST_* options are protocol-independent. The actual definitions 9527c478bd9Sstevel@tonic-gate * are with the v6 options below; this comment is here to note the 9537c478bd9Sstevel@tonic-gate * namespace usage. 9547c478bd9Sstevel@tonic-gate * 9557c478bd9Sstevel@tonic-gate * #define MCAST_JOIN_GROUP 0x29 9567c478bd9Sstevel@tonic-gate * #define MCAST_LEAVE_GROUP 0x2a 9577c478bd9Sstevel@tonic-gate * #define MCAST_BLOCK_SOURCE 0x2b 9587c478bd9Sstevel@tonic-gate * #define MCAST_UNBLOCK_SOURCE 0x2c 9597c478bd9Sstevel@tonic-gate * #define MCAST_JOIN_SOURCE_GROUP 0x2d 9607c478bd9Sstevel@tonic-gate * #define MCAST_LEAVE_SOURCE_GROUP 0x2e 9617c478bd9Sstevel@tonic-gate */ 9627c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 9637c478bd9Sstevel@tonic-gate 9647c478bd9Sstevel@tonic-gate /* 9657c478bd9Sstevel@tonic-gate * SunOS private (potentially not portable) IP_ option names 9667c478bd9Sstevel@tonic-gate */ 9677c478bd9Sstevel@tonic-gate #define IP_BOUND_IF 0x41 /* bind socket to an ifindex */ 9687c478bd9Sstevel@tonic-gate #define IP_UNSPEC_SRC 0x42 /* use unspecified source address */ 969a7107231Smeem #define IP_BROADCAST_TTL 0x43 /* use specific TTL for broadcast */ 970e11c3f44Smeem /* can be reused 0x44 */ 971e704a8f2Smeem #define IP_DHCPINIT_IF 0x45 /* accept all unicast DHCP traffic */ 972e704a8f2Smeem 9737c478bd9Sstevel@tonic-gate /* 9747c478bd9Sstevel@tonic-gate * Option values and names (when !_XPG5) shared with <xti_inet.h> 9757c478bd9Sstevel@tonic-gate */ 9767c478bd9Sstevel@tonic-gate #ifndef IP_REUSEADDR 9777c478bd9Sstevel@tonic-gate #define IP_REUSEADDR 0x104 9787c478bd9Sstevel@tonic-gate #endif 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate #ifndef IP_DONTROUTE 9817c478bd9Sstevel@tonic-gate #define IP_DONTROUTE 0x105 9827c478bd9Sstevel@tonic-gate #endif 9837c478bd9Sstevel@tonic-gate 9847c478bd9Sstevel@tonic-gate #ifndef IP_BROADCAST 9857c478bd9Sstevel@tonic-gate #define IP_BROADCAST 0x106 9867c478bd9Sstevel@tonic-gate #endif 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate /* 9897c478bd9Sstevel@tonic-gate * The following option values are reserved by <xti_inet.h> 9907c478bd9Sstevel@tonic-gate * 9917c478bd9Sstevel@tonic-gate * T_IP_OPTIONS 0x107 - IP per-packet options 9927c478bd9Sstevel@tonic-gate * T_IP_TOS 0x108 - IP per packet type of service 9937c478bd9Sstevel@tonic-gate */ 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate /* 9967c478bd9Sstevel@tonic-gate * Default value constants for multicast attributes controlled by 9977c478bd9Sstevel@tonic-gate * IP*_MULTICAST_LOOP and IP*_MULTICAST_{TTL,HOPS} options. 9987c478bd9Sstevel@tonic-gate */ 9997c478bd9Sstevel@tonic-gate #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 10007c478bd9Sstevel@tonic-gate #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 10037c478bd9Sstevel@tonic-gate /* 10047c478bd9Sstevel@tonic-gate * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 10057c478bd9Sstevel@tonic-gate */ 10067c478bd9Sstevel@tonic-gate struct ip_mreq { 10077c478bd9Sstevel@tonic-gate struct in_addr imr_multiaddr; /* IP multicast address of group */ 10087c478bd9Sstevel@tonic-gate struct in_addr imr_interface; /* local IP address of interface */ 10097c478bd9Sstevel@tonic-gate }; 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate /* 10127c478bd9Sstevel@tonic-gate * Argument structure for IP_BLOCK_SOURCE, IP_UNBLOCK_SOURCE, 10137c478bd9Sstevel@tonic-gate * IP_ADD_SOURCE_MEMBERSHIP, and IP_DROP_SOURCE_MEMBERSHIP. 10147c478bd9Sstevel@tonic-gate */ 10157c478bd9Sstevel@tonic-gate struct ip_mreq_source { 10167c478bd9Sstevel@tonic-gate struct in_addr imr_multiaddr; /* IP address of group */ 10177c478bd9Sstevel@tonic-gate struct in_addr imr_sourceaddr; /* IP address of source */ 10187c478bd9Sstevel@tonic-gate struct in_addr imr_interface; /* IP address of interface */ 10197c478bd9Sstevel@tonic-gate }; 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate /* 10227c478bd9Sstevel@tonic-gate * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP on 10237c478bd9Sstevel@tonic-gate * IPv6 addresses. 10247c478bd9Sstevel@tonic-gate */ 10257c478bd9Sstevel@tonic-gate struct ipv6_mreq { 10267c478bd9Sstevel@tonic-gate struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */ 10277c478bd9Sstevel@tonic-gate unsigned int ipv6mr_interface; /* interface index */ 10287c478bd9Sstevel@tonic-gate }; 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate /* 10317c478bd9Sstevel@tonic-gate * Use #pragma pack() construct to force 32-bit alignment on amd64. 10327c478bd9Sstevel@tonic-gate * This is needed to keep the structure size and offsets consistent 10337c478bd9Sstevel@tonic-gate * between a 32-bit app and the 64-bit amd64 kernel in structures 10347c478bd9Sstevel@tonic-gate * where 64-bit alignment would create gaps (in this case, structures 10357c478bd9Sstevel@tonic-gate * which have a uint32_t followed by a struct sockaddr_storage). 10367c478bd9Sstevel@tonic-gate */ 10377c478bd9Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 10387c478bd9Sstevel@tonic-gate #pragma pack(4) 10397c478bd9Sstevel@tonic-gate #endif 10407c478bd9Sstevel@tonic-gate 10417c478bd9Sstevel@tonic-gate /* 10427c478bd9Sstevel@tonic-gate * Argument structure for MCAST_JOIN_GROUP and MCAST_LEAVE_GROUP. 10437c478bd9Sstevel@tonic-gate */ 10447c478bd9Sstevel@tonic-gate struct group_req { 10457c478bd9Sstevel@tonic-gate uint32_t gr_interface; /* interface index */ 10467c478bd9Sstevel@tonic-gate struct sockaddr_storage gr_group; /* group address */ 10477c478bd9Sstevel@tonic-gate }; 10487c478bd9Sstevel@tonic-gate 10497c478bd9Sstevel@tonic-gate /* 10507c478bd9Sstevel@tonic-gate * Argument structure for MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE, 10517c478bd9Sstevel@tonic-gate * MCAST_JOIN_SOURCE_GROUP, MCAST_LEAVE_SOURCE_GROUP. 10527c478bd9Sstevel@tonic-gate */ 10537c478bd9Sstevel@tonic-gate struct group_source_req { 10547c478bd9Sstevel@tonic-gate uint32_t gsr_interface; /* interface index */ 10557c478bd9Sstevel@tonic-gate struct sockaddr_storage gsr_group; /* group address */ 10567c478bd9Sstevel@tonic-gate struct sockaddr_storage gsr_source; /* source address */ 10577c478bd9Sstevel@tonic-gate }; 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate /* 10607c478bd9Sstevel@tonic-gate * Argument for SIOC[GS]MSFILTER ioctls 10617c478bd9Sstevel@tonic-gate */ 10627c478bd9Sstevel@tonic-gate struct group_filter { 10637c478bd9Sstevel@tonic-gate uint32_t gf_interface; /* interface index */ 10647c478bd9Sstevel@tonic-gate struct sockaddr_storage gf_group; /* multicast address */ 10657c478bd9Sstevel@tonic-gate uint32_t gf_fmode; /* filter mode */ 10667c478bd9Sstevel@tonic-gate uint32_t gf_numsrc; /* number of sources */ 10677c478bd9Sstevel@tonic-gate struct sockaddr_storage gf_slist[1]; /* source address */ 10687c478bd9Sstevel@tonic-gate }; 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 10717c478bd9Sstevel@tonic-gate #pragma pack() 10727c478bd9Sstevel@tonic-gate #endif 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate #define GROUP_FILTER_SIZE(numsrc) \ 10757c478bd9Sstevel@tonic-gate (sizeof (struct group_filter) - sizeof (struct sockaddr_storage) \ 10767c478bd9Sstevel@tonic-gate + (numsrc) * sizeof (struct sockaddr_storage)) 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate /* 10797c478bd9Sstevel@tonic-gate * Argument for SIOC[GS]IPMSFILTER ioctls (IPv4-specific) 10807c478bd9Sstevel@tonic-gate */ 10817c478bd9Sstevel@tonic-gate struct ip_msfilter { 10827c478bd9Sstevel@tonic-gate struct in_addr imsf_multiaddr; /* IP multicast address of group */ 10837c478bd9Sstevel@tonic-gate struct in_addr imsf_interface; /* local IP address of interface */ 10847c478bd9Sstevel@tonic-gate uint32_t imsf_fmode; /* filter mode */ 10857c478bd9Sstevel@tonic-gate uint32_t imsf_numsrc; /* number of sources in src_list */ 10867c478bd9Sstevel@tonic-gate struct in_addr imsf_slist[1]; /* start of source list */ 10877c478bd9Sstevel@tonic-gate }; 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate #define IP_MSFILTER_SIZE(numsrc) \ 10907c478bd9Sstevel@tonic-gate (sizeof (struct ip_msfilter) - sizeof (struct in_addr) \ 10917c478bd9Sstevel@tonic-gate + (numsrc) * sizeof (struct in_addr)) 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate /* 10947c478bd9Sstevel@tonic-gate * Multicast source filter manipulation functions in libsocket; 10957c478bd9Sstevel@tonic-gate * defined in RFC 3678. 10967c478bd9Sstevel@tonic-gate */ 10977c478bd9Sstevel@tonic-gate int setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t, 10987c478bd9Sstevel@tonic-gate uint_t, struct sockaddr_storage *); 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, uint32_t *, 11017c478bd9Sstevel@tonic-gate uint_t *, struct sockaddr_storage *); 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate int setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t, 11047c478bd9Sstevel@tonic-gate uint32_t, struct in_addr *); 11057c478bd9Sstevel@tonic-gate 11067c478bd9Sstevel@tonic-gate int getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *, 11077c478bd9Sstevel@tonic-gate uint32_t *, struct in_addr *); 11087c478bd9Sstevel@tonic-gate 11097c478bd9Sstevel@tonic-gate /* 11107c478bd9Sstevel@tonic-gate * Definitions needed for [gs]etsourcefilter(), [gs]etipv4sourcefilter() 11117c478bd9Sstevel@tonic-gate */ 11127c478bd9Sstevel@tonic-gate #define MCAST_INCLUDE 1 11137c478bd9Sstevel@tonic-gate #define MCAST_EXCLUDE 2 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate /* 111619a30e1aSrshoaib * Argument struct for IP_PKTINFO option 111719a30e1aSrshoaib */ 111819a30e1aSrshoaib typedef struct in_pktinfo { 111919a30e1aSrshoaib unsigned int ipi_ifindex; /* send/recv interface index */ 112019a30e1aSrshoaib struct in_addr ipi_spec_dst; /* matched source address */ 112119a30e1aSrshoaib struct in_addr ipi_addr; /* src/dst address in IP hdr */ 112219a30e1aSrshoaib } in_pktinfo_t; 112319a30e1aSrshoaib 112419a30e1aSrshoaib /* 11257c478bd9Sstevel@tonic-gate * Argument struct for IPV6_PKTINFO option 11267c478bd9Sstevel@tonic-gate */ 11277c478bd9Sstevel@tonic-gate struct in6_pktinfo { 11287c478bd9Sstevel@tonic-gate struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 11297c478bd9Sstevel@tonic-gate unsigned int ipi6_ifindex; /* send/recv interface index */ 11307c478bd9Sstevel@tonic-gate }; 11317c478bd9Sstevel@tonic-gate 11327c478bd9Sstevel@tonic-gate /* 11337c478bd9Sstevel@tonic-gate * Argument struct for IPV6_MTUINFO option 11347c478bd9Sstevel@tonic-gate */ 11357c478bd9Sstevel@tonic-gate struct ip6_mtuinfo { 11367c478bd9Sstevel@tonic-gate struct sockaddr_in6 ip6m_addr; /* dst address including zone ID */ 11377c478bd9Sstevel@tonic-gate uint32_t ip6m_mtu; /* path MTU in host byte order */ 11387c478bd9Sstevel@tonic-gate }; 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate /* 11417c478bd9Sstevel@tonic-gate * IPv6 routing header types 11427c478bd9Sstevel@tonic-gate */ 11437c478bd9Sstevel@tonic-gate #define IPV6_RTHDR_TYPE_0 0 11447c478bd9Sstevel@tonic-gate 11457c478bd9Sstevel@tonic-gate extern socklen_t inet6_rth_space(int type, int segments); 11467c478bd9Sstevel@tonic-gate extern void *inet6_rth_init(void *bp, socklen_t bp_len, int type, int segments); 11477c478bd9Sstevel@tonic-gate extern int inet6_rth_add(void *bp, const struct in6_addr *addr); 11487c478bd9Sstevel@tonic-gate extern int inet6_rth_reverse(const void *in, void *out); 11497c478bd9Sstevel@tonic-gate extern int inet6_rth_segments(const void *bp); 11507c478bd9Sstevel@tonic-gate extern struct in6_addr *inet6_rth_getaddr(const void *bp, int index); 11517c478bd9Sstevel@tonic-gate 11527c478bd9Sstevel@tonic-gate extern int inet6_opt_init(void *extbuf, socklen_t extlen); 11537c478bd9Sstevel@tonic-gate extern int inet6_opt_append(void *extbuf, socklen_t extlen, int offset, 11547c478bd9Sstevel@tonic-gate uint8_t type, socklen_t len, uint_t align, void **databufp); 11557c478bd9Sstevel@tonic-gate extern int inet6_opt_finish(void *extbuf, socklen_t extlen, int offset); 11567c478bd9Sstevel@tonic-gate extern int inet6_opt_set_val(void *databuf, int offset, void *val, 11577c478bd9Sstevel@tonic-gate socklen_t vallen); 11587c478bd9Sstevel@tonic-gate extern int inet6_opt_next(void *extbuf, socklen_t extlen, int offset, 11597c478bd9Sstevel@tonic-gate uint8_t *typep, socklen_t *lenp, void **databufp); 11607c478bd9Sstevel@tonic-gate extern int inet6_opt_find(void *extbufp, socklen_t extlen, int offset, 11617c478bd9Sstevel@tonic-gate uint8_t type, socklen_t *lenp, void **databufp); 11627c478bd9Sstevel@tonic-gate extern int inet6_opt_get_val(void *databuf, int offset, void *val, 11637c478bd9Sstevel@tonic-gate socklen_t vallen); 11647c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate /* 11677c478bd9Sstevel@tonic-gate * Argument structure for IP_ADD_PROXY_ADDR. 11687c478bd9Sstevel@tonic-gate * Note that this is an unstable, experimental interface. It may change 11697c478bd9Sstevel@tonic-gate * later. Don't use it unless you know what it is. 11707c478bd9Sstevel@tonic-gate */ 11717c478bd9Sstevel@tonic-gate typedef struct { 11727c478bd9Sstevel@tonic-gate struct in_addr in_prefix_addr; 11737c478bd9Sstevel@tonic-gate unsigned int in_prefix_len; 11747c478bd9Sstevel@tonic-gate } in_prefix_t; 11757c478bd9Sstevel@tonic-gate 11767c478bd9Sstevel@tonic-gate 1177*6daf81a9SLauri Tirkkonen #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 11787c478bd9Sstevel@tonic-gate /* 11797c478bd9Sstevel@tonic-gate * IPv6 options 11807c478bd9Sstevel@tonic-gate */ 11817c478bd9Sstevel@tonic-gate #define IPV6_UNICAST_HOPS 0x5 /* hop limit value for unicast */ 11827c478bd9Sstevel@tonic-gate /* packets. */ 11837c478bd9Sstevel@tonic-gate /* argument type: uint_t */ 11847c478bd9Sstevel@tonic-gate #define IPV6_MULTICAST_IF 0x6 /* outgoing interface for */ 11857c478bd9Sstevel@tonic-gate /* multicast packets. */ 11867c478bd9Sstevel@tonic-gate /* argument type: struct in6_addr */ 11877c478bd9Sstevel@tonic-gate #define IPV6_MULTICAST_HOPS 0x7 /* hop limit value to use for */ 11887c478bd9Sstevel@tonic-gate /* multicast packets. */ 11897c478bd9Sstevel@tonic-gate /* argument type: uint_t */ 11907c478bd9Sstevel@tonic-gate #define IPV6_MULTICAST_LOOP 0x8 /* enable/disable delivery of */ 11917c478bd9Sstevel@tonic-gate /* multicast packets on same socket. */ 11927c478bd9Sstevel@tonic-gate /* argument type: uint_t */ 11937c478bd9Sstevel@tonic-gate #define IPV6_JOIN_GROUP 0x9 /* join an IPv6 multicast group. */ 11947c478bd9Sstevel@tonic-gate /* argument type: struct ipv6_mreq */ 11957c478bd9Sstevel@tonic-gate #define IPV6_LEAVE_GROUP 0xa /* leave an IPv6 multicast group */ 11967c478bd9Sstevel@tonic-gate /* argument type: struct ipv6_mreq */ 1197*6daf81a9SLauri Tirkkonen 1198*6daf81a9SLauri Tirkkonen /* 1199*6daf81a9SLauri Tirkkonen * Other XPG6 constants. 1200*6daf81a9SLauri Tirkkonen */ 1201*6daf81a9SLauri Tirkkonen #define INET_ADDRSTRLEN 16 /* max len IPv4 addr in ascii dotted */ 1202*6daf81a9SLauri Tirkkonen /* decimal notation. */ 1203*6daf81a9SLauri Tirkkonen #define INET6_ADDRSTRLEN 46 /* max len of IPv6 addr in ascii */ 1204*6daf81a9SLauri Tirkkonen /* standard colon-hex notation. */ 1205*6daf81a9SLauri Tirkkonen 1206*6daf81a9SLauri Tirkkonen #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 1207*6daf81a9SLauri Tirkkonen 1208*6daf81a9SLauri Tirkkonen #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1209*6daf81a9SLauri Tirkkonen 12107c478bd9Sstevel@tonic-gate /* 12117c478bd9Sstevel@tonic-gate * IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP are being kept 12127c478bd9Sstevel@tonic-gate * for backward compatibility. They have the same meaning as IPV6_JOIN_GROUP 12137c478bd9Sstevel@tonic-gate * and IPV6_LEAVE_GROUP respectively. 12147c478bd9Sstevel@tonic-gate */ 12157c478bd9Sstevel@tonic-gate #define IPV6_ADD_MEMBERSHIP 0x9 /* join an IPv6 multicast group. */ 12167c478bd9Sstevel@tonic-gate /* argument type: struct ipv6_mreq */ 12177c478bd9Sstevel@tonic-gate #define IPV6_DROP_MEMBERSHIP 0xa /* leave an IPv6 multicast group */ 12187c478bd9Sstevel@tonic-gate /* argument type: struct ipv6_mreq */ 12197c478bd9Sstevel@tonic-gate 12207c478bd9Sstevel@tonic-gate #define IPV6_PKTINFO 0xb /* addr plus interface index */ 12217c478bd9Sstevel@tonic-gate /* arg type: "struct in6_pktingo" - */ 12227c478bd9Sstevel@tonic-gate #define IPV6_HOPLIMIT 0xc /* hoplimit for datagram */ 12237c478bd9Sstevel@tonic-gate #define IPV6_NEXTHOP 0xd /* next hop address */ 12247c478bd9Sstevel@tonic-gate #define IPV6_HOPOPTS 0xe /* hop by hop options */ 12257c478bd9Sstevel@tonic-gate #define IPV6_DSTOPTS 0xf /* destination options - after */ 12267c478bd9Sstevel@tonic-gate /* the routing header */ 12277c478bd9Sstevel@tonic-gate #define IPV6_RTHDR 0x10 /* routing header */ 12287c478bd9Sstevel@tonic-gate #define IPV6_RTHDRDSTOPTS 0x11 /* destination options - before */ 12297c478bd9Sstevel@tonic-gate /* the routing header */ 12307c478bd9Sstevel@tonic-gate #define IPV6_RECVPKTINFO 0x12 /* enable/disable IPV6_PKTINFO */ 12317c478bd9Sstevel@tonic-gate #define IPV6_RECVHOPLIMIT 0x13 /* enable/disable IPV6_HOPLIMIT */ 12327c478bd9Sstevel@tonic-gate #define IPV6_RECVHOPOPTS 0x14 /* enable/disable IPV6_HOPOPTS */ 12337c478bd9Sstevel@tonic-gate 12347c478bd9Sstevel@tonic-gate /* 12357c478bd9Sstevel@tonic-gate * This options exists for backwards compatability and should no longer be 12367c478bd9Sstevel@tonic-gate * used. Use IPV6_RECVDSTOPTS instead. 12377c478bd9Sstevel@tonic-gate */ 12387c478bd9Sstevel@tonic-gate #define _OLD_IPV6_RECVDSTOPTS 0x15 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate #define IPV6_RECVRTHDR 0x16 /* enable/disable IPV6_RTHDR */ 12417c478bd9Sstevel@tonic-gate 12427c478bd9Sstevel@tonic-gate /* 12437c478bd9Sstevel@tonic-gate * enable/disable IPV6_RTHDRDSTOPTS. Now obsolete. IPV6_RECVDSTOPTS enables 12447c478bd9Sstevel@tonic-gate * the receipt of both headers. 12457c478bd9Sstevel@tonic-gate */ 12467c478bd9Sstevel@tonic-gate #define IPV6_RECVRTHDRDSTOPTS 0x17 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate #define IPV6_CHECKSUM 0x18 /* Control checksum on raw sockets */ 12497c478bd9Sstevel@tonic-gate #define IPV6_RECVTCLASS 0x19 /* enable/disable IPV6_CLASS */ 12507c478bd9Sstevel@tonic-gate #define IPV6_USE_MIN_MTU 0x20 /* send packets with minimum MTU */ 12517c478bd9Sstevel@tonic-gate #define IPV6_DONTFRAG 0x21 /* don't fragment packets */ 12527c478bd9Sstevel@tonic-gate #define IPV6_SEC_OPT 0x22 /* Used to set IPSEC options */ 12537c478bd9Sstevel@tonic-gate #define IPV6_SRC_PREFERENCES 0x23 /* Control socket's src addr select */ 12547c478bd9Sstevel@tonic-gate #define IPV6_RECVPATHMTU 0x24 /* receive PMTU info */ 12557c478bd9Sstevel@tonic-gate #define IPV6_PATHMTU 0x25 /* get the PMTU */ 12567c478bd9Sstevel@tonic-gate #define IPV6_TCLASS 0x26 /* traffic class */ 12577c478bd9Sstevel@tonic-gate #define IPV6_V6ONLY 0x27 /* v6 only socket option */ 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate /* 12607c478bd9Sstevel@tonic-gate * enable/disable receipt of both both IPV6_DSTOPTS headers. 12617c478bd9Sstevel@tonic-gate */ 12627c478bd9Sstevel@tonic-gate #define IPV6_RECVDSTOPTS 0x28 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate /* 12657c478bd9Sstevel@tonic-gate * protocol-independent multicast membership options. 12667c478bd9Sstevel@tonic-gate */ 12677c478bd9Sstevel@tonic-gate #define MCAST_JOIN_GROUP 0x29 /* join group for all sources */ 12687c478bd9Sstevel@tonic-gate #define MCAST_LEAVE_GROUP 0x2a /* leave group */ 12697c478bd9Sstevel@tonic-gate #define MCAST_BLOCK_SOURCE 0x2b /* block specified source */ 12707c478bd9Sstevel@tonic-gate #define MCAST_UNBLOCK_SOURCE 0x2c /* unblock specified source */ 12717c478bd9Sstevel@tonic-gate #define MCAST_JOIN_SOURCE_GROUP 0x2d /* join group for specified source */ 12727c478bd9Sstevel@tonic-gate #define MCAST_LEAVE_SOURCE_GROUP 0x2e /* leave source/group pair */ 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate /* 32Bit field for IPV6_SRC_PREFERENCES */ 12757c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_HOME 0x00000001 12767c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_COA 0x00000002 12777c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_PUBLIC 0x00000004 12787c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_TMP 0x00000008 12797c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_NONCGA 0x00000010 12807c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_CGA 0x00000020 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_MIPMASK (IPV6_PREFER_SRC_HOME | IPV6_PREFER_SRC_COA) 12837c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_MIPDEFAULT IPV6_PREFER_SRC_HOME 12847c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_TMPMASK (IPV6_PREFER_SRC_PUBLIC | IPV6_PREFER_SRC_TMP) 12857c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_TMPDEFAULT IPV6_PREFER_SRC_PUBLIC 12867c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_CGAMASK (IPV6_PREFER_SRC_NONCGA | IPV6_PREFER_SRC_CGA) 12877c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_CGADEFAULT IPV6_PREFER_SRC_NONCGA 12887c478bd9Sstevel@tonic-gate 12897c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_MASK (IPV6_PREFER_SRC_MIPMASK |\ 12907c478bd9Sstevel@tonic-gate IPV6_PREFER_SRC_TMPMASK | IPV6_PREFER_SRC_CGAMASK) 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate #define IPV6_PREFER_SRC_DEFAULT (IPV6_PREFER_SRC_MIPDEFAULT |\ 12937c478bd9Sstevel@tonic-gate IPV6_PREFER_SRC_TMPDEFAULT | IPV6_PREFER_SRC_CGADEFAULT) 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate /* 12967c478bd9Sstevel@tonic-gate * SunOS private (potentially not portable) IPV6_ option names 12977c478bd9Sstevel@tonic-gate */ 12987c478bd9Sstevel@tonic-gate #define IPV6_BOUND_IF 0x41 /* bind to an ifindex */ 12997c478bd9Sstevel@tonic-gate #define IPV6_UNSPEC_SRC 0x42 /* source of packets set to */ 13007c478bd9Sstevel@tonic-gate /* unspecified (all zeros) */ 13017c478bd9Sstevel@tonic-gate 13027c478bd9Sstevel@tonic-gate /* 13037c478bd9Sstevel@tonic-gate * Miscellaneous IPv6 constants. 13047c478bd9Sstevel@tonic-gate */ 13057c478bd9Sstevel@tonic-gate #define IPV6_PAD1_OPT 0 /* pad byte in IPv6 extension hdrs */ 13067c478bd9Sstevel@tonic-gate 13077c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 13087c478bd9Sstevel@tonic-gate 13097c478bd9Sstevel@tonic-gate /* 13107c478bd9Sstevel@tonic-gate * Extern declarations for pre-defined global const variables 13117c478bd9Sstevel@tonic-gate */ 1312*6daf81a9SLauri Tirkkonen #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) 13137c478bd9Sstevel@tonic-gate #ifndef _KERNEL 13147c478bd9Sstevel@tonic-gate #ifdef __STDC__ 13157c478bd9Sstevel@tonic-gate extern const struct in6_addr in6addr_any; 13167c478bd9Sstevel@tonic-gate extern const struct in6_addr in6addr_loopback; 13177c478bd9Sstevel@tonic-gate #else 13187c478bd9Sstevel@tonic-gate extern struct in6_addr in6addr_any; 13197c478bd9Sstevel@tonic-gate extern struct in6_addr in6addr_loopback; 13207c478bd9Sstevel@tonic-gate #endif 13217c478bd9Sstevel@tonic-gate #endif 1322*6daf81a9SLauri Tirkkonen #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ 13237c478bd9Sstevel@tonic-gate 13247c478bd9Sstevel@tonic-gate #ifdef __cplusplus 13257c478bd9Sstevel@tonic-gate } 13267c478bd9Sstevel@tonic-gate #endif 13277c478bd9Sstevel@tonic-gate 13287c478bd9Sstevel@tonic-gate #endif /* _NETINET_IN_H */ 1329