The following code:
using boost::asio::ip::tcp;
std::string ipAddress;
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(boost::asio::ip::host_name(), "");
tcp::resolver::iterator iter = resolver.resolve(query);
results in the following error when run on OS X High Sierra using Xcode 9.1:
std::runtime_error: resolve: Host not found (authoritative)
The value of resolver
is:
(boost::asio::ip::tcp::resolver) resolver = {
boost::asio::basic_io_object<boost::asio::ip::resolver_service<boost::asio::ip::tcp>, false> = {
service = 0x00000001023159a0
implementation = nullptr {
__ptr_ = 0x0000000000000000
__cntrl_ = 0x00000001023156c0
}
}
}
and the value of query
is:
(boost::asio::ip::basic_resolver<boost::asio::ip::tcp, boost::asio::ip::resolver_service<boost::asio::ip::tcp> >::query) query = {
hints_ = {
ai_flags = 1024
ai_family = 0
ai_socktype = 1
ai_protocol = 6
ai_addrlen = 0
ai_canonname = 0x0000000000000000
ai_addr = 0x0000000000000000
ai_next = 0x0000000000000000
}
host_name_ = "iMac.local"
service_name_ = ""
}
The resolve
function looks like this:
iterator resolve(const query& q)
{
boost::system::error_code ec;
iterator i = this->service.resolve(this->implementation, q, ec);
boost::asio::detail::throw_error(ec, "resolve");
return i;
}
so I can see that calling resolve
with resolver.implementation
being a nullptr
is what's causing the problem. However, I don't know why it's a nullptr
.
This is not a problem on different machines running OS X Yosemite or El Capitan.
boost::asio::ip::host_name()
return? Is it a valid hostname or IP-address? And if you want to connect to the local host why not simply use"127.0.0.1"
?iMac.local
ping
the host returned byhost_name
? Perhaps it's simply not correctly set up?