Skip to content

Commit

Permalink
net: Add IPv4ToString (we already have IPv6ToString)
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift committed Apr 1, 2021
1 parent 2b2ab9a commit 5858057
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5858057

Please sign in to comment.