rippled
Loading...
Searching...
No Matches
IPAddress.h
1#pragma once
2
3#include <xrpl/beast/hash/hash_append.h>
4#include <xrpl/beast/hash/uhash.h>
5#include <xrpl/beast/net/IPAddressV4.h>
6#include <xrpl/beast/net/IPAddressV6.h>
7#include <xrpl/beast/utility/instrumentation.h>
8
9#include <boost/asio/ip/address.hpp>
10#include <boost/functional/hash.hpp>
11
12#include <string>
13
14//------------------------------------------------------------------------------
15
16namespace beast {
17namespace IP {
18
19using Address = boost::asio::ip::address;
20
22inline std::string
23to_string(Address const& addr)
24{
25 return addr.to_string();
26}
27
29inline bool
30is_loopback(Address const& addr)
31{
32 return addr.is_loopback();
33}
34
36inline bool
38{
39 return addr.is_unspecified();
40}
41
43inline bool
45{
46 return addr.is_multicast();
47}
48
50inline bool
51is_private(Address const& addr)
52{
53 return (addr.is_v4()) ? is_private(addr.to_v4()) : is_private(addr.to_v6());
54}
55
57inline bool
58is_public(Address const& addr)
59{
60 return (addr.is_v4()) ? is_public(addr.to_v4()) : is_public(addr.to_v6());
61}
62
63} // namespace IP
64
65//------------------------------------------------------------------------------
66
67template <class Hasher>
68void
69hash_append(Hasher& h, beast::IP::Address const& addr) noexcept
70{
72 if (addr.is_v4())
73 hash_append(h, addr.to_v4().to_bytes());
74 else if (addr.is_v6())
75 hash_append(h, addr.to_v6().to_bytes());
76 else
77 {
78 // LCOV_EXCL_START
79 UNREACHABLE("beast::hash_append : invalid address type");
80 // LCOV_EXCL_STOP
81 }
82}
83} // namespace beast
84
85namespace boost {
86template <>
87struct hash<::beast::IP::Address>
88{
89 explicit hash() = default;
90
93 {
94 return ::beast::uhash<>{}(addr);
95 }
96};
97} // namespace boost
bool is_multicast(Address const &addr)
Returns true if the address is a multicast address.
Definition IPAddress.h:44
bool is_loopback(Address const &addr)
Returns true if this is a loopback address.
Definition IPAddress.h:30
bool is_public(Address const &addr)
Returns true if the address is a public routable address.
Definition IPAddress.h:58
bool is_unspecified(Address const &addr)
Returns true if the address is unspecified.
Definition IPAddress.h:37
boost::asio::ip::address Address
Definition IPAddress.h:19
bool is_private(Address const &addr)
Returns true if the address is a private unroutable address.
Definition IPAddress.h:51
std::string to_string(Address const &addr)
Returns the address represented as a string.
Definition IPAddress.h:23
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
std::size_t operator()(::beast::IP::Address const &addr) const
Definition IPAddress.h:92