Indy 9
TIdDNSResolver
Hierarchy, Properties, Methods, Events, See Also, Unit: IdDNSResolver
Implements a UDP-based resolver for DNS queries.
TIdDNSResolver = class(TIdUDPClient)
Unit
IdDNSResolver
Description
TIdDNSResolver is a TIdUDPClient descendant that provides a stateless UDP-based implementation of a resolver for DNS (Domain Name Server) queries using the DNS protocol. The DNS protocol is described in the Internet Standards documents:

  • RFC 1034 - Domain Names Concepts and Facilities (http://www.rfc-editor.org/rfc/rfc1034.txt)

  • RFC 1035 - Domain Names Implementation and Specification (http://www.rfc-editor.org/rfc/rfc1035.txt)

  • RFC 1591 - Domain Name System Structure and Delegation (http://www.rfc-editor.org/rfc/rfc1591.txt)

  • RFC 1183 - New DNS RR Definitions. (http://www.rfc-editor.org/rfc/rfc1183.txt)

  • RFC 2181 - Clarifications to the DNS Specification. (http://www.rfc-editor.org/rfc/rfc2181.txt)

TIdDNSResolver provides facilities for accessing the Domain Name Space and Resource Records retrieved from a DNS Server using queries for specified domain names, resource types, and resource classes.

TIdDNSResolver provides properties and methods that simplify the process of creating a valid DNS query, and accessing the resource records returned in the query results.

Use QueryRecords to indicate DNS Resource Record types to be returned by the DNS Query. QueryRecords must contain on or more of the values from TQueryRecordTypes.

Set AllowRecursiveQueries to the value to be used in the DNS Query header. AllowRecursiveQueries permits a DNS server to pursue the query for DNS resource records on another name server. AllowRecursiveQueries has no effect if the DNS server does not implement recursive queries.

Use the Resolve method to peform a DNS Query for the specified domain name. Resolve creates the DNS Query packet, including the DNS header, transmits the request to the DNS host, and captures and parses the query results.

Use QueryResult to determine the number of resource records returned by the QueryClass, QueryType, and DomainName in the DNS Query, and to access the TResultRecord object instances containing the data for the resource records. Items in QueryResults may also be cast to an instance of a TResultRecord descendant class to access additional properties and methods based on its resource record type and class.

Note: Currently, the TIdDNSResolver implementation does not support all aspects of the DNS protocol, and includes the following limitations:

  • The DNS query type is limited to standard queries, where the DNS Header OPCODE is 0. Inverse queries (OPCODE=1) and Status queries (OPCODE=2) are not supported at this time.

  • The DNS query class field is limited to examing resource records for the IN (Internet) class only. CS (CSNet), CH (CHAOS), and HS (Hesiod) are not supported at this time.

TIdDNSResolver.AllowRecursiveQueries
TIdDNSResolver, See Also
Indicates if recursive DNS queries are desired on the DNS server.
property AllowRecursiveQueries: Boolean;
Description
AllowRecursiveQueries is a Boolean property that indicates if the DNS server should persue client queries which require resource records from another DNS name server. AllowRecursiveQueries is stored in the DNS Header for the request to the DNS server.

AllowRecursiveQueries will have no effect when the DNS does not implement recursive queries, as indicated in the DNS Header RA field from the server response.

The default value for AllowRecursiveQueries is True, as assigned in the Create constructor. Set the desired value for AllowRecursiveQueries prior to calling Resolve.


TIdDNSResolver.QueryRecords
TIdDNSResolver, See Also
Identifies the resource record types to examine using the DNS query.
property QueryRecords: TQueryType;
Description
QueryRecords is a TQueryType property that represents the resource record types desired in the answer to a DNS Query. QueryRecords is used to construct the Question portion of the DNS packet sent to the DNS server.

QueryRecords may contain one or more of the TQueryType values, including the following:

  • qtA - Host address

  • qtNS - Authoritative name server

  • qtMD - Mail destination (Obsolete - use MX)

  • qtMF - Mail forwarder (Obsolete - use MX)

  • qtName - Canonical name for an alias

  • qtSOA - Start of a zone of authority marker

  • qtMB - Mailbox domain name (EXPERIMENTAL)

  • qtMG - Mail group member (EXPERIMENTAL)

  • qtMR - Mail rename domain name (EXPERIMENTAL)

  • qtNull - Null resource record (EXPERIMENTAL)

  • qtWKS - Well known service description

  • qtPTR - Domain name pointer

  • qtHINFO - Host information

  • qtMINFO - Mailbox or mail list information

  • qtMX - Mail exchange

  • qtTXT - Text strings

  • qtSTAR - All resource record types

Update QueryRecords to include the values desired prior to calling the Resolve method.


TIdDNSResolver.QueryResult
TIdDNSResolver, See Also
Container for values and resource records in a DNS response.
property QueryResult: TQueryResult;
Description
QueryResult is a read-only TQueryResult property acts as a container for the results from a DNS query. QueryResult will indicate the class, type, and domain name used in the DNS query, as well as any DNS resource records returned in the query response.

QueryResult is updated when the Resolve method parses values found in the Answer portion of the DNS response.

QueryResult is a collection for TResultRecord resource records, and Items in the collection can be accessed using their integer position. Items in QueryResult may also be cast to a TResultRecord descendant class instance to allow access to additional properties and method specific to the resource record type.


TIdDNSResolver.Create
TIdDNSResolver, See Also
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
Parameters
AOwner: TComponent
Owner of the object instance.
Description
Create is the constructor for the object instance, and calls the inherited Create method using the value specified in AOwner. Create initializes Port to the constant value IdPORT_DOMAIN, as required by the DNS Protocol, and sets the default value of AllowRecursiveQueries to True. Create also allocates resources required for the QueryResult and DNSHeader properties.

TIdDNSResolver.Destroy
TIdDNSResolver, See Also
Frees the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for the object instance. Destroy frees and release resources allocated in Create for the QueryResult property. Destroy calls the inherited Destroy method prior to exiting.

TIdDNSResolver.Resolve
TIdDNSResolver, See Also
Performs a DNS query to resolve a domain name, and parses the response.
procedure Resolve(ADomain: string);
Parameters
ADomain: string
Domain Name to resolve using the DNS query.
Description
Resolve is a Procedure that implements the processing required to perform a DNS query for the requested resource record types, and handle the response from the DNS server.

ADomain is the domain name to be resolved in the DNS query using the values specified in AllowRecursiveQueries and QueryRecords. Update QueryRecords and AllowRecursiveQueries prior to calling the Resolve method.

Resolve creates a DNS query packet, including the DNS header, using the value specified in ADomain. Resolve can raise an EIdDnsResolverError exception if a valid DNS query cannot be created using the values in ADomain, AllowRecursiveQueries, and QueryRecords.

Resolve send the DNS query packet to the server, and reads the DNS response. Resolve handles parsing of values in the DNS response into the DNS header and QueryResult. Resolve can raise an EIdDnsResolverError if a timeout occurs, or an incomplete data packet is received, while waiting for a DNS server response.


Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.