From 592649d3f201a8af957b3d8abb360e29df99c8ca Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Sep 2023 21:59:24 +0200 Subject: [PATCH] net/ToString: check family==AF_INET6 instead of looking for colons --- src/net/ToString.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net/ToString.cxx b/src/net/ToString.cxx index 7907b158b..41421d8e5 100644 --- a/src/net/ToString.cxx +++ b/src/net/ToString.cxx @@ -70,13 +70,13 @@ ToString(SocketAddress address) noexcept char host[NI_MAXHOST], serv[NI_MAXSERV]; int ret = getnameinfo(address.GetAddress(), address.GetSize(), host, sizeof(host), serv, sizeof(serv), - NI_NUMERICHOST|NI_NUMERICSERV); + NI_NUMERICHOST | NI_NUMERICSERV); if (ret != 0) return "unknown"; if (serv[0] != 0 && (serv[0] != '0' || serv[1] != 0)) { #ifdef HAVE_IPV6 - if (std::strchr(host, ':') != nullptr) { + if (address.GetFamily() == AF_INET6) { return fmt::format("[{}]:{}", host, serv); } #endif