rippled
Loading...
Searching...
No Matches
IPAddressV4.cpp
1#include <xrpl/beast/net/IPAddressV4.h>
2
3namespace beast {
4namespace IP {
5
6bool
7is_private(AddressV4 const& addr)
8{
9 return ((addr.to_uint() & 0xff000000) ==
10 0x0a000000) || // Prefix /8, 10. #.#.#
11 ((addr.to_uint() & 0xfff00000) ==
12 0xac100000) || // Prefix /12 172. 16.#.# - 172.31.#.#
13 ((addr.to_uint() & 0xffff0000) ==
14 0xc0a80000) || // Prefix /16 192.168.#.#
15 addr.is_loopback();
16}
17
18bool
19is_public(AddressV4 const& addr)
20{
21 return !is_private(addr) && !addr.is_multicast();
22}
23
24char
25get_class(AddressV4 const& addr)
26{
27 static char const* table = "AAAABBCD";
28 return table[(addr.to_uint() & 0xE0000000) >> 29];
29}
30
31} // namespace IP
32} // namespace beast
char get_class(AddressV4 const &address)
Returns the address class for the given address.
bool is_public(Address const &addr)
Returns true if the address is a public routable address.
Definition IPAddress.h:59
boost::asio::ip::address_v4 AddressV4
Definition IPAddressV4.h:11
bool is_private(Address const &addr)
Returns true if the address is a private unroutable address.
Definition IPAddress.h:52