From 6d39a0a9b2d1df792f7ff18be134fc0668992b86 Mon Sep 17 00:00:00 2001 From: Dmitry Chapyshev Date: Sat, 11 Nov 2023 19:47:09 +0500 Subject: [PATCH] Added check for v4 address. --- source/base/net/tcp_channel.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/base/net/tcp_channel.cc b/source/base/net/tcp_channel.cc index 0774b07ec7..f850e633f6 100644 --- a/source/base/net/tcp_channel.cc +++ b/source/base/net/tcp_channel.cc @@ -119,7 +119,17 @@ std::u16string TcpChannel::peerAddress() const if (!socket_.is_open()) return std::u16string(); - return utf16FromLocal8Bit(socket_.remote_endpoint().address().to_string()); + asio::ip::address address = socket_.remote_endpoint().address(); + if (address.is_v4()) + { + asio::ip::address ipv4_address = address.to_v4(); + return utf16FromLocal8Bit(ipv4_address.to_string()); + } + else + { + asio::ip::address ipv6_address = address.to_v6(); + return utf16FromLocal8Bit(ipv6_address.to_string()); + } } //--------------------------------------------------------------------------------------------------