tags:

views:

543

answers:

1

According to the documentation of boost::asio::ip::tcp::resolver::query in order to resolve host it should receive service as well.

What if I want to resolve host without relation to port? How should I do it at all? Should I specify dummy port?

+1  A: 

In one post in the boost mailing list somebody else seemed to do it like this (copied, reformatted, service-number changed, nothing else):

namespace bai = boost::asio::ip;
bai::tcp::endpoint ep(bai::address_v4(0xD155AB64), 0); // 209.85.171.100:0
boost::asio::io_service ios;
bai::tcp::resolver resolver(ios);
bai::tcp::resolver::iterator iter = resolver.resolve(ep);
bai::tcp::resolver::iterator end;
while (iter != end)
{
  std::cerr << (*iter).host_name() << std::endl; // cg-in-f100.google.com
  ++iter;
}

As you correctly said, here a service is still passed in, but a step through the Boost.Asio code revealed this (in resolver_service.hpp, I'm using the rather old 1.36 release):

// First try resolving with the service name. If that fails try resolving
// but allow the service to be returned as a number.

So, just go with 0, and it should do what you want.

gimpf
Take a not that you do use port number "ep(bai::address_v4(0xD155AB64), 80); // 209.85.171.100:80"
Artyom
I slightly revised the example, hope it helps.
gimpf