aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src/net_utils_base.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-29 10:47:53 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-07-16 11:35:53 +0000
commit65c40049633f0c5db3c24af8716bb683520f368c (patch)
tree9531d5d4c2cfa4e5a5b1ac35cea13af1b173ccbe /contrib/epee/src/net_utils_base.cpp
parentp2p: store network address directly in blocked host list (diff)
downloadmonero-65c40049633f0c5db3c24af8716bb683520f368c.tar.xz
allow blocking whole subnets
Diffstat (limited to '')
-rw-r--r--contrib/epee/src/net_utils_base.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/contrib/epee/src/net_utils_base.cpp b/contrib/epee/src/net_utils_base.cpp
index 9b781027e..b7f07a23b 100644
--- a/contrib/epee/src/net_utils_base.cpp
+++ b/contrib/epee/src/net_utils_base.cpp
@@ -22,6 +22,24 @@ namespace epee { namespace net_utils
bool ipv4_network_address::is_local() const { return net_utils::is_ip_local(ip()); }
+ bool ipv4_network_subnet::equal(const ipv4_network_subnet& other) const noexcept
+ { return is_same_host(other) && m_mask == other.m_mask; }
+
+ bool ipv4_network_subnet::less(const ipv4_network_subnet& other) const noexcept
+ { return subnet() < other.subnet() ? true : (other.subnet() < subnet() ? false : (m_mask < other.m_mask)); }
+
+ std::string ipv4_network_subnet::str() const
+ { return string_tools::get_ip_string_from_int32(subnet()) + "/" + std::to_string(m_mask); }
+
+ std::string ipv4_network_subnet::host_str() const { return string_tools::get_ip_string_from_int32(subnet()) + "/" + std::to_string(m_mask); }
+ bool ipv4_network_subnet::is_loopback() const { return net_utils::is_ip_loopback(subnet()); }
+ bool ipv4_network_subnet::is_local() const { return net_utils::is_ip_local(subnet()); }
+ bool ipv4_network_subnet::matches(const ipv4_network_address &address) const
+ {
+ return (address.ip() & ~(0xffffffffull << m_mask)) == subnet();
+ }
+
+
bool network_address::equal(const network_address& other) const
{
// clang typeid workaround