net: Add IPv4ToString (we already have IPv6ToString)

pull/826/head
practicalswift 4 years ago
parent 2b2ab9ab78
commit 5858057384

@ -551,6 +551,11 @@ enum Network CNetAddr::GetNetwork() const
return m_net;
}
static std::string IPv4ToString(Span<const uint8_t> a)
{
return strprintf("%u.%u.%u.%u", a[0], a[1], a[2], a[3]);
}
static std::string IPv6ToString(Span<const uint8_t> a)
{
assert(a.size() == ADDR_IPV6_SIZE);
@ -582,7 +587,7 @@ std::string CNetAddr::ToStringIP() const
return std::string(name);
}
if (m_net == NET_IPV4) {
return strprintf("%u.%u.%u.%u", m_addr[0], m_addr[1], m_addr[2], m_addr[3]);
return IPv4ToString(m_addr);
}
return IPv6ToString(m_addr);
}

Loading…
Cancel
Save