I would like to do a DNS reverse lookup (return hostname for a given IP Address) with asio, but I am not able to figure out which components I need to achieve this. Asio documentiation refers to ip::basic_resolver::resolve
, but an endpoint_type
is needed and I don't know how to use it.
Could someone please post or refer to an example?
EDIT:
With Joachim Pileborg's help I was able to accomplish the task. Needed code (Minumin without error handling):
#include <asio.hpp>
#include <string>
#include <iostream>
int main()
{
asio::ip::address_v4 ipa = asio::ip::address_v4::from_string("8.8.8.8");
asio::ip::tcp::endpoint ep;
ep.address(ipa);
asio::io_service io_service;
asio::ip::tcp::resolver resolver(io_service);
asio::ip::tcp::resolver::iterator destination = resolver.resolve(ep);
std::cout << destination->host_name() << std::endl;
return 0;
}