nsapi - Moved literal ip parsing out of dns-query

- Not inherently a dns operation
- Able to reuse SocketAddress provided to the NetworkInterface
pull/2652/head
Christopher Haster 2016-09-23 04:33:37 -05:00
parent 2194ca1c1e
commit 4f7b10f433
2 changed files with 14 additions and 11 deletions

View File

@ -24,11 +24,25 @@
// Default NetworkStack operations
int NetworkStack::gethostbyname(const char *name, SocketAddress *address)
{
// check for simple ip addresses
if (address->set_ip_address(name)) {
return 0;
}
return nsapi_dns_query(this, name, address);
}
int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
// check for simple ip addresses
if (address->set_ip_address(name)) {
if (address->get_ip_version() != version) {
return NSAPI_ERROR_DNS_FAILURE;
}
return 0;
}
return nsapi_dns_query(this, name, address, version);
}

View File

@ -199,17 +199,6 @@ static int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
return NSAPI_ERROR_PARAMETER;
}
// check for simple ip addresses
SocketAddress address;
if (address.set_ip_address(host)) {
if (address.get_ip_version() != version) {
return NSAPI_ERROR_DNS_FAILURE;
}
*addr = address.get_addr();
return 0;
}
// create a udp socket
UDPSocket socket;
int err = socket.open(stack);