Network Dual-Stack Component  Version 7.0 (Beta)
MDK-Professional Middleware for IPv4 and IPv6 Networking
 All Data Structures Files Functions Enumerations Groups Pages
DNS Client

DNS Client routines help to resolve DNS requests using an external DNS server. More...

DNS Client routines help to resolve DNS requests using an external DNS server.

Domain Name System (DNS) servers store and manage information about domains and respond to resolution requests for clients (in some cases millions of times each day). The DNS database is a distributed name database stored on many DNS servers. DNS uses a hierarchical tree structure for its name space and a hierarchical tree for name authorities and registration.

The DNS Client is capable of resolving the IP address of a host from the host's name. It does this by sending DNS requests to a DNS Server. The IP address of a DNS Server is specified in the network interface configuration file or can be obtained from the DHCP Server for the Local Area Network.

Note
The page DNS Client gives you more information on the actual usage of the functions and how to work with them in a project.

Code Examples

DNS Resolution Example

#include <stdio.h>
#include "cmsis_os.h" // CMSIS RTOS definitions
#include "rl_net.h" // Network definitions
const char *hosts[] = {
"www.google.com",
"www.keil.com",
"www.microsoft.com",
"www.yahoo.com",
"192.168.0.253"
};
unsigned int idx;
// Select next host from the table.
static void next_host () {
if (++idx == sizeof(hosts)/sizeof(hosts[0])) {
idx = 0;
}
}
// This function is called by the DNS client when dns event occurs.
static void dns_cbfunc (dnsClientEvent event, const uint8_t *ip_addr) {
switch (event) {
case dnsClientSuccess:
// Host Address successfully resolved.
printf("IP Address : %d.%d.%d.%d\n", ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]);
next_host();
break;
case dnsClientNotResolved:
// Host Name does not exist in DNS record database.
printf("Host name does not exist.\n");
next_host();
break;
case dnsClientTimeout:
// All DNS Resolver retries used up and timeouts expired.
printf("DNS Resolver Timeout expired, Host Address not resolved.\n");
break;
case dnsClientError:
// DNS Protocol Error, invalid or corrupted reply received.
printf("DNS Resolver Protocol Error, Host Address not resolved.\n");
break;
}
}
int main (void) {
netStatus res;
idx = 0;
while (1) {
...
res = get_host_by_name (hosts[idx], dns_cbfunc);
switch (res) {
case netOK:
// Resolver started, wait for callback event.
break;
case netBusy:
// Busy, retry on next tick.
break;
case netInvalidParameter:
printf ("Invalid parameters!\n");
next_host();
break;
case netServerError:
printf ("DNS Server unknown!\n");
break;
default:
// catch other enumeration values
break;
}
}
}