xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
beast
net
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 <
cstddef
>
13
#include <
string
>
14
15
//------------------------------------------------------------------------------
16
17
namespace
beast
{
18
namespace
ip
{
19
20
using
Address
= boost::asio::ip::address;
21
25
inline
std::string
26
to_string
(
Address
const
& addr)
27
{
28
return
addr.to_string();
29
}
30
34
inline
bool
35
isLoopback
(
Address
const
& addr)
36
{
37
return
addr.is_loopback();
38
}
39
43
inline
bool
44
isUnspecified
(
Address
const
& addr)
45
{
46
return
addr.is_unspecified();
47
}
48
52
inline
bool
53
isMulticast
(
Address
const
& addr)
54
{
55
return
addr.is_multicast();
56
}
57
61
inline
bool
62
isPrivate
(
Address
const
& addr)
63
{
64
return
(addr.is_v4()) ?
isPrivate
(addr.to_v4()) :
isPrivate
(addr.to_v6());
65
}
66
70
inline
bool
71
isPublic
(
Address
const
& addr)
72
{
73
return
(addr.is_v4()) ?
isPublic
(addr.to_v4()) :
isPublic
(addr.to_v6());
74
}
75
76
}
// namespace ip
77
78
//------------------------------------------------------------------------------
79
80
template
<
class
Hasher>
81
void
82
hash_append
(Hasher& h,
beast::ip::Address
const
& addr)
noexcept
83
{
84
using
beast::hash_append
;
85
if
(addr.is_v4())
86
{
87
hash_append
(h, addr.to_v4().to_bytes());
88
}
89
else
if
(addr.is_v6())
90
{
91
hash_append
(h, addr.to_v6().to_bytes());
92
}
93
else
94
{
95
// LCOV_EXCL_START
96
UNREACHABLE(
"beast::hash_append : invalid address type"
);
97
// LCOV_EXCL_STOP
98
}
99
}
100
}
// namespace beast
101
102
namespace
boost
{
103
template
<>
104
struct
hash
<::
beast::ip::Address
>
105
{
106
hash
() =
default
;
107
108
std::size_t
109
operator()
(
::beast::ip::Address
const
& addr)
const
110
{
111
return ::beast::Uhash<>{}(addr);
112
}
113
};
114
}
// namespace boost
std::string
cstddef
beast::ip
Definition
IPAddress.h:18
beast::ip::isLoopback
bool isLoopback(Address const &addr)
Returns true if this is a loopback address.
Definition
IPAddress.h:35
beast::ip::Address
boost::asio::ip::address Address
Definition
IPAddress.h:20
beast::ip::isPublic
bool isPublic(Address const &addr)
Returns true if the address is a public routable address.
Definition
IPAddress.h:71
beast::ip::isUnspecified
bool isUnspecified(Address const &addr)
Returns true if the address is unspecified.
Definition
IPAddress.h:44
beast::ip::isPrivate
bool isPrivate(Address const &addr)
Returns true if the address is a private unroutable address.
Definition
IPAddress.h:62
beast::ip::isMulticast
bool isMulticast(Address const &addr)
Returns true if the address is a multicast address.
Definition
IPAddress.h:53
beast::ip::to_string
std::string to_string(Address const &addr)
Returns the address represented as a string.
Definition
IPAddress.h:26
beast
Definition
base_uint.h:697
beast::hash_append
void hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Definition
hash_append.h:206
boost
Definition
IPAddress.h:102
std::size_t
string
boost::hash<::beast::ip::Address >::hash
hash()=default
boost::hash<::beast::ip::Address >::operator()
std::size_t operator()(::beast::ip::Address const &addr) const
Definition
IPAddress.h:109
Generated by
1.17.0