0

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.

9
  • What does 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"? Commented Nov 16, 2017 at 9:32
  • It returns iMac.local
    – ksl
    Commented Nov 16, 2017 at 9:34
  • What if I just want to find out what the IP address is of the machine?
    – ksl
    Commented Nov 16, 2017 at 9:39
  • Your local address is always 127.0.0.1. It's the standard address of the local loopback interface. Commented Nov 16, 2017 at 9:44
  • 1
    Have you tried to ping the host returned by host_name? Perhaps it's simply not correctly set up? Commented Nov 16, 2017 at 10:08

1 Answer 1

2

Posting an answer in case others have the same problem and end up here.

Finally figured it out, thanks in part to Some programmer dude asking about pinging the host and then searching based on the fact that ping failed.

This post https://discussions.apple.com/thread/7707202?start=0&tstart=0 states that for some reason .local hostname is kept turned off unless any of the sharing services is active.

Turning them on fixed the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.