The DNS interface is for DNS lookups. Note that this class is - while be used asynchrounosly - internal using a thread for the look up stuff.

File information


Classes IDns


Examples Code Example



class IDns {
    static IDns * Create(class IIoMux * const iomux);
    virtual ~IDns() {};
    virtual void GetHostByName(const char * host, class UDns * const user, class IInstanceLog * const log, dword timeout = DNS_DEFAULT_TIMEOUT, bool all = false);

Public functions

Create (static)

Creates an instance of IDns. iomux has to be a iomux instance IDns can use. The returned instance needs to be deleted after it is no longer used. Note that the IDns uses a thread to make the DNS lookup to not block the application. Generally this won't be a problem for the application, because the result of the lookup will be send to the mainthread of the application (or at least to the thread of the given iomux) in an synchronized way.


class IIoMux * const iomuxThe IIoMux instance used by IDns.

Return value

The IDns instance the application can use for for DNS lookups. Note that this instance must be released by the application, if no longer used.


Starts the lookup of the given host. The lookup requests will be cached internally and handled in a fifo order. The interface uses the DNS servers defined in the local network settings of the AppPlatform.


const char * hostThe hostname (e. g. "innovaphone.com").
class UDns * userThe UDns instance callback after the name has been resolved (or an error occurred).
class IInstanceLog * const logThe IInstanceLog instance to write logging messages to. Only used, if LOG_DNS is enabled.
dword timeout(Default: DNS_DEFAULT_TIMEOUT) The timeout in milliseconds to wait until the request will be canceled if the DNS server won't answer.
bool all(Default: false) If that flag is set, all IP addresses found for the hostname will be reported, else only the first one.


UDns::DnsGetHostByNameResult() will be called, passing the IP address for the given hostname. If all is set to true, the function can be called multiple times. If an error occures, the addr parameter of the callback function will be nullptr. See UDns.


class UDns {
    virtual void DnsGetHostByNameResult(const char * addr, bool isIPv6);

When calling IDns::GetHostByName(), an instance of UDns must be passed as user. So the application must provide a class instance that implements UDns. After a DNS lookup, this function will be called. If the flag all of IDnsGetHostByName() has ben set to true, DnsGetHostByNameResult() can be called multiple times, one time for each DNS entry found.


const char * addrThe TCP/IP address of the hostname given to IDns::GetHostByName(). If an error occured, addr will be nullptr.
bool isIPv6True, if the address given in addr is an IPv6 address, or false, if it is IPv4.

Data types

Defines / Statics

DNS_DEFAULT_TIMEOUTThe default timeout for DNS lookup requests (5000ms).

Code Example

app::app(IIoMux * iomux)
    : iomux(iomux)
    this->dns = IDns::Create(iomux);
    this->dns->GetHostByName("innovaphone.com", this);

void app::DnsGetHostByNameResult(const char * addr, bool isIPv6)

    if (addr == nullptr) debug->printf("DNS lookup of innovaphone.com failed\n");
    else debug->printf("ip address of innovaphone.com = %s\n", addr);

    delete this->dns;
    this->dns = nullptr;