9
9
#include <arpa/inet.h>
13
#define IPPROTO_IP IPPROTO_IP
15
#define IPPROTO_TCP IPPROTO_TCP
17
#define IPPROTO_UDP IPPROTO_UDP
14
#define IPPROTO_IP IPPROTO_IP
16
#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS
18
#define IPPROTO_ICMP IPPROTO_ICMP
20
#define IPPROTO_IGMP IPPROTO_IGMP
22
#define IPPROTO_IPIP IPPROTO_IPIP
24
#define IPPROTO_TCP IPPROTO_TCP
26
#define IPPROTO_EGP IPPROTO_EGP
28
#define IPPROTO_PUP IPPROTO_PUP
30
#define IPPROTO_UDP IPPROTO_UDP
32
#define IPPROTO_IDP IPPROTO_IDP
34
#define IPPROTO_TP IPPROTO_TP
36
#define IPPROTO_DCCP IPPROTO_DCCP
38
#define IPPROTO_IPV6 IPPROTO_IPV6
40
#define IPPROTO_ROUTING IPPROTO_ROUTING
41
IPPROTO_FRAGMENT = 44,
42
#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT
44
#define IPPROTO_RSVP IPPROTO_RSVP
46
#define IPPROTO_GRE IPPROTO_GRE
48
#define IPPROTO_ESP IPPROTO_ESP
50
#define IPPROTO_AH IPPROTO_AH
52
#define IPPROTO_ICMPV6 IPPROTO_ICMPV6
54
#define IPPROTO_NONE IPPROTO_NONE
56
#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS
58
#define IPPROTO_MTP IPPROTO_MTP
60
#define IPPROTO_ENCAP IPPROTO_ENCAP
62
#define IPPROTO_PIM IPPROTO_PIM
64
#define IPPROTO_COMP IPPROTO_COMP
66
#define IPPROTO_SCTP IPPROTO_SCTP
67
IPPROTO_UDPLITE = 136,
68
#define IPPROTO_UDPLITE IPPROTO_UDPLITE
70
#define IPPROTO_RAW IPPROTO_RAW
21
74
#define INET_ADDRSTRLEN 16
75
#define INET6_ADDRSTRLEN 46
23
77
#define INADDR_ANY 0
78
#define INADDR_LOOPBACK 0x7f000001 /* 127.0.0.1 */
26
81
unsigned long s_addr;
37
unsigned char s6_addr[16];
93
uint8_t _s6_addr8[16];
94
uint16_t _s6_addr16[8];
95
uint32_t _s6_addr32[4];
97
#define s6_addr _u._s6_addr8
98
#define s6_addr16 _u._s6_addr16
99
#define s6_addr32 _u._s6_addr32
102
extern const struct in6_addr in6addr_any;
103
extern const struct in6_addr in6addr_loopback;
104
extern const struct in6_addr in6addr_linklocal_allnodes;
105
extern const struct in6_addr in6addr_linklocal_allrouters;
106
extern const struct in6_addr in6addr_interfacelocal_allnodes;
107
extern const struct in6_addr in6addr_interfacelocal_allrouters;
108
extern const struct in6_addr in6addr_sitelocal_allrouters;
110
#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
111
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
112
#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
113
{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
114
#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
115
{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 } } }
40
117
struct sockaddr_in6 {
119
unsigned short sin6_port;
43
120
int sin6_flowinfo;
44
121
struct in6_addr sin6_addr;
45
122
int sin6_scope_id;
70
152
#define IP_MULTICAST_ALL 49
71
153
#define IP_UNICAST_IF 50
156
* Tests for IPv6 address types
159
#define IN6_IS_ADDR_LINKLOCAL(addr) \
160
(((addr)->s6_addr32[0] & htonl(0xffc00000)) == htonl(0xfe800000))
162
#define IN6_IS_ADDR_LOOPBACK(addr) \
163
(((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \
164
((addr)->s6_addr32[2] == 0) && ((addr)->s6_addr32[3] == htonl(1)))
166
#define IN6_IS_ADDR_MULTICAST(addr) \
167
((addr)->s6_addr8[0] == 0xff)
169
#define IN6_IS_ADDR_SITELOCAL(addr) \
170
(((addr)->s6_addr32[0] & htonl(0xffc00000)) == htonl(0xfec00000))
172
#define IN6_IS_ADDR_UNSPECIFIED(addr) \
173
(((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \
174
((addr)->s6_addr32[2] == 0) && ((addr)->s6_addr32[3] == 0))
176
#define IN6_IS_ADDR_V4COMPAT(addr) \
177
(((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \
178
((addr)->s6_addr32[2] == 0) && ((addr)->s6_addr32[3] & ~htonl(1)))
180
#define IN6_IS_ADDR_V4MAPPED(addr) \
181
(((addr)->s6_addr32[0] == 0) && ((addr)->s6_addr32[1] == 0) && \
182
((addr)->s6_addr32[2] == htonl(0xffff)))
184
#define IN6_ARE_ADDR_EQUAL(addr1, addr2) \
185
(((addr1)->s6_addr32[0] == (addr2)->s6_addr32[0]) && \
186
((addr1)->s6_addr32[1] == (addr2)->s6_addr32[1]) && \
187
((addr1)->s6_addr32[2] == (addr2)->s6_addr32[2]) && \
188
((addr1)->s6_addr32[3] == (addr2)->s6_addr32[3]))
191
* IPv6 Multicast scoping. The scope is stored
192
* in the bottom 4 bits of the second byte of the
195
/* 0x0 */ /* reserved */
196
#define IN6_NODE_LOCAL 0x1 /* node-local scope */
197
#define IN6_LINK_LOCAL 0x2 /* link-local scope */
198
/* 0x3 */ /* (unassigned) */
199
/* 0x4 */ /* (unassigned) */
200
#define IN6_SITE_LOCAL 0x5 /* site-local scope */
201
/* 0x6 */ /* (unassigned) */
202
/* 0x7 */ /* (unassigned) */
203
#define IN6_ORG_LOCAL 0x8 /* organization-local scope */
204
/* 0x9 */ /* (unassigned) */
205
/* 0xA */ /* (unassigned) */
206
/* 0xB */ /* (unassigned) */
207
/* 0xC */ /* (unassigned) */
208
/* 0xD */ /* (unassigned) */
209
#define IN6_GLOBAL 0xE /* global scope */
210
/* 0xF */ /* reserved */
212
#define IN6_MSCOPE(addr) ((addr)->s6_addr8[1] & 0x0f)
214
#define IN6_IS_ADDR_MC_NODELOCAL(addr) \
215
(IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_NODE_LOCAL))
216
#define IN6_IS_ADDR_MC_LINKLOCAL(addr) \
217
(IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_LINK_LOCAL))
218
#define IN6_IS_ADDR_MC_SITELOCAL(addr) \
219
(IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_SITE_LOCAL))
220
#define IN6_IS_ADDR_MC_ORGLOCAL(addr) \
221
(IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_ORG_LOCAL))
222
#define IN6_IS_ADDR_MC_GLOBAL(addr) \
223
(IN6_IS_ADDR_MULTICAST(addr) && (IN6_MSCOPE(addr) == IN6_GLOBAL))
73
225
#ifdef __cplusplus