3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "iana-ip-data.c"
15 compare_ipv4_block(const void *key
, const void *element
)
17 const uint32_t *ipnum
= key
;
18 const struct ws_iana_ip_special_block
*ptr
= element
;
20 uint32_t val
= *ipnum
& ptr
->u_ip
.ipv4
.nmask
;
22 if (val
< ptr
->u_ip
.ipv4
.addr
)
24 if (val
> ptr
->u_ip
.ipv4
.addr
)
29 const struct ws_iana_ip_special_block
*
30 ws_iana_ipv4_special_block_lookup(uint32_t ipnum
)
32 return bsearch(&ipnum
, __ipv4_special_block
, G_N_ELEMENTS(__ipv4_special_block
),
33 sizeof(struct ws_iana_ip_special_block
), compare_ipv4_block
);
36 static const uint8_t bitmasks
[9] =
37 { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
40 compare_ipv6_block(const void *key
, const void *element
)
42 const ws_in6_addr
*addr
= key
;
43 const struct ws_iana_ip_special_block
*ptr
= element
;
48 prefix
= ptr
->u_ip
.ipv6
.prefix
;
51 byte_a
= addr
->bytes
[pos
];
52 byte_b
= ptr
->u_ip
.ipv6
.addr
.bytes
[pos
];
54 return byte_a
- byte_b
;
61 byte_a
= addr
->bytes
[pos
] & bitmasks
[prefix
];
62 byte_b
= ptr
->u_ip
.ipv6
.addr
.bytes
[pos
];
64 return byte_a
- byte_b
;
70 const struct ws_iana_ip_special_block
*
71 ws_iana_ipv6_special_block_lookup(const ws_in6_addr
*addr
)
73 return bsearch(addr
, __ipv6_special_block
, G_N_ELEMENTS(__ipv6_special_block
),
74 sizeof(struct ws_iana_ip_special_block
), compare_ipv6_block
);