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 | common/interface/dns.h |
Classes |
IDns UDns IDnsQueryResult IDnsQueryEntry IDnsQueryEntryA IDnsQueryEntryAAAA IDnsQueryEntryCNAME IDnsQueryEntryMX IDnsQueryEntryNS IDnsQueryEntrySRV IDnsQueryEntryTXT IDnsQueryEntrySOA IDnsQueryEntryPTR IDnsQueryEntryNAPTR |
Data types |
DNS_DEFAULT_TIMEOUT dns_query_type_sdk |
Examples |
Code Example |
class IDns {
public:
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);
virtual void Query(const char * hostName, class UDns * const user, class IInstanceLog * const log, dns_query_type_sdk queryType);
};
class IIoMux * const iomux | The IIoMux instance used by IDns. |
const char * host | The hostname (e. g. "innovaphone.com"). |
class UDns * user | The UDns instance callback after the name has been resolved (or an error occurred). |
class IInstanceLog * const log | The 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. |
const char * host | The hostname (e. g. "innovaphone.com"). |
class UDns * user | The UDns instance callback after the name has been resolved (or an error occurred). |
class IInstanceLog * const log | The IInstanceLog instance to write logging messages to. Only used, if LOG_DNS is enabled. |
dns_query_type_sdk queryType | A value of enum dns_query_type_sdk to indicate the type of search. |
class UDns {
public:
virtual void DnsGetHostByNameResult(const char * addr, bool isIPv6);
virtual void DnsQueryResult(const byte * answer, unsigned length);
};
const char * addr | The TCP/IP address of the hostname given to IDns::GetHostByName(). If an error occured, addr will be nullptr. |
bool isIPv6 | True, if the address given in addr is an IPv6 address, or false, if it is IPv4. |
const byte * answer | The binary answer. |
unsigned length | The length of the binary data. |
class IDnsQueryResult {
public:
static IDnsQueryResult * Parse(const byte * answer, unsigned length);
virtual ~IDnsQueryResult() {};
virtual size_t GetAnswerCount() = 0;
virtual size_t GetAuthorityCount() = 0;
virtual size_t GetAdditionalCount() = 0;
virtual IDnsQueryEntry * GetAnswer(size_t index) = 0;
virtual IDnsQueryEntry * GetAuthority(size_t index) = 0;
virtual IDnsQueryEntry * GetAdditional(size_t index) = 0;
};
const byte * answer | The binary data of the DNS query response. |
unsigned length | The length of the binary data. |
size_t index | The index of the answer record. |
size_t index | The index of the authority record. |
size_t index | The index of the additional record. |
class IDnsQueryEntry {
public:
virtual ~IDnsQueryEntry() {};
virtual const char * GetName() { return nullptr; }
virtual dns_query_type_sdk GetType() { return DNS_QUERY_TYPE_NONE; }
virtual dword GetTTL() { return 0; }
};
class IDnsQueryEntryA : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryA() {};
virtual const char * GetAddress() = 0;
};
class IDnsQueryEntryAAAA : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryAAAA() {};
virtual const char * GetAddress() = 0;
};
class IDnsQueryEntryCNAME : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryCNAME() {};
virtual const char * GetCanonicalName() = 0;
};
class IDnsQueryEntryMX : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryMX() {};
virtual word GetPreference() = 0;
virtual const char * GetMailServer() = 0;
};
class IDnsQueryEntryNS : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryNS() {};
virtual const char * GetNameServer() = 0;
};
class IDnsQueryEntrySRV : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntrySRV() {};
virtual word GetPriority() = 0;
virtual word GetWeight() = 0;
virtual word GetPort() = 0;
virtual const char * GetTarget() = 0;
};
class IDnsQueryEntryTXT : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryTXT() {};
virtual size_t GetTextCount() = 0;
virtual const char * GetTxt(size_t index) = 0;
};
size_t index | The index of the text string. |
class IDnsQueryEntrySOA : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntrySOA() {};
virtual const char * GetPrimaryNS() = 0;
virtual const char * GetResponsibleMailbox() = 0;
virtual dword GetSerialNumber() = 0;
virtual dword GetRefreshInterval() = 0;
virtual dword GetRetryInterval() = 0;
virtual dword GetExpireLimit() = 0;
virtual dword GetMinimumTTL() = 0;
};
class IDnsQueryEntryPTR : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryPTR() {};
virtual const char * GetDomainName() = 0;
};
class IDnsQueryEntryNAPTR : public virtual IDnsQueryEntry {
public:
virtual ~IDnsQueryEntryNAPTR() {};
virtual word GetOrder() = 0;
virtual word GetPreference() = 0;
virtual const char * GetFlags() = 0;
virtual const char * GetServices() = 0;
virtual const char * GetRegexp() = 0;
virtual const char * GetReplacement() = 0;
};
DNS_DEFAULT_TIMEOUT | The default timeout for DNS lookup requests (5000ms). |
typedef enum {
DNS_QUERY_TYPE_NONE = 0, /* use getaddr_info instead of res_query */
DNS_QUERY_TYPE_A = 1, /* host address */
DNS_QUERY_TYPE_NS = 2, /* authoritative server */
DNS_QUERY_TYPE_MD = 3, /* mail destination */
DNS_QUERY_TYPE_MF = 4, /* mail forwarder */
DNS_QUERY_TYPE_CNAME = 5, /* canonical name */
DNS_QUERY_TYPE_SOA = 6, /* start of authority zone */
DNS_QUERY_TYPE_MB = 7, /* mailbox domain name */
DNS_QUERY_TYPE_MG = 8, /* mail group member */
DNS_QUERY_TYPE_MR = 9, /* mail rename name */
DNS_QUERY_TYPE_NULL = 10, /* null resource record */
DNS_QUERY_TYPE_WKS = 11, /* well known service */
DNS_QUERY_TYPE_PTR = 12, /* domain name pointer */
DNS_QUERY_TYPE_HINFO = 13, /* host information */
DNS_QUERY_TYPE_MINFO = 14, /* mailbox information */
DNS_QUERY_TYPE_MX = 15, /* mail routing information */
DNS_QUERY_TYPE_TXT = 16, /* text strings */
DNS_QUERY_TYPE_RP = 17, /* responsible person */
DNS_QUERY_TYPE_AFSDB = 18, /* AFS cell database */
DNS_QUERY_TYPE_X25 = 19, /* X_25 calling address */
DNS_QUERY_TYPE_ISDN = 20, /* ISDN calling address */
DNS_QUERY_TYPE_RT = 21, /* router */
DNS_QUERY_TYPE_NSAP = 22, /* NSAP address */
DNS_QUERY_TYPE_NSAP_PTR = 23, /* reverse NSAP lookup (deprecated) */
DNS_QUERY_TYPE_SIG = 24, /* security signature */
DNS_QUERY_TYPE_KEY = 25, /* security key */
DNS_QUERY_TYPE_PX = 26, /* X.400 mail mapping */
DNS_QUERY_TYPE_GPOS = 27, /* geographical position (withdrawn) */
DNS_QUERY_TYPE_AAAA = 28, /* IP6 Address */
DNS_QUERY_TYPE_LOC = 29, /* Location Information */
DNS_QUERY_TYPE_NXT = 30, /* Next Valid Name in Zone */
DNS_QUERY_TYPE_EID = 31, /* Endpoint identifier */
DNS_QUERY_TYPE_NIMLOC = 32, /* Nimrod locator */
DNS_QUERY_TYPE_SRV = 33, /* Server selection */
DNS_QUERY_TYPE_ATMA = 34, /* ATM Address */
DNS_QUERY_TYPE_NAPTR = 35, /* Naming Authority PoinTeR */
DNS_QUERY_TYPE_KX = 36, /* Key Exchanger */
DNS_QUERY_TYPE_CERT = 37, /* CERT */
DNS_QUERY_TYPE_A6 = 38, /* A6 */
DNS_QUERY_TYPE_DNAME = 39, /* DNAME */
DNS_QUERY_TYPE_SINK = 40, /* SINK */
DNS_QUERY_TYPE_OPT = 41, /* OPT pseudo-RR, RFC2671 */
DNS_QUERY_TYPE_APL = 42, /* APL */
DNS_QUERY_TYPE_DS = 43, /* Delegation Signer */
DNS_QUERY_TYPE_SSHFP = 44, /* SSH Key Fingerprint */
DNS_QUERY_TYPE_RRSIG = 46, /* RRSIG */
DNS_QUERY_TYPE_NSEC = 47, /* NSEC */
DNS_QUERY_TYPE_DNSKEY = 48 /* DNSKEY */
} dns_query_type_sdk;
This enum is used determine the type of the query.
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;
}