net/ToString: append port only if it is non-zero

This commit is contained in:
Max Kellermann 2023-09-18 11:10:20 +02:00
parent 5fd2fc77f3
commit 61c29473d3

View File

@ -72,6 +72,7 @@ ToString(SocketAddress address) noexcept
if (ret != 0) if (ret != 0)
return "unknown"; return "unknown";
if (serv[0] != 0 && (serv[0] != '0' || serv[1] != 0)) {
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
if (std::strchr(host, ':') != nullptr) { if (std::strchr(host, ':') != nullptr) {
std::string result("["); std::string result("[");
@ -88,6 +89,9 @@ ToString(SocketAddress address) noexcept
return result; return result;
} }
return host;
}
std::string std::string
HostToString(SocketAddress address) noexcept HostToString(SocketAddress address) noexcept
{ {