[EOSIO/eos] keosd failed to configure http to listen on (resolve: Host not found (authoritative)) (#5422)

I was setting up an Ubuntu 18.04 offline machine with cleos for cold storage purposes. After a successful installation I tried to run a «cleos sign …» command and got the following output:
«/usr/local/eosio/bin/keosd» launched
Unable to connect to keosd, if keosd is running please kill the process and try again.

The next step for debugging was to try to launch keosd manually. This error was listed in the output:
2018-08-25T11:45:49.611 thread-0 http_plugin.cpp:347 plugin_initialize ] failed to configure http to listen on (resolve: Host not found (authoritative))
After some debugging I noticed that if I turn network connection on then the command works. Right when I go offline it stops working again. This is weird as it’s only supposed to connect through localhost.

I ended up having a look at the code around the line 347 (from the error message) in the file plugins/http_plugin/http_plugin.cpp:
string lipstr = options.at( «http-server-address» ).as();
string host = lipstr.substr( 0, lipstr.find( ‘:’ ));
string port = lipstr.substr( host.size() + 1, lipstr.size());
tcp::resolver::query query( tcp::v4(), host.c_str(), port.c_str());
try {
my->listen_endpoint = *resolver.resolve( query );
ilog( «configured http to listen on ${h}:${p}», («h», host)( «p», port ));
} catch ( const boost::system::system_error& ec ) {
elog( «failed to configure http to listen on ${h}:${p} (${m})»,
(«h», host)( «p», port )( «m», ec.what()));

It seems `*resolver.resolve( query )` fails so I had a look at the [documentation](https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/reference/ip__basic_resolver_query/basic_resolver_query.html) where the query constructor is defined like this:
const protocol_type & protocol,
const std::string & host,
const std::string & service,
resolver_query_base::flags resolve_flags = address_configured);
The important part here is that flags default to «address_configured». Again, based on the [documentation](https://www.boost.org/doc/libs/1_68_0/doc/html/boost_asio/reference/ip__basic_resolver_query/address_configured.html) it is defined as: «Only return IPv4 addresses if a non-loopback IPv4 address is configured for the system. Only return IPv6 addresses if a non-loopback IPv6 address is configured for the system.»

This seems to explain that my problem occurs only when I turn off networking. I suspect also others than me would like to use cleos on an offline machine so this might be worthwhile to fix.

I got it working on my local machine by changing the row 341 in plugins/http_plugin/http_plugin.cpp to the following and then rebuilding and installing.
tcp::resolver::query query( tcp::v4(), host.c_str(), port.c_str(), boost::asio::ip::resolver_query_base::numeric_service);