2017-04-10 00:34:57 +08:00
|
|
|
.. _dns-resolve-sample:
|
2017-04-05 03:00:08 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
DNS Resolve Application
|
|
|
|
#######################
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
Overview
|
2017-01-21 07:58:05 +08:00
|
|
|
********
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
The DNS resolver sample application implements a basic DNS resolver according
|
|
|
|
to RFC 1035. Supported DNS answers are IPv4/IPv6 addresses and CNAME.
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
If a CNAME is received, the DNS resolver will create another DNS query.
|
|
|
|
The number of additional queries is controlled by the
|
|
|
|
DNS_RESOLVER_ADDITIONAL_QUERIES Kconfig variable.
|
|
|
|
|
2017-09-04 03:12:23 +08:00
|
|
|
The multicast DNS (mDNS) client resolver support can be enabled by setting
|
|
|
|
CONFIG_MDNS_RESOLVER Kconfig variable.
|
|
|
|
See https://tools.ietf.org/html/rfc6762 for more details about mDNS.
|
|
|
|
|
2017-09-04 18:43:49 +08:00
|
|
|
The link-local multicast name resolution (LLMNR) client resolver support can be
|
|
|
|
enabled by setting the :option:`CONFIG_LLMNR_RESOLVER` Kconfig option.
|
|
|
|
See https://tools.ietf.org/html/rfc4795 for more details about LLMNR.
|
|
|
|
|
2017-01-08 06:01:53 +08:00
|
|
|
For more information about DNS configuration variables, see:
|
|
|
|
:file:`subsys/net/lib/dns/Kconfig`. The DNS resolver API can be found at
|
2017-04-10 00:34:57 +08:00
|
|
|
:file:`include/net/dns_resolve.h`. The sample code can be found at:
|
|
|
|
:file:`samples/net/dns_resolve`.
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
Requirements
|
2017-01-21 07:58:05 +08:00
|
|
|
************
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-06-07 18:18:03 +08:00
|
|
|
- :ref:`networking_with_qemu`
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
- screen terminal emulator or equivalent.
|
|
|
|
|
|
|
|
- For the Arduino 101 board, the ENC28J60 Ethernet module is required.
|
|
|
|
|
|
|
|
- dnsmasq application. The dnsmasq version used in this sample is:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
dnsmasq -v
|
|
|
|
Dnsmasq version 2.76 Copyright (c) 2000-2016 Simon Kelley
|
|
|
|
|
|
|
|
Building and Running
|
2017-01-21 07:58:05 +08:00
|
|
|
********************
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
Network Configuration
|
2017-01-21 07:58:05 +08:00
|
|
|
=====================
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-02-03 03:49:16 +08:00
|
|
|
Open the project configuration file for your platform, for example:
|
|
|
|
:file:`prj_frdm_k64f.conf` is the configuration file for the
|
2017-04-10 00:34:57 +08:00
|
|
|
:ref:`frdm_k64f` board.
|
2017-02-03 03:49:16 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
In this sample application, both static or DHCPv4 IP addresses are supported.
|
|
|
|
Static IP addresses are specified in the project configuration file,
|
2017-02-03 03:49:16 +08:00
|
|
|
for example:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-03-15 23:01:47 +08:00
|
|
|
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
|
|
|
|
CONFIG_NET_APP_PEER_IPV6_ADDR="2001:db8::2"
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
are the IPv6 addresses for the DNS client running Zephyr and the DNS server,
|
|
|
|
respectively.
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
DNS server
|
|
|
|
==========
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
The dnsmasq tool may be used for testing purposes. Sample dnsmasq start
|
2017-06-07 18:18:03 +08:00
|
|
|
script can be downloaded from the zephyrproject-rtos/net-tools project area:
|
|
|
|
https://github.com/zephyrproject-rtos/net-tools
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
Open a terminal window and type:
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
$ cd net-tools
|
2017-09-04 03:12:23 +08:00
|
|
|
$ sudo ./dnsmasq.sh
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-06-02 06:12:57 +08:00
|
|
|
The default project configurations settings for this sample uses the public
|
|
|
|
Google DNS servers. In order to use the local dnsmasq server, please edit
|
|
|
|
the appropriate 'prj.conf' file and update the DNS server addresses. For
|
|
|
|
instance, if using the usual IP addresses assigned to testing, update them
|
|
|
|
to the following values:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
CONFIG_DNS_SERVER1="192.0.2.2:5353"
|
|
|
|
CONFIG_DNS_SERVER2="[2001:db8::2]:5353"
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
DNS uses port 53 by default, but the dnsmasq.conf file provided by
|
|
|
|
net-tools uses port 5353 to allow executing the daemon without
|
|
|
|
superuser privileges.
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
If dnsmasq fails to start with an error like this:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
dnsmasq: failed to create listening socket for port 5353: Address already in use
|
|
|
|
|
|
|
|
Open a terminal window and type:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ killall -s KILL dnsmasq
|
|
|
|
|
|
|
|
Try to launch the dnsmasq application again.
|
|
|
|
|
2017-09-04 03:12:23 +08:00
|
|
|
For testing mDNS, use Avahi script in net-tools project:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ cd net-tools
|
|
|
|
$ ./avahi-daemon.sh
|
|
|
|
|
2017-01-08 06:01:53 +08:00
|
|
|
QEMU x86
|
2017-01-21 07:58:05 +08:00
|
|
|
========
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-06-07 18:18:03 +08:00
|
|
|
To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
|
2017-01-08 06:01:53 +08:00
|
|
|
FRDM K64F
|
2017-01-21 07:58:05 +08:00
|
|
|
=========
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-01-16 03:00:22 +08:00
|
|
|
Open a terminal window and type:
|
|
|
|
|
2017-11-10 18:25:45 +08:00
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/net/dns_resolve
|
|
|
|
:board: frdm_k64f
|
|
|
|
:goals: build flash
|
|
|
|
:compact:
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-02-02 22:18:52 +08:00
|
|
|
See :ref:`Freedom-K64F board documentation <frdm_k64f>` for more information
|
2017-01-08 06:01:53 +08:00
|
|
|
about this board.
|
|
|
|
|
|
|
|
Open a terminal window and type:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ screen /dev/ttyACM0 115200
|
|
|
|
|
|
|
|
|
|
|
|
Use 'dmesg' to find the right USB device.
|
|
|
|
|
|
|
|
Once the binary is loaded into the FRDM board, press the RESET button.
|
|
|
|
|
|
|
|
Arduino 101
|
2017-01-21 07:58:05 +08:00
|
|
|
===========
|
2017-01-08 06:01:53 +08:00
|
|
|
|
2017-01-16 03:00:22 +08:00
|
|
|
Open a terminal window and type:
|
|
|
|
|
2017-11-10 18:25:45 +08:00
|
|
|
.. zephyr-app-commands::
|
|
|
|
:zephyr-app: samples/net/dns_resolve
|
|
|
|
:board: arduino_101
|
|
|
|
:goals: build
|
|
|
|
:compact:
|
2017-04-10 00:34:57 +08:00
|
|
|
|
2017-01-08 06:01:53 +08:00
|
|
|
To load the binary in the development board follow the steps
|
2017-01-27 03:03:30 +08:00
|
|
|
in :ref:`arduino_101`.
|
2017-01-08 06:01:53 +08:00
|
|
|
|
|
|
|
Open a terminal window and type:
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
$ screen /dev/ttyUSB0 115200
|
|
|
|
|
2017-04-10 00:34:57 +08:00
|
|
|
|
2017-01-08 06:01:53 +08:00
|
|
|
Use 'dmesg' to find the right USB device.
|
|
|
|
|
|
|
|
Once the binary is loaded into the Arduino 101 board, press the RESET button.
|
2017-09-04 03:12:23 +08:00
|
|
|
|
|
|
|
The ENC28J60 module is an Ethernet device with SPI interface.
|
|
|
|
The following pins must be connected from the ENC28J60 device to the
|
|
|
|
Arduino 101 board:
|
|
|
|
|
|
|
|
=========== ===================================
|
|
|
|
Arduino 101 ENC28J60 (pin numbers on the board)
|
|
|
|
=========== ===================================
|
|
|
|
D13 SCK (1)
|
|
|
|
D12 SO (3)
|
|
|
|
D11 SI (2)
|
|
|
|
D10 CS (7)
|
|
|
|
D04 INT (5)
|
|
|
|
3.3V VCC (10)
|
|
|
|
GDN GND (9)
|
|
|
|
=========== ===================================
|