Skip to content

[nsapi] Refactor dns-query #2497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand Down Expand Up @@ -449,7 +460,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,
Expand Down
1 change: 1 addition & 0 deletions features/net/FEATURE_IPV4/lwip-interface/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

#define LWIP_DHCP 1
#define LWIP_DNS 1
#define LWIP_SOCKET 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this modify? Seems unrelated to this patch or at least modifies behavior which I cannot tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It disables the BSD-compatible socket API that lwip provides, which is unused in the network-socket API. The only change would be a small decrease in code size.


#define SO_REUSE 1

Expand Down
216 changes: 0 additions & 216 deletions features/net/network-socket/DnsQuery/DnsQuery.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions features/net/network-socket/DnsQuery/DnsQuery.h

This file was deleted.

11 changes: 2 additions & 9 deletions features/net/network-socket/NetworkStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include "NetworkStack.h"
#include "DnsQuery.h"
#include "nsapi_dns.h"
#include "mbed.h"
#include "stddef.h"
#include <new>
Expand All @@ -24,14 +24,7 @@
// Default NetworkStack operations
int NetworkStack::gethostbyname(SocketAddress *address, const char *name)
{
char buffer[NSAPI_IP_SIZE];
int err = dnsQuery(this, name, buffer);
if (err) {
return err;
}

address->set_ip_address(buffer);
return 0;
return nsapi_dns_query(this, address, name);
}

int NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
Expand Down
Loading