Skip to content

Commit 4f7b10f

Browse files
committed
nsapi - Moved literal ip parsing out of dns-query
- Not inherently a dns operation - Able to reuse SocketAddress provided to the NetworkInterface
1 parent 2194ca1 commit 4f7b10f

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

features/net/network-socket/NetworkStack.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,25 @@
2424
// Default NetworkStack operations
2525
int NetworkStack::gethostbyname(const char *name, SocketAddress *address)
2626
{
27+
// check for simple ip addresses
28+
if (address->set_ip_address(name)) {
29+
return 0;
30+
}
31+
2732
return nsapi_dns_query(this, name, address);
2833
}
2934

3035
int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
3136
{
37+
// check for simple ip addresses
38+
if (address->set_ip_address(name)) {
39+
if (address->get_ip_version() != version) {
40+
return NSAPI_ERROR_DNS_FAILURE;
41+
}
42+
43+
return 0;
44+
}
45+
3246
return nsapi_dns_query(this, name, address, version);
3347
}
3448

features/net/network-socket/nsapi_dns.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,6 @@ static int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
199199
return NSAPI_ERROR_PARAMETER;
200200
}
201201

202-
// check for simple ip addresses
203-
SocketAddress address;
204-
if (address.set_ip_address(host)) {
205-
if (address.get_ip_version() != version) {
206-
return NSAPI_ERROR_DNS_FAILURE;
207-
}
208-
209-
*addr = address.get_addr();
210-
return 0;
211-
}
212-
213202
// create a udp socket
214203
UDPSocket socket;
215204
int err = socket.open(stack);

0 commit comments

Comments
 (0)