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

Functions to start the DNS Client. More...

Functions to start the DNS Client.

Start the DNS Client by calling the function netDNSc_GetHostByName. DNS requests are routed to the DNS Server IP address of an active network interface. If you are using a PPP or SLIP interface and no Ethernet Interface interface, you must enable the "Use default Gateway on remote Network" option in the configuration file (Net_Config_PPP_0.h or Net_Config_SLIP_0.h).

You must also specify a callback function, which is called from the DNS Client when a DNS event occurs.

static void dns_cbfunc (netDNSc_Event event, const NET_ADDR *addr) {
char ip_ascii[40];
switch (event) {
case netDNSc_EventSuccess:
// Host Address successfully resolved.
netIP_ntoa (addr->addr_type, addr->addr, ip_ascii, sizeof (ip_ascii));
printf ("IP Address: %s\n", ip_ascii)
break;
case netDNSc_EventTimeout:
// All DNS Resolver retries used up and timeouts expired.
printf ("DNS Resolver Timeout expired, Host Address not resolved.\n");
break;
case netDNSc_EventNotResolved:
// Host Name does not exist in DNS record database.
printf ("Host name does not exist.\n");
break;
case netDNSc_EventError:
// DNS Protocol Error, invalid or corrupted reply received.
printf ("DNS Resolver Protocol Error, Host Address not resolved.\n");
break;
}
}

When the required host is found in the local DNS Cache, the callback function is called immediately with the result code netDNSc_EventSuccess and provides the IP address of the host to the function. In this case, no actual DNS request packet is sent to the remote DNS Server.

Note
You can also provide the IP address in a string format to specify the host name. The DNS Client decodes it and returns the decoded IP address to the callback function.