sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
ip6_addr.h
Go to the documentation of this file.
1
7
8
/*
9
* Copyright (c) 2010 Inico Technologies Ltd.
10
* All rights reserved.
11
*
12
* Redistribution and use in source and binary forms, with or without modification,
13
* are permitted provided that the following conditions are met:
14
*
15
* 1. Redistributions of source code must retain the above copyright notice,
16
* this list of conditions and the following disclaimer.
17
* 2. Redistributions in binary form must reproduce the above copyright notice,
18
* this list of conditions and the following disclaimer in the documentation
19
* and/or other materials provided with the distribution.
20
* 3. The name of the author may not be used to endorse or promote products
21
* derived from this software without specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32
* OF SUCH DAMAGE.
33
*
34
* This file is part of the lwIP TCP/IP stack.
35
*
36
* Author: Ivan Delamer <delamer@inicotech.com>
37
*
38
* Structs and macros for handling IPv6 addresses.
39
*
40
* Please coordinate changes and requests with Ivan Delamer
41
* <delamer@inicotech.com>
42
*/
43
#ifndef LWIP_HDR_IP6_ADDR_H
44
#define LWIP_HDR_IP6_ADDR_H
45
46
#include "
lwip/opt.h
"
47
#include "
def.h
"
48
49
#if LWIP_IPV6
/* don't build if not configured for use in lwipopts.h */
50
51
#include "
lwip/ip6_zone.h
"
52
53
#ifdef __cplusplus
54
extern
"C"
{
55
#endif
56
57
60
struct
ip6_addr
{
61
u32_t addr[4];
62
#if LWIP_IPV6_SCOPES
63
u8_t zone;
64
#endif
/* LWIP_IPV6_SCOPES */
65
};
66
68
typedef
struct
ip6_addr
ip6_addr_t
;
69
71
#define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \
72
(ip6addr)->addr[index] = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
73
76
#define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \
77
(ip6addr)->addr[0] = idx0; \
78
(ip6addr)->addr[1] = idx1; \
79
(ip6addr)->addr[2] = idx2; \
80
(ip6addr)->addr[3] = idx3; \
81
ip6_addr_clear_zone(ip6addr); } while(0)
82
84
#define IP6_ADDR_BLOCK1(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
86
#define IP6_ADDR_BLOCK2(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
88
#define IP6_ADDR_BLOCK3(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
90
#define IP6_ADDR_BLOCK4(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
92
#define IP6_ADDR_BLOCK5(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
94
#define IP6_ADDR_BLOCK6(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
96
#define IP6_ADDR_BLOCK7(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
98
#define IP6_ADDR_BLOCK8(ip6addr) ((u16_t)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
99
101
#define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
102
(dest).addr[1] = (src).addr[1]; \
103
(dest).addr[2] = (src).addr[2]; \
104
(dest).addr[3] = (src).addr[3]; \
105
ip6_addr_copy_zone((dest), (src)); }while(0)
107
#define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
108
(dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
109
(dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
110
(dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3]; \
111
ip6_addr_set_zone((dest), (src) == NULL ? IP6_NO_ZONE : ip6_addr_zone(src)); }while(0)
112
114
#define ip6_addr_copy_from_packed(dest, src) do{(dest).addr[0] = (src).addr[0]; \
115
(dest).addr[1] = (src).addr[1]; \
116
(dest).addr[2] = (src).addr[2]; \
117
(dest).addr[3] = (src).addr[3]; \
118
ip6_addr_clear_zone(&dest); }while(0)
119
121
#define ip6_addr_copy_to_packed(dest, src) do{(dest).addr[0] = (src).addr[0]; \
122
(dest).addr[1] = (src).addr[1]; \
123
(dest).addr[2] = (src).addr[2]; \
124
(dest).addr[3] = (src).addr[3]; }while(0)
125
127
#define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \
128
(ip6addr)->addr[1] = 0; \
129
(ip6addr)->addr[2] = 0; \
130
(ip6addr)->addr[3] = 0; \
131
ip6_addr_clear_zone(ip6addr);}while(0)
132
134
#define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
136
#define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \
137
(ip6addr)->addr[1] = 0; \
138
(ip6addr)->addr[2] = 0; \
139
(ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \
140
ip6_addr_clear_zone(ip6addr);}while(0)
143
#define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
144
(dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
145
(dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
146
(dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]); \
147
ip6_addr_set_zone((dest), (src) == NULL ? IP6_NO_ZONE : ip6_addr_zone(src));}while(0)
148
149
151
#define ip6_addr_netcmp_zoneless(addr1, addr2) ip6_addr_net_zoneless_eq(addr1, addr2)
153
#define ip6_addr_net_zoneless_eq(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
154
((addr1)->addr[1] == (addr2)->addr[1]))
155
160
#define ip6_addr_netcmp(addr1, addr2) ip6_addr_net_eq(addr1, addr2)
168
#define ip6_addr_net_eq(addr1, addr2) (ip6_addr_net_zoneless_eq((addr1), (addr2)) && \
169
ip6_addr_zone_eq((addr1), (addr2)))
170
171
#define ip6_addr_nethostcmp(addr1, addr2) ip6_addr_nethost_eq(addr1, addr2)
172
/* Exact-host comparison *after* ip6_addr_net_eq() succeeded, for efficiency. */
173
#define ip6_addr_nethost_eq(addr1, addr2) (((addr1)->addr[2] == (addr2)->addr[2]) && \
174
((addr1)->addr[3] == (addr2)->addr[3]))
175
177
#define ip6_addr_cmp_zoneless(addr1, addr2) ip6_addr_zoneless_eq(addr1, addr2)
179
#define ip6_addr_zoneless_eq(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
180
((addr1)->addr[1] == (addr2)->addr[1]) && \
181
((addr1)->addr[2] == (addr2)->addr[2]) && \
182
((addr1)->addr[3] == (addr2)->addr[3]))
184
#define ip6_addr_cmp(addr1, addr2) ip6_addr_eq(addr1, addr2)
193
#define ip6_addr_eq(addr1, addr2) (ip6_addr_zoneless_eq((addr1), (addr2)) && \
194
ip6_addr_zone_eq((addr1), (addr2)))
195
197
#define ip6_addr_cmp_packed(ip6addr, paddr, zone_idx) ip6_addr_packed_eq(ip6addr, paddr, zone_idx)
199
#define ip6_addr_packed_eq(ip6addr, paddr, zone_idx) (((ip6addr)->addr[0] == (paddr)->addr[0]) && \
200
((ip6addr)->addr[1] == (paddr)->addr[1]) && \
201
((ip6addr)->addr[2] == (paddr)->addr[2]) && \
202
((ip6addr)->addr[3] == (paddr)->addr[3]) && \
203
ip6_addr_equals_zone((ip6addr), (zone_idx)))
204
205
#define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
206
207
#define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
208
((ip6addr).addr[1] == 0) && \
209
((ip6addr).addr[2] == 0) && \
210
((ip6addr).addr[3] == 0))
211
#define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
212
213
#define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
214
((ip6addr)->addr[1] == 0UL) && \
215
((ip6addr)->addr[2] == 0UL) && \
216
((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
217
218
#define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
219
220
#define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
221
222
#define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
223
224
#define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
225
226
#define ip6_addr_isipv4mappedipv6(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
227
228
#define ip6_addr_isipv4compat(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
229
((ip6addr)->addr[1] == 0UL) && \
230
((ip6addr)->addr[2] == 0UL) && \
231
(htonl((ip6addr)->addr[3]) > 1))
232
233
#define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
234
#define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
235
#define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
236
#define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
237
#define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
238
#define IP6_MULTICAST_SCOPE_RESERVED 0x0
239
#define IP6_MULTICAST_SCOPE_RESERVED0 0x0
240
#define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1
241
#define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2
242
#define IP6_MULTICAST_SCOPE_RESERVED3 0x3
243
#define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4
244
#define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5
245
#define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8
246
#define IP6_MULTICAST_SCOPE_GLOBAL 0xe
247
#define IP6_MULTICAST_SCOPE_RESERVEDF 0xf
248
#define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
249
#define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
250
#define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
251
#define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
252
#define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
253
#define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
254
255
/* Scoping note: while interface-local and link-local multicast addresses do
256
* have a scope (i.e., they are meaningful only in the context of a particular
257
* interface), the following functions are not assigning or comparing zone
258
* indices. The reason for this is backward compatibility. Any call site that
259
* produces a non-global multicast address must assign a multicast address as
260
* appropriate itself. */
261
262
#define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
263
((ip6addr)->addr[1] == 0UL) && \
264
((ip6addr)->addr[2] == 0UL) && \
265
((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
266
267
#define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
268
((ip6addr)->addr[1] == 0UL) && \
269
((ip6addr)->addr[2] == 0UL) && \
270
((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
271
#define ip6_addr_set_allnodes_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
272
(ip6addr)->addr[1] = 0; \
273
(ip6addr)->addr[2] = 0; \
274
(ip6addr)->addr[3] = PP_HTONL(0x00000001UL); \
275
ip6_addr_clear_zone(ip6addr); }while(0)
276
277
#define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
278
((ip6addr)->addr[1] == 0UL) && \
279
((ip6addr)->addr[2] == 0UL) && \
280
((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
281
#define ip6_addr_set_allrouters_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
282
(ip6addr)->addr[1] = 0; \
283
(ip6addr)->addr[2] = 0; \
284
(ip6addr)->addr[3] = PP_HTONL(0x00000002UL); \
285
ip6_addr_clear_zone(ip6addr); }while(0)
286
287
#define ip6_addr_issolicitednode(ip6addr) ( ((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
288
((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
289
(((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) )
290
291
#define ip6_addr_set_solicitednode(ip6addr, if_id) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
292
(ip6addr)->addr[1] = 0; \
293
(ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
294
(ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id)); \
295
ip6_addr_clear_zone(ip6addr); }while(0)
296
297
#define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) ip6_addr_solicitednode_eq(ip6addr, sn_addr)
298
#define ip6_addr_solicitednode_eq(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
299
((ip6addr)->addr[1] == 0) && \
300
((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
301
((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
302
303
/* IPv6 address states. */
304
#define IP6_ADDR_INVALID 0x00
305
#define IP6_ADDR_TENTATIVE 0x08
306
#define IP6_ADDR_TENTATIVE_1 0x09
/* 1 probe sent */
307
#define IP6_ADDR_TENTATIVE_2 0x0a
/* 2 probes sent */
308
#define IP6_ADDR_TENTATIVE_3 0x0b
/* 3 probes sent */
309
#define IP6_ADDR_TENTATIVE_4 0x0c
/* 4 probes sent */
310
#define IP6_ADDR_TENTATIVE_5 0x0d
/* 5 probes sent */
311
#define IP6_ADDR_TENTATIVE_6 0x0e
/* 6 probes sent */
312
#define IP6_ADDR_TENTATIVE_7 0x0f
/* 7 probes sent */
313
#define IP6_ADDR_VALID 0x10
/* This bit marks an address as valid (preferred or deprecated) */
314
#define IP6_ADDR_PREFERRED 0x30
315
#define IP6_ADDR_DEPRECATED 0x10
/* Same as VALID (valid but not preferred) */
316
#define IP6_ADDR_DUPLICATED 0x40
/* Failed DAD test, not valid */
317
318
#define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07
/* 1-7 probes sent */
319
320
#define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
321
#define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
322
#define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID)
/* Include valid, preferred, and deprecated. */
323
#define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
324
#define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
325
#define ip6_addr_isduplicated(addr_state) (addr_state == IP6_ADDR_DUPLICATED)
326
327
#if LWIP_IPV6_ADDRESS_LIFETIMES
328
#define IP6_ADDR_LIFE_STATIC (0)
329
#define IP6_ADDR_LIFE_INFINITE (0xffffffffUL)
330
#define ip6_addr_life_isstatic(addr_life) ((addr_life) == IP6_ADDR_LIFE_STATIC)
331
#define ip6_addr_life_isinfinite(addr_life) ((addr_life) == IP6_ADDR_LIFE_INFINITE)
332
#endif
/* LWIP_IPV6_ADDRESS_LIFETIMES */
333
334
#define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
335
LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
336
a, b, c, d, e, f, g, h))
337
#define ip6_addr_debug_print(debug, ipaddr) \
338
ip6_addr_debug_print_parts(debug, \
339
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \
340
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \
341
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \
342
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \
343
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \
344
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \
345
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \
346
(u16_t)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
347
#define ip6_addr_debug_print_val(debug, ipaddr) \
348
ip6_addr_debug_print_parts(debug, \
349
IP6_ADDR_BLOCK1(&(ipaddr)), \
350
IP6_ADDR_BLOCK2(&(ipaddr)), \
351
IP6_ADDR_BLOCK3(&(ipaddr)), \
352
IP6_ADDR_BLOCK4(&(ipaddr)), \
353
IP6_ADDR_BLOCK5(&(ipaddr)), \
354
IP6_ADDR_BLOCK6(&(ipaddr)), \
355
IP6_ADDR_BLOCK7(&(ipaddr)), \
356
IP6_ADDR_BLOCK8(&(ipaddr)))
357
358
#define IP6ADDR_STRLEN_MAX 46
359
360
int
ip6addr_aton(
const
char
*cp,
ip6_addr_t
*addr);
362
char
*ip6addr_ntoa(
const
ip6_addr_t
*addr);
363
char
*ip6addr_ntoa_r(
const
ip6_addr_t
*addr,
char
*buf,
int
buflen);
364
365
366
367
#ifdef __cplusplus
368
}
369
#endif
370
371
#endif
/* LWIP_IPV6 */
372
373
#endif
/* LWIP_HDR_IP6_ADDR_H */
ip6_addr_t
struct ip6_addr ip6_addr_t
Definition
tcpip.h:434
def.h
ip6_zone.h
opt.h
ip6_addr
Definition
tcpip.h:429
core
ps2ip
include
lwip_include
lwip
ip6_addr.h
Generated by
1.18.0