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