Hi Robin,
The reason this is typically done is that because the entire IPv4 space fits in the IPv6 space, this format can be uniform, allowing connections from both address families to be handled using the same logic.
If you explicitly want an IPv4 string there are a few options:
You can use socket_con_type::get_socket() to return the underlying asio::ip::tcp::socket and then use the standard Asio functions to inspect the address of the remote endpoint. Something like..
// lowest layer ensures that you strip out any intermediate socket layers, such as an SSL/TLS wrapper
auto addr = con.get_socket().lowest_layer().remote_endpoint().address();
// check if this is a v4 address
if (addr.is_v4()) {
// cast to a v4 specific address before converting to string
std::string str = addr.to_v4().to_string();
} else {
// v6 address can't be represented as a v4
}
I haven't tested it, but its possible that if you ask the endpoint to listen exclusively on the IPv4 address family that it would print IPv4 address strings by default. Doing this will obviously prevent your application from working on IPv6 networks.
You can ask your endpoint to listen on a specific address family via something like..
endpoint.listen(websocketpp::lib::asio::ip::tcp::v4(), 3000);