xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
beast
net
IPAddressV4.cpp
1
#include <xrpl/beast/net/IPAddressV4.h>
2
3
namespace
beast::ip
{
4
5
bool
6
isPrivate
(
AddressV4
const
& addr)
7
{
8
return
((addr.to_uint() & 0xff000000) == 0x0a000000) ||
// Prefix /8, 10. #.#.#
9
((addr.to_uint() & 0xfff00000) == 0xac100000) ||
// Prefix /12 172. 16.#.# - 172.31.#.#
10
((addr.to_uint() & 0xffff0000) == 0xc0a80000) ||
// Prefix /16 192.168.#.#
11
addr.is_loopback();
12
}
13
14
bool
15
isPublic
(
AddressV4
const
& addr)
16
{
17
if
(
isPrivate
(addr))
18
return
false
;
19
if
(addr.is_multicast())
20
return
false
;
21
22
auto
const
ip
= addr.to_uint();
23
24
// 0.0.0.0/8 "This network"
25
if
((
ip
& 0xff000000) == 0x00000000)
26
return
false
;
27
// 100.64.0.0/10 Shared Address Space (CGNAT) - RFC 6598
28
if
((
ip
& 0xffc00000) == 0x64400000)
29
return
false
;
30
// 169.254.0.0/16 Link-local
31
if
((
ip
& 0xffff0000) == 0xa9fe0000)
32
return
false
;
33
// 192.0.0.0/24 IETF Protocol Assignments - RFC 6890
34
if
((
ip
& 0xffffff00) == 0xc0000000)
35
return
false
;
36
// 192.0.2.0/24 TEST-NET-1 (documentation) - RFC 5737
37
if
((
ip
& 0xffffff00) == 0xc0000200)
38
return
false
;
39
// 192.88.99.0/24 6to4 Relay Anycast (deprecated) - RFC 7526
40
if
((
ip
& 0xffffff00) == 0xc0586300)
41
return
false
;
42
// 198.18.0.0/15 Benchmarking - RFC 2544
43
if
((
ip
& 0xfffe0000) == 0xc6120000)
44
return
false
;
45
// 198.51.100.0/24 TEST-NET-2 (documentation) - RFC 5737
46
if
((
ip
& 0xffffff00) == 0xc6336400)
47
return
false
;
48
// 203.0.113.0/24 TEST-NET-3 (documentation) - RFC 5737
49
if
((
ip
& 0xffffff00) == 0xcb007100)
50
return
false
;
51
// 240.0.0.0/4 Reserved for future use - RFC 1112
52
if
((
ip
& 0xf0000000) == 0xf0000000)
53
return
false
;
54
55
return
true
;
56
}
57
58
char
59
getClass
(
AddressV4
const
& addr)
60
{
61
static
char
const
* kTable =
"AAAABBCD"
;
// cspell:disable-line
62
return
kTable[(addr.to_uint() & 0xE0000000) >> 29];
63
}
64
65
}
// namespace beast::ip
beast::ip
Definition
IPAddress.h:18
beast::ip::getClass
char getClass(AddressV4 const &address)
Returns the address class for the given address.
Definition
IPAddressV4.cpp:59
beast::ip::isPublic
bool isPublic(Address const &addr)
Returns true if the address is a public routable address.
Definition
IPAddress.h:71
beast::ip::AddressV4
boost::asio::ip::address_v4 AddressV4
Definition
IPAddressV4.h:7
beast::ip::isPrivate
bool isPrivate(Address const &addr)
Returns true if the address is a private unroutable address.
Definition
IPAddress.h:62
Generated by
1.17.0