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, an error message will be written to the log (if LOG_DNS is set) and the addr parameter will be nullptr. If no or no more results can be found, addr parameter will be set to nullptr, too. 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(). Maybe nullptr (see remarks below).
bool isIPv6True, if the address given in addr is an IPv6 address, or false, if it is IPv4.


There are two reasons, why addr will be nullptr. At first, if an error occured. In that case the error message will be written to the log (if the log flag LOG_DNS is set, using SetLogFlags() of your app instance class). The second reason is, that no or no more results are available. If the all flag of IDns::GetHostByName() is set, this function can be called multiple times. So your application should save or handle each result until addr is set to nullptr.

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;