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"
#include "rl_net.h"
const char *hosts[] = {
"www.google.com",
"www.keil.com",
"www.microsoft.com",
"www.yahoo.com",
"192.168.0.253"
};
unsigned int idx;
static void next_host () {
if (++idx == sizeof(hosts)/sizeof(hosts[0])) {
idx = 0;
}
}
static void dns_cbfunc (dnsClientEvent event, const uint8_t *ip_addr) {
switch (event) {
case dnsClientSuccess:
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:
printf("Host name does not exist.\n");
next_host();
break;
case dnsClientTimeout:
printf("DNS Resolver Timeout expired, Host Address not resolved.\n");
break;
case dnsClientError:
printf("DNS Resolver Protocol Error, Host Address not resolved.\n");
break;
}
}
int main (void) {
idx = 0;
while (1) {
...
res = get_host_by_name (hosts[idx], dns_cbfunc);
switch (res) {
case netOK:
break;
case netBusy:
break;
case netInvalidParameter:
printf ("Invalid parameters!\n");
next_host();
break;
case netServerError:
printf ("DNS Server unknown!\n");
break;
default:
break;
}
}
}