|
| get_host_by_name| Summary | |
#include <rtl.h>
U8 get_host_by_name (
U8* hostn, /* Pointer to the hostname. */
void (*cbfunc)(U8 event, U8* host_ip) ); /* Function to call when the DNS request ends. */
| | Description | | The get_host_by_name function resolves the IP address of a host from a hostname. The argument hostn is a pointer to a NULL terminated string that specifies the hostname. The function get_host_by_name starts the DNS client on TCPnet, to send a request to the DNS server. The argument cbfunc specifies a user provided callback function that the DNS client calls when an event ends the DNS session. The DNS client specifies the event and the host IP address (in case of DNS_EVT_SUCCESS) when calling the cbfunc function. | Event | Description |
|---|
| DNS_EVT_SUCCESS | The IP address has been resolved. The argument host_ip of the function cbfunc points to a 4-byte buffer containing the IP address in dotted decimal notation. | | DNS_EVT_NONAME | The hostname was not found in the DNS server. | | DNS_EVT_TIMEOUT | The timeout has expired before the IP address could be resolved. | | DNS_EVT_ERROR | A DNS communication protocol error has occurred. This can also result from misplaced dots in the hostname or incorrect name labels. |
The get_host_by_name function is in the RL-TCPnet library. The prototype is defined in rtl.h. note - The hostname argument hostn can also point to the dotted decimal IP address in sting format (for example "192.168.0.100"). In this case, the DNS client calls the cbfunc function immediately with the IP address.
| | Return Value | | The get_host_by_name function returns a code that specifies either the state of the dns resolving process or an error. If the return code is an error, then the current DNS request is ignored: | Return code | Description |
|---|
| DNS_RES_OK | The DNS resolving process has started. | | DNS_ERROR_BUSY | The DNS resolving process is still busy. | | DNS_ERROR_LABEL | The hostname label is too long. | | DNS_ERROR_NAME | The hostname is too long. | | DNS_ERROR_NOSRV | The DNS server IP address has not been specified. | | DNS_ERROR_UDPSEND | The UDP socket cannot send packets. |
| | Example | |
static void dns_cbfunc (U8 event, U8 *ip);
void resolve_host (void) {
U8 res;
res = get_host_by_name ("www.keil.com",dns_cbfunc);
switch (res) {
case DNS_RES_OK:
break;
case DNS_ERROR_BUSY:
printf("DNS Resolver is still busy. Request ignored.\n");
break;
case DNS_ERROR_LABEL:
printf("Host name label too long.\n");
break;
case DND_ERROR_NAME:
printf("Host name too long.\n");
break;
case DNS_ERROR_NOSRV:
printf("DNS Server IP address not specified.\n");
break;
case DNS_ERROR_UDPSEND:
printf("Error sending UDP packet.\n");
break;
}
}
|
|
|