Network Component
Version 7.19.0
MDK Middleware for IPv4 and IPv6 Networking
|
Functions to start the DNS Client. More...
Typedefs | |
typedef void(* | netDNSc_cb_t) (netDNSc_Event event, const NET_ADDR *addr) |
DNS Client Event callback function. More... | |
Functions | |
netStatus | netDNSc_GetHostByName (const char *name, int16_t addr_type, netDNSc_cb_t cb_func) |
Resolve IP address of a host from a hostname. [thread-safe]. More... | |
netStatus | netDNSc_GetHostByNameX (const char *name, int16_t addr_type, NET_ADDR *addr) |
Resolve IP address of a host from a hostname in blocking mode. [thread-safe]. More... | |
netStatus | netDNSc_ClearCache (void) |
Flush or clear the local DNS cache. [thread-safe]. 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.h or Net_Config_SLIP.h).
You must also specify a callback function, which is called from the DNS Client when a DNS event occurs.
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.
void(* netDNSc_cb_t)(netDNSc_Event event, const NET_ADDR *addr) |
DNS Client Event callback function.
[in] | event | DNS client event type as defined in netDNSc_Event. |
[in] | addr | Pointer to the structure containing resolved IP address of the host name. |
Is the type definition for the DNS callback function. The function is invoked by the DNS client when an event ends the DNS session. The DNS client specifies the event and the host IP address (in case of netDNSc_EventSuccess) when calling the function.
Parameter for:
Code Example
netStatus netDNSc_ClearCache | ( | void | ) |
Flush or clear the local DNS cache. [thread-safe].
The function netDNSc_ClearCache flushes all resolved IP addresses from the local DNS cache. You can use this function when the cache holds outdated values that are no longer valid.
Possible netStatus return values:
Code Example
netStatus netDNSc_GetHostByName | ( | const char * | name, |
int16_t | addr_type, | ||
netDNSc_cb_t | cb_func | ||
) |
Resolve IP address of a host from a hostname. [thread-safe].
[in] | name | hostname, a null-terminated string. |
[in] | addr_type | network address type to resolve:
|
[in] | cb_func | callback function to call, when DNS session ends. |
The non-blocking function netDNSc_GetHostByName resolves the IP address of a host from a host name. It starts the DNS client and sends a request to the DNS server.
The argument name is a pointer to a null-terminated string that specifies the host name. The argument name can also point to the dotted decimal IPv4 address in string format (for example "192.168.0.100"), or to the hexadecimal IPv6 address in string format (for example "2001:4860:4860::8888"). In this case, the DNS client calls the cb_func function immediately with the IP address. The argument name can also be "localhost", in this case the DNS client calls the cb_func function immediately with the loopback IP address: "127.0.0.1" for IPv4 or "::1" for IPv6.
The argument addr_type specifies the type of address to resolve. It is NET_ADDR_IP4 when you want to resolve an IPv4 address, and NET_ADDR_IP6 when you want to resolve an IPv6 address.
The argument cb_func specifies a user-provided callback function. Refer to netDNSc_cb_t.
Possible netStatus return values:
Code Example
Resolve IP address of a host from a hostname in blocking mode. [thread-safe].
[in] | name | hostname, a null-terminated string. |
[in] | addr_type | network address type to resolve:
|
[out] | addr | structure that will receive resolved IP address of the hostname. |
The blocking function netDNSc_GetHostByNameX resolves the IP address of a host from a host name. It starts the DNS client, sends a request to the DNS server and returns the resolved IP address.
The argument name is a pointer to a null-terminated string that specifies the host name. The argument name can also point to the dotted decimal IPv4 address in string format (for example "192.168.0.100"), or to the hexadecimal IPv6 address in string format (for example "2001:4860:4860::8888"). In this case, the DNS client calls the cb_func function immediately with the IP address. The argument name can also be "localhost", in this case the DNS client calls the cb_func function immediately with the loopback IP address: "127.0.0.1" for IPv4 or "::1" for IPv6.
The argument addr_type specifies the type of address to resolve. It is NET_ADDR_IP4 when you want to resolve an IPv4 address, and NET_ADDR_IP6 when you want to resolve an IPv6 address.
The argument addr specifies a user-provided NET_ADDR address structure that will receive the resolved IP address.
Possible netStatus return values:
Code Example