Boost logo

Boost :

Subject: Re: [boost] Unexpected behavior in reverse lookup (asio resolver)
From: Gavin Lambert (boost_at_[hidden])
Date: 2018-09-19 03:55:10

On 19/09/2018 01:36, LC via Boost wrote:
> When performing a reverse lookup of an address:
> *r->async_resolve( boost::asio::ip::tcp::resolver::endpoint_type( adr, 80 )
> ...*
> the address itself is returned (as string), when the name of the host cannot
> be found. I would expect an error/exception, telling me this instead.
> *Nr. 6, however, is a non-existent ip-address. As you can see, instead of an
> error, the address itself is returned when calling
> "endpoint_iterator->host_name();".*
> This is unexpected and (I think) undocumented. It can be easily detected by
> testing if host_name returns an address, but this would require another
> (test) conversion; as a result you'd end up with forth&back conversions.

I don't know if this is the reason, but most code will prefer displaying
and using the hostname (when available), but when no hostname is
available then the address works just as well.

Similarly when async_resolve is asked to find the address for a
hostname, you can supply a "hostname" which is actually an address, and
this simply returns the same address without error, which is what most
people want.

This allows code to just use a resolve -> connect chain in all cases
regardless of whether the input hostname is actually an address or not.

Or to put it another way, an address is also a valid hostname.

Boost list run by bdawes at, gregod at, cpdaniel at, john at