rippled
Loading...
Searching...
No Matches
IPAddress.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef BEAST_NET_IPADDRESS_H_INCLUDED
21#define BEAST_NET_IPADDRESS_H_INCLUDED
22
23#include <xrpl/beast/hash/hash_append.h>
24#include <xrpl/beast/hash/uhash.h>
25#include <xrpl/beast/net/IPAddressV4.h>
26#include <xrpl/beast/net/IPAddressV6.h>
27#include <xrpl/beast/utility/instrumentation.h>
28
29#include <boost/asio/ip/address.hpp>
30#include <boost/functional/hash.hpp>
31
32#include <string>
33
34//------------------------------------------------------------------------------
35
36namespace beast {
37namespace IP {
38
39using Address = boost::asio::ip::address;
40
42inline std::string
43to_string(Address const& addr)
44{
45 return addr.to_string();
46}
47
49inline bool
50is_loopback(Address const& addr)
51{
52 return addr.is_loopback();
53}
54
56inline bool
58{
59 return addr.is_unspecified();
60}
61
63inline bool
65{
66 return addr.is_multicast();
67}
68
70inline bool
71is_private(Address const& addr)
72{
73 return (addr.is_v4()) ? is_private(addr.to_v4()) : is_private(addr.to_v6());
74}
75
77inline bool
78is_public(Address const& addr)
79{
80 return (addr.is_v4()) ? is_public(addr.to_v4()) : is_public(addr.to_v6());
81}
82
83} // namespace IP
84
85//------------------------------------------------------------------------------
86
87template <class Hasher>
88void
89hash_append(Hasher& h, beast::IP::Address const& addr) noexcept
90{
92 if (addr.is_v4())
93 hash_append(h, addr.to_v4().to_bytes());
94 else if (addr.is_v6())
95 hash_append(h, addr.to_v6().to_bytes());
96 else
97 UNREACHABLE("beast::hash_append : invalid address type");
98}
99} // namespace beast
100
101namespace boost {
102template <>
103struct hash<::beast::IP::Address>
104{
105 explicit hash() = default;
106
109 {
110 return ::beast::uhash<>{}(addr);
111 }
112};
113} // namespace boost
114
115#endif
bool is_multicast(Address const &addr)
Returns true if the address is a multicast address.
Definition IPAddress.h:64
bool is_loopback(Address const &addr)
Returns true if this is a loopback address.
Definition IPAddress.h:50
bool is_public(Address const &addr)
Returns true if the address is a public routable address.
Definition IPAddress.h:78
bool is_unspecified(Address const &addr)
Returns true if the address is unspecified.
Definition IPAddress.h:57
boost::asio::ip::address Address
Definition IPAddress.h:39
bool is_private(Address const &addr)
Returns true if the address is a private unroutable address.
Definition IPAddress.h:71
std::string to_string(Address const &addr)
Returns the address represented as a string.
Definition IPAddress.h:43
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:108