From 83286c3e784df2639b5e388b0d4d2b993742c29c Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 18 Aug 2016 18:26:37 -0500 Subject: [PATCH] Adopted netconn_gethostbyname in the lwip interface Provides proper integration with DHCP through lwip --- .../net/FEATURE_IPV4/lwip-interface/lwip_stack.c | 16 ++++++++++++++-- .../net/FEATURE_IPV4/lwip-interface/lwipopts.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c b/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c index 6aaee583da..cb67d70096 100644 --- a/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c +++ b/features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c @@ -217,7 +217,7 @@ static int lwip_err_remap(err_t err) { /* LWIP network stack implementation */ -static nsapi_addr_t lwip_get_addr(nsapi_stack_t *stack) +static nsapi_addr_t lwip_getaddr(nsapi_stack_t *stack) { if (!lwip_get_ip_address()) { return (nsapi_addr_t){0}; @@ -229,6 +229,17 @@ static nsapi_addr_t lwip_get_addr(nsapi_stack_t *stack) return addr; } +static int lwip_gethostbyname(nsapi_stack_t *stack, nsapi_addr_t *addr, const char *host) +{ + err_t err = netconn_gethostbyname(host, (ip_addr_t *)addr->bytes); + if (err != ERR_OK) { + return NSAPI_ERROR_DNS_FAILURE; + } + + addr->version = NSAPI_IPv4; + return 0; +} + static int lwip_socket_open(nsapi_stack_t *stack, nsapi_socket_t *handle, nsapi_protocol_t proto) { 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 /* LWIP network stack */ const nsapi_stack_api_t lwip_stack_api = { - .get_ip_address = lwip_get_addr, + .get_ip_address = lwip_getaddr, + .gethostbyname = lwip_gethostbyname, .socket_open = lwip_socket_open, .socket_close = lwip_socket_close, .socket_bind = lwip_socket_bind, diff --git a/features/net/FEATURE_IPV4/lwip-interface/lwipopts.h b/features/net/FEATURE_IPV4/lwip-interface/lwipopts.h index 5e16535ba2..f557e353cb 100644 --- a/features/net/FEATURE_IPV4/lwip-interface/lwipopts.h +++ b/features/net/FEATURE_IPV4/lwip-interface/lwipopts.h @@ -66,6 +66,7 @@ #define LWIP_DHCP 1 #define LWIP_DNS 1 +#define LWIP_SOCKET 0 #define SO_REUSE 1