Skip to content

Commit 83286c3

Browse files
geky0xc0170
authored andcommitted
Adopted netconn_gethostbyname in the lwip interface
Provides proper integration with DHCP through lwip
1 parent 6c2a82b commit 83286c3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
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();
@@ -445,7 +456,8 @@ static void lwip_socket_attach(nsapi_stack_t *stack, nsapi_socket_t handle, void
445456

446457
/* LWIP network stack */
447458
const nsapi_stack_api_t lwip_stack_api = {
448-
.get_ip_address = lwip_get_addr,
459+
.get_ip_address = lwip_getaddr,
460+
.gethostbyname = lwip_gethostbyname,
449461
.socket_open = lwip_socket_open,
450462
.socket_close = lwip_socket_close,
451463
.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

0 commit comments

Comments
 (0)