From 61c29473d3b4554c4fd67b3a3e4f54ec6a543f3b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Sep 2023 11:10:20 +0200 Subject: [PATCH] net/ToString: append port only if it is non-zero --- src/net/ToString.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/net/ToString.cxx b/src/net/ToString.cxx index db7d47daa..f8a015fc3 100644 --- a/src/net/ToString.cxx +++ b/src/net/ToString.cxx @@ -72,20 +72,24 @@ ToString(SocketAddress address) noexcept if (ret != 0) return "unknown"; + if (serv[0] != 0 && (serv[0] != '0' || serv[1] != 0)) { #ifdef HAVE_IPV6 - if (std::strchr(host, ':') != nullptr) { - std::string result("["); - result.append(host); - result.append("]:"); + if (std::strchr(host, ':') != nullptr) { + std::string result("["); + result.append(host); + result.append("]:"); + result.append(serv); + return result; + } +#endif + + std::string result(host); + result.push_back(':'); result.append(serv); return result; } -#endif - std::string result(host); - result.push_back(':'); - result.append(serv); - return result; + return host; } std::string