我正在使用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的地址作为字符串...
ip::address
存储IPv4或IPv6地址。您可以通过is_v6()
或is_v4()
方法检查存储哪种地址。