My previous code to take the hostname of a server and resolve it to and IP
looked like this:
tcp::resolver resolver(m_io);
tcp::endpoint endpoint;
typedef tcp::resolver::query Lookup;
Lookup query(
endpoint.protocol(), host, lexical_cast<string>(port),
Lookup::all_matching | Lookup::numeric_service);
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;
error_code error = host_not_found;
while (error && endpoint_iterator != end)
{
m_socket.close();
m_socket.connect(*endpoint_iterator++, error);
}
if (error)
BOOST_THROW_EXCEPTION(system_error(error));
I originally though that all_matching would mean this code would resolve an
IPv6 address if necessary but it doesn't. So I made the following changes:
tcp::resolver resolver(m_io);
typedef tcp::resolver::query Lookup;
Lookup query(
tcp::v6(), host_name, lexical_cast<string>(port),
Lookup::all_matching | Lookup::v4_mapped |
Lookup::numeric_service);
This works on my test IPv6 setup but is it good enough? There are all
sorts of things I don't understand like mapping and tunnelling so I'm
looking for a best practice for IP-agnostic name resolution.
Many thanks.
Alex Lamaison
--
SFTP for Windows Explorer (http://www.swish-sftp.org)
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
> I'm trying to add IPv6 support to my program without breaking IPv4. What
> is the canonical way, if any, to do this win ASIO on Windows.
...
> I originally though that all_matching would mean this code would resolve an
> IPv6 address if necessary but it doesn't. So I made the following changes:
>
> tcp::resolver resolver(m_io);
> typedef tcp::resolver::query Lookup;
> Lookup query(
> tcp::v6(), host_name, lexical_cast<string>(port),
> Lookup::all_matching | Lookup::v4_mapped |
> Lookup::numeric_service);
>
> This works on my test IPv6 setup but is it good enough? There are all
> sorts of things I don't understand like mapping and tunnelling so I'm
> looking for a best practice for IP-agnostic name resolution.
Turns out, this does indeed break IPv4 when run from an OS such as Windows
2000 that doesn't have IPv6. How can I resolve a hostname in both
situations?