[asio] How to get the name of the endpoint from the ip address of the endpoint.
If I have an endpoint as an ip address (IP V4 or IPv6), how can I do a DNS lookup to get the name of the endpoint? In the example below, I understand that the host_name is coming from the query. But how do I do a lookup to get the host name from the IP? This may help. If I do something like this: ip::tcp::resolver_iterator res = ip::tcp::resolver(ios).resolve(ip::tcp::resolver_query("google.com", "80")); for(;res != ip::tcp::resolver_iterator(); ++res) { std::cout << res->host_name() << ":" << res->service_name() << " "; std::cout << res->endpoint().address().to_string() << std::endl; } The the output is: google.com:80 209.85.171.100 google.com:80 74.125.67.100 google.com:80 74.125.45.100 However if I do: ip::tcp::resolver_iterator res = ip::tcp::resolver(ios).resolve(ip::tcp::resolver_query("209.85.171.100", "80")); I get: 209.85.171.100:80 209.85.171.100 so th ehosr name comes from the query. I really want: google.com:80 209.85.171.100 Thanks in advance for any help. Andrew -- ___________________________________________ Andrew J. P. Maclean Centre for Autonomous Systems The Rose Street Building J04 The University of Sydney 2006 NSW AUSTRALIA Ph: +61 2 9351 3283 Fax: +61 2 9351 7474 URL: http://www.acfr.usyd.edu.au/ ___________________________________________
In the example below, I understand that the host_name is coming from the query. But how do I do a lookup to get the host name from the IP?
Use resolver::resolve overload that takes endpoint as a parameter.
participants (2)
-
Andrew Maclean
-
Igor R