Fix IP address serialization on big endian

IP addresses are stored in network byte order even on little
endian hosts
This commit is contained in:
moneromooo-monero 2019-05-17 18:03:04 +00:00
parent c1fa4a7f8c
commit bc1144e98e
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
2 changed files with 17 additions and 1 deletions

View File

@ -38,6 +38,7 @@
#include "enums.h" #include "enums.h"
#include "misc_log_ex.h" #include "misc_log_ex.h"
#include "serialization/keyvalue_serialization.h" #include "serialization/keyvalue_serialization.h"
#include "int-util.h"
#undef MONERO_DEFAULT_LOG_CATEGORY #undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net" #define MONERO_DEFAULT_LOG_CATEGORY "net"
@ -91,7 +92,20 @@ namespace net_utils
static constexpr bool is_blockable() noexcept { return true; } static constexpr bool is_blockable() noexcept { return true; }
BEGIN_KV_SERIALIZE_MAP() 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) KV_SERIALIZE(m_port)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View File

@ -95,7 +95,9 @@ namespace boost
{ {
uint32_t ip{na.ip()}; uint32_t ip{na.ip()};
uint16_t port{na.port()}; uint16_t port{na.port()};
ip = SWAP32LE(ip);
a & ip; a & ip;
ip = SWAP32LE(ip);
a & port; a & port;
if (!typename Archive::is_saving()) if (!typename Archive::is_saving())
na = epee::net_utils::ipv4_network_address{ip, port}; na = epee::net_utils::ipv4_network_address{ip, port};