Skip to content

Commit 9ec0ec0

Browse files
authored
Merge pull request #2497 from geky/nsapi_dns
[nsapi] Refactor dns-query
2 parents ea3526d + 4ffeec1 commit 9ec0ec0

File tree

7 files changed

+503
-268
lines changed

7 files changed

+503
-268
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static int lwip_err_remap(err_t err) {
217217

218218

219219
/* LWIP network stack implementation */
220-
static nsapi_addr_t lwip_get_addr(nsapi_stack_t *stack)
220+
static nsapi_addr_t lwip_getaddr(nsapi_stack_t *stack)
221221
{
222222
if (!lwip_get_ip_address()) {
223223
return (nsapi_addr_t){0};
@@ -229,6 +229,17 @@ static nsapi_addr_t lwip_get_addr(nsapi_stack_t *stack)
229229
return addr;
230230
}
231231

232+
static int lwip_gethostbyname(nsapi_stack_t *stack, nsapi_addr_t *addr, const char *host)
233+
{
234+
err_t err = netconn_gethostbyname(host, (ip_addr_t *)addr->bytes);
235+
if (err != ERR_OK) {
236+
return NSAPI_ERROR_DNS_FAILURE;
237+
}
238+
239+
addr->version = NSAPI_IPv4;
240+
return 0;
241+
}
242+
232243
static int lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto)
233244
{
234245
struct lwip_socket *s = lwip_arena_alloc();
@@ -449,7 +460,8 @@ static void lwip_socket_attach(nsapi_stack_t *stack, nsapi_socket_t handle, void
449460

450461
/* LWIP network stack */
451462
const nsapi_stack_api_t lwip_stack_api = {
452-
.get_ip_address = lwip_get_addr,
463+
.get_ip_address = lwip_getaddr,
464+
.gethostbyname = lwip_gethostbyname,
453465
.socket_open = lwip_socket_open,
454466
.socket_close = lwip_socket_close,
455467
.socket_bind = lwip_socket_bind,

features/net/FEATURE_IPV4/lwip-interface/lwipopts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
#define LWIP_DHCP 1
6868
#define LWIP_DNS 1
69+
#define LWIP_SOCKET 0
6970

7071
#define SO_REUSE 1
7172

features/net/network-socket/DnsQuery/DnsQuery.cpp

Lines changed: 0 additions & 216 deletions
This file was deleted.

features/net/network-socket/DnsQuery/DnsQuery.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

features/net/network-socket/NetworkStack.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
#include "NetworkStack.h"
18-
#include "DnsQuery.h"
18+
#include "nsapi_dns.h"
1919
#include "mbed.h"
2020
#include "stddef.h"
2121
#include <new>
@@ -24,14 +24,7 @@
2424
// Default NetworkStack operations
2525
int NetworkStack::gethostbyname(SocketAddress *address, const char *name)
2626
{
27-
char buffer[NSAPI_IP_SIZE];
28-
int err = dnsQuery(this, name, buffer);
29-
if (err) {
30-
return err;
31-
}
32-
33-
address->set_ip_address(buffer);
34-
return 0;
27+
return nsapi_dns_query(this, address, name);
3528
}
3629

3730
int NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)

0 commit comments

Comments
 (0)