Dns C Reference Documentation
Dns
Current Version: 11.6.0
Chilkat.Dns
Query common DNS record types and receive structured JSON results that
are easy to inspect or pass to other application logic.
Configure the nameservers Chilkat uses instead of relying only on the
operating system's default DNS configuration.
Prefer DNS-over-TLS when appropriate for applications that need encrypted
DNS lookups.
Control how long DNS queries may wait before failing, which is useful for
responsive applications and troubleshooting.
Nameserver settings affect DNS resolution across Chilkat classes, not
only the current
Use
For an extended overview, see
Dns Class Overview.
Configure DNS resolution and query DNS records directly from Chilkat.
Chilkat.Dns is a focused class for DNS configuration and DNS
record querying. It allows applications to control the nameservers used by
Chilkat, query common DNS record types into JSON, configure DNS-over-TLS
preference, set DNS query timeouts, and obtain useful diagnostics through
LastErrorText.
DNS record queries
Nameserver control
DNS-over-TLS preference
Timeout settings
Application-wide behavior
Dns object.
Diagnostics
LastErrorText to troubleshoot DNS configuration,
lookup failures, timeout problems, or nameserver connectivity issues.
Dns either to perform direct DNS lookups, or to configure
the DNS behavior used by Chilkat as a whole. Because nameserver changes can
affect DNS resolution across Chilkat classes, treat them as application-wide
configuration rather than object-local state.
Create/Dispose
HCkDns instance = CkDns_Create();
// ...
CkDns_Dispose(instance);Creates an instance of the HCkDns object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.
Objects created by calling CkDns_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkDns_Dispose.
Callback Functions
void CkDns_setAbortCheck(HCkHttp cHandle, BOOL (*fnAbortCheck)(void));
Gives your application a chance to cancel a method call while it is running. Return to abort the operation in progress, or TRUE to let it continue.FALSE
This callback fires periodically, at the interval set by the HeartbeatMs property. For example, set HeartbeatMs to 200 to receive five AbortCheck callbacks per second. If HeartbeatMs is 0, no callbacks are made and the operation cannot be aborted.
void CkDns_setPercentDone(HCkHttp cHandle, BOOL (*fnPercentDone)(int pctDone));
Reports how far along a method call is, as a percentage. It applies to methods that involve network communication or time-consuming processing, and fires only when a percentage completed can actually be measured and it makes sense to express progress that way.
The pctDone argument is a value from 1 to 100. Methods that finish very quickly may produce only a few callbacks, but the final callback always reports 100. Long-running operations produce at most one callback per percentage point (for example: 1, 2, 3, … 98, 99, 100).
This callback also counts as an AbortCheck callback. When PercentDone fires, it replaces the AbortCheck callback that would otherwise have occurred at that moment.
The return value controls whether the method call continues. Return to abort, or TRUE to proceed.FALSE
void CkDns_setProgressInfo(HCkHttp cHandle, void (*fnProgressInfo)(const char *name, const char *value));
A general-purpose callback that reports name/value pairs describing what is happening at various points during a method call. The information provided varies by method, and some methods provide none at all. To see what a particular method reports, write a handler that logs each name/value pair. Most are self-explanatory.
void CkDns_setTaskCompleted(HCkHttp cHandle, void (*fnTaskCompleted)(HCkTask hTask));
Called when an asynchronous task finishes. This callback runs in the background thread rather than the thread that started the task. (While an async method is running, all callbacks occur in the background thread.)
Properties
DebugLogFilePath
void CkDns_putDebugLogFilePath(HCkDns cHandle, const char *newVal);
const char *CkDns_debugLogFilePath(HCkDns cHandle);
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
HeartbeatMs
void CkDns_putHeartbeatMs(HCkDns cHandle, int newVal);
The interval in milliseconds between each AbortCheck event callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set to 0, meaning no AbortCheck event callbacks will trigger.
LastErrorHtml
const char *CkDns_lastErrorHtml(HCkDns cHandle);
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
const char *CkDns_lastErrorText(HCkDns cHandle);
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
const char *CkDns_lastErrorXml(HCkDns cHandle);
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
void CkDns_putLastMethodSuccess(HCkDns cHandle, BOOL newVal);
Indicates the success or failure of the most recent method call: TRUE means success, FALSE means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
MaxWaitMs
void CkDns_putMaxWaitMs(HCkDns cHandle, int newVal);
The maxiumum number of milliseconds to wait for the answer to a DNS query. A value of 0 is to wait indefinitely (no timeout). It's not a good idea to specify 0 (infinite timeout) or a value less than 1000 (1 second). The default value is 10000 milliseconds.
topNumNameservers
The number of nameservers currently being used by Chilkat for DNS queries in all objects/classes, such as for HTTP, Email, FTP, SSH, etc.
topTlsPref
void CkDns_putTlsPref(HCkDns cHandle, int newVal);
Specifies the TLS preference. Possible values are:
- 0 = No TLS
- 1 = Prefer TLS if possible.
- 2 = Require TLS
The default value is 0. If TLS is preferred then DNS nameservers with TLS capability will be tried first. If none succeed, then UDP/TCP will be tried. If TLS is required, then only TLS capable nameservers will be tried and all DNS queries will use TLS.
Note: To use TLS, your application needs to first specify nameservers by calling AddNameserver once per nameserver with the supportsTls argument set to TRUE.
UncommonOptions
void CkDns_putUncommonOptions(HCkDns cHandle, const char *newVal);
const char *CkDns_uncommonOptions(HCkDns cHandle);
This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.
topUtf8
void CkDns_putUtf8(HCkDns cHandle, BOOL newVal);
When set to TRUE, all const char * arguments and return values are interpreted as UTF-8 strings. When set to FALSE, they are interpreted as ANSI strings.
In Chilkat v11.0.0 and later, the default value is TRUE. Before v11.0.0, it was FALSE.
VerboseLogging
void CkDns_putVerboseLogging(HCkDns cHandle, BOOL newVal);
If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
Methods
AddDefaultNameservers
Adds the default (auto-assigned) nameservers to the collection of nameservers used by Chilkat for DNS queries and domain to IP address lookups.
AddNameserver
Adds a new nameserver to the collection of nameservers used by Chilkat for DNS queries and domain to IP address lookups. The ipAddr specifies the IPv4 address of the nameserver. The supportsTls indicates if the namserver supports DoT (DNS over TLS. DoT uses port 853 for encrypted DNS communication.) If the TlsPreference property is set to 1 or 2, then Chilkat will use TLS nameservers.
GetNameserver
const char *CkDns_getNameserver(HCkDns cHandle, int index);
Returns the IP address of the Nth nameserver currently used by Chilkat for DNS queries and domain to IP address lookups. The index specifies the index of the nameserver. The 1st nameserver is at index 0.
Returns TRUE for success, FALSE for failure.
Query
Performs an DNS query for domain and returns the answer in answer. The type of DNS query is specified in recordType and can be A, AAAA, ALIAS, CAA, MX, NS, SOA, TXT. Additional record types can be added as needed.
QueryAsync (1)
Creates an asynchronous task to call the Query method with the arguments provided.
Returns NULL on failure
RemoveAllNameservers
Removes all nameservers from the collection of nameservers used by Chilkat. An application can call this method to reset to 0 nameservers before adding new nameservers. If a DNS domain to IP address resolution is needed by Chilkat, then the auto-assigned nameserver IP addresses will be automaticaly restored.
RemoveNameserver
Removes a nameserver from the collection of nameservers used by Chilkat. The ipAddr is the IPv4 address of the nameserver to be removed.