From 7657db4be9d0af9d6d9a2169bfbec387c3e7ce63 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 28 Oct 2016 11:41:33 -0500 Subject: [PATCH] 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 --- features/netsocket/NetworkStack.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/features/netsocket/NetworkStack.cpp b/features/netsocket/NetworkStack.cpp index 44419905f4..d59f4a9aa7 100644 --- a/features/netsocket/NetworkStack.cpp +++ b/features/netsocket/NetworkStack.cpp @@ -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); }