Skip to content

Commit d8d2b0a

Browse files
committed
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
1 parent c9f9ffa commit d8d2b0a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

features/netsocket/NetworkStack.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_
3333
return 0;
3434
}
3535

36+
// if the version is unspecified, try to guess the version from the
37+
// ip address of the underlying stack
38+
if (version == NSAPI_UNSPEC) {
39+
SocketAddress testaddress;
40+
if (testaddress.set_ip_address(this->get_ip_address())) {
41+
version = testaddress.get_ip_version();
42+
}
43+
}
44+
3645
return nsapi_dns_query(this, name, address, version);
3746
}
3847

0 commit comments

Comments
 (0)