如何从boost :: asio :: ip :: tcp :: socket :: local_endpoint()。address()]中提取地址字符串>

问题描述 投票:0回答:1

我正在使用boost::asio::ip::tcp。在我的TCP客户端和TCP服务器之间建立连接后,我想在两边都将local_endpoint的地址作为字符串,并将remote_endpoint的地址作为字符串。

auto localAddress = tcpSocket.local_endpoint().address().to_string();
auto remoteAddress = tcpSocket-remote_endpoint().address().to_string();

但是我很困惑。在某些情况下,我得到127.0.0.1,在某些情况下,我得到::ffff:127.0.0.1::ffff:127.0.0.1是V6,127.0.0.1是V4吗?我只需要IP地址为127.0.0.1

我也可以提取子串来获得127.0.0.1件。但是我想知道是否存在boost::asio标准技术来将::ffff:127.0.0.1提取/转换为127.0.0.1

我正在使用boost :: asio :: ip :: tcp。在我的TCP客户端和TCP服务器之间建立连接后,我想将local_endpoint的地址作为字符串,并将remote_endpoint的地址作为字符串...

tcp boost-asio endpoint
1个回答
0
投票

ip::address存储IPv4或IPv6地址。您可以通过is_v6()is_v4()方法检查存储哪种地址。

© www.soinside.com 2019 - 2024. All rights reserved.