
3 changed files with 125 additions and 0 deletions
@ -0,0 +1,26 @@
|
||||
APPLICATION = gnrc_sock_dns
|
||||
include ../Makefile.tests_common |
||||
|
||||
RIOTBASE ?= $(CURDIR)/../..
|
||||
|
||||
BOARD_INSUFFICIENT_MEMORY := chronos telosb nucleo32-f042 nucleo32-f031 nucleo-f030 nucleo-l053 nucleo32-l031 stm32f0discovery
|
||||
|
||||
USEMODULE += sock_dns
|
||||
USEMODULE += gnrc_sock_udp
|
||||
USEMODULE += gnrc_ipv6_default
|
||||
USEMODULE += gnrc_netdev_default
|
||||
USEMODULE += auto_init_gnrc_netif
|
||||
|
||||
USEMODULE += shell_commands
|
||||
|
||||
USEMODULE += posix
|
||||
|
||||
CFLAGS += -DDEVELHELP
|
||||
|
||||
LOW_MEMORY_BOARDS := nucleo-f334 msb-430 msb-430h weio
|
||||
|
||||
ifeq ($(BOARD),$(filter $(BOARD),$(LOW_MEMORY_BOARDS))) |
||||
CFLAGS += -DGNRC_PKTBUF_SIZE=512 -DGNRC_IPV6_NETIF_ADDR_NUMOF=4 -DGNRC_IPV6_NC_SIZE=1
|
||||
endif |
||||
|
||||
include $(RIOTBASE)/Makefile.include |
@ -0,0 +1,30 @@
|
||||
# Overview |
||||
|
||||
This folder contains a test application for RIOT's sock-based DNS client. |
||||
|
||||
# How to test with native |
||||
|
||||
Setup up a tap interface: |
||||
|
||||
$ sudo ip tuntap add dev tap0 mode tap user $(id -u -n) |
||||
$ sudo ip a a 2001:db8::1/64 dev tap0 |
||||
$ sudo ip link set up dev tap0 |
||||
|
||||
Start dnsmasq (in another console): |
||||
|
||||
$ sudo dnsmasq -d -2 -z -i tap0 -q --no-resolv \ |
||||
--dhcp-range=::1,constructor:tap0,ra-only \ |
||||
--listen-address 2001:db8::1 \ |
||||
--host-record=example.org,10.0.0.1,2001:db8::1 |
||||
|
||||
(NetworkManager is known to start an interfering dnsmasq instance. It needs to |
||||
be stopped before this test.) |
||||
|
||||
Then run the test application |
||||
|
||||
$ make term |
||||
|
||||
The application will take a little while to auto-configure it's IP address. |
||||
Then you should see something like |
||||
|
||||
example.org resolves to 2001:db8::1 |
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de> |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @ingroup tests |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief sock DNS client test application |
||||
* |
||||
* @author Kaspar Schleiser <kaspar@schleiser.de> |
||||
* |
||||
* @} |
||||
*/ |
||||
|
||||
#include <stddef.h> |
||||
#include <stdio.h> |
||||
|
||||
#include <arpa/inet.h> |
||||
|
||||
#include "net/sock/dns.h" |
||||
#include "net/sock/util.h" |
||||
#include "xtimer.h" |
||||
|
||||
#ifndef TEST_NAME |
||||
#define TEST_NAME "example.org" |
||||
#endif |
||||
|
||||
#ifndef DNS_SERVER |
||||
#define DNS_SERVER "[2001:db8::1]:53" |
||||
#endif |
||||
|
||||
/* global DNS server UDP endpoint */ |
||||
sock_udp_ep_t sock_dns_server; |
||||
|
||||
/* import "ifconfig" shell command, used for printing addresses */ |
||||
|
||||
extern int _netif_config(int argc, char **argv); |
||||
|
||||
int main(void) |
||||
{ |
||||
uint8_t addr[16] = {0}; |
||||
|
||||
sock_udp_str2ep(&sock_dns_server, DNS_SERVER); |
||||
|
||||
puts("waiting for router advertisement..."); |
||||
xtimer_usleep(1U*1000000); |
||||
|
||||
/* print network addresses */ |
||||
puts("Configured network interfaces:"); |
||||
_netif_config(0, NULL); |
||||
|
||||
int res = sock_dns_query(TEST_NAME, addr, AF_UNSPEC); |
||||
if (res > 0) { |
||||
char addrstr[INET6_ADDRSTRLEN]; |
||||
inet_ntop(res == 4 ? AF_INET : AF_INET6, addr, addrstr, sizeof(addrstr)); |
||||
printf("%s resolves to %s\n", TEST_NAME, addrstr); |
||||
} |
||||
else { |
||||
printf("error resolving %s\n", TEST_NAME); |
||||
} |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue