nsapi - Added better heuristic for the default record of DNS queries

Takes advantage of the get_ip_address function to predict the IP
address version wanted by the underlying interface. The should avoid
the need for most IPv6 interfaces to overload gethostbyname.

suggested by @kjbracey-arm
pull/3161/head
Christopher Haster 2016-10-28 11:41:33 -05:00
parent c9f9ffa583
commit d8d2b0a41d
1 changed files with 9 additions and 0 deletions

View File

@ -33,6 +33,15 @@ int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_
return 0;
}
// if the version is unspecified, try to guess the version from the
// ip address of the underlying stack
if (version == NSAPI_UNSPEC) {
SocketAddress testaddress;
if (testaddress.set_ip_address(this->get_ip_address())) {
version = testaddress.get_ip_version();
}
}
return nsapi_dns_query(this, name, address, version);
}