aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/net
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include/net')
-rw-r--r--contrib/epee/include/net/local_ip.h7
-rw-r--r--contrib/epee/include/net/net_utils_base.h16
2 files changed, 22 insertions, 1 deletions
diff --git a/contrib/epee/include/net/local_ip.h b/contrib/epee/include/net/local_ip.h
index ce74e1cd3..246cf6ad8 100644
--- a/contrib/epee/include/net/local_ip.h
+++ b/contrib/epee/include/net/local_ip.h
@@ -30,6 +30,11 @@
#include <string>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/ip/address_v6.hpp>
+#include "int-util.h"
+
+// IP addresses are kept in network byte order
+// Masks below are little endian
+// -> convert from network byte order to host byte order before comparing
namespace epee
{
@@ -62,6 +67,7 @@ namespace epee
inline
bool is_ip_local(uint32_t ip)
{
+ ip = SWAP32LE(ip);
/*
local ip area
10.0.0.0 — 10.255.255.255
@@ -85,6 +91,7 @@ namespace epee
inline
bool is_ip_loopback(uint32_t ip)
{
+ ip = SWAP32LE(ip);
if( (ip | 0xffffff00) == 0xffffff7f)
return true;
//MAKE_IP
diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h
index dd80fae8b..028e605d7 100644
--- a/contrib/epee/include/net/net_utils_base.h
+++ b/contrib/epee/include/net/net_utils_base.h
@@ -38,6 +38,7 @@
#include "enums.h"
#include "misc_log_ex.h"
#include "serialization/keyvalue_serialization.h"
+#include "int-util.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net"
@@ -91,7 +92,20 @@ namespace net_utils
static constexpr bool is_blockable() noexcept { return true; }
BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(m_ip)
+ if (is_store)
+ {
+ KV_SERIALIZE_VAL_POD_AS_BLOB_N(m_ip, "ip")
+ uint32_t ip = SWAP32LE(this_ref.m_ip);
+ epee::serialization::selector<is_store>::serialize(ip, stg, hparent_section, "m_ip");
+ }
+ else
+ {
+ if (!epee::serialization::selector<is_store>::serialize_t_val_as_blob(this_ref.m_ip, stg, hparent_section, "ip"))
+ {
+ KV_SERIALIZE(m_ip)
+ const_cast<ipv4_network_address&>(this_ref).m_ip = SWAP32LE(this_ref.m_ip);
+ }
+ }
KV_SERIALIZE(m_port)
END_KV_SERIALIZE_MAP()
};