Difference between revisions of "Unit DNS"

From Ultibo.org
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
'''Ultibo DNS client unit'''
+
'''Ultibo DNS Client unit'''
  
 
Note: DNS Client is IPv4 based, for IPv6 see new Winsock2 functions
 
Note: DNS Client is IPv4 based, for IPv6 see new Winsock2 functions
Line 20: Line 20:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>DNS_TIMEOUT = 5000;</code>
+
| <code>DNS_TIMEOUT = 2000;</code>
| We wait for 5 seconds for a DNS reply
+
| We wait for 2 seconds for a DNS reply
 
|-
 
|-
| <code>DNS_RETRIES = 4;</code>
+
| <code>DNS_RETRIES = 2;</code>
| Try the request 4 times
+
| Try the request 2 times
 
|-
 
|-
 
|colspan="2"|&nbsp;
 
|colspan="2"|&nbsp;
Line 77: Line 77:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''DNS field masks''' <code> DNS_OPCODE_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''DNS field mask''' <code> DNS_*_MASK </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 91: Line 91:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''DNS query code''' <code> DNS_QUERY* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''DNS opcode''' <code> DNS_OPCODE_* </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>DNS_QUERY = 0;</code>
+
| <code>DNS_OPCODE_QUERY = 0;</code>
 
| A standard query
 
| A standard query
 
|-
 
|-
| <code>DNS_INV_QUERY = 1;</code>
+
| <code>DNS_OPCODE_IQUERY = 1;</code>
 
| An inverse query
 
| An inverse query
 
|-
 
|-
| <code>DNS_COMP_QUERY_MULTI = 2;</code>
+
| <code>DNS_OPCODE_SERVER_STATUS = 2;</code>
| A completion query, multiple reply (Obsolete)
+
| &nbsp;
 
|-
 
|-
| <code>DNS_COMP_QUERY_SINGLE = 3;</code>
+
| <code>DNS_OPCODE_UNKNOWN = 3;</code>
| A completion query, single reply (Obsolete)
+
| &nbsp;
 +
|-
 +
| <code>DNS_OPCODE_NOTIFY = 4;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_OPCODE_UPDATE = 5;</code>
 +
| &nbsp;
 
|-
 
|-
 
|}
 
|}
Line 111: Line 117:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''DNS response code''' <code> DNS_NO_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''DNS response code''' <code> DNS_RESPONSE_* </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>DNS_NO_ERROR = 0;</code>
+
| <code>DNS_RESPONSE_NO_ERROR = 0;</code>
 
| style="width: 50%;"|&nbsp;
 
| style="width: 50%;"|&nbsp;
 
|-
 
|-
| <code>DNS_FORMAT_ERROR = 1;</code>
+
| <code>DNS_RESPONSE_FORMAT_ERROR = 1;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_SERVER_FAILURE = 2;</code>
+
| <code>DNS_RESPONSE_SERVER_FAILURE = 2;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_NAME_ERROR = 3;</code>
+
| <code>DNS_RESPONSE_NAME_ERROR = 3;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_NOT_IMPLEMENTED = 4;</code>
+
| <code>DNS_RESPONSE_NOT_IMPLEMENTED = 4;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_REFUSED = 5;</code>
+
| <code>DNS_RESPONSE_REFUSED = 5;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 141: Line 147:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>DNS_TYPE_A = 1;</code>
+
| <code>DNS_TYPE_A = $0001;</code>
 
| Host address resource record (RR)
 
| Host address resource record (RR)
 
|-
 
|-
| <code>DNS_TYPE_NS = 2;</code>
+
| <code>DNS_TYPE_NS = $0002;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MD = 3;</code>
+
| <code>DNS_TYPE_MD = $0003;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MF = 4;</code>
+
| <code>DNS_TYPE_MF = $0004;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_CNAME = 5;</code>
+
| <code>DNS_TYPE_CNAME = $0005;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_SOA = 6;</code>
+
| <code>DNS_TYPE_SOA = $0006;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MB = 7;</code>
+
| <code>DNS_TYPE_MB = $0007;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MG = 8;</code>
+
| <code>DNS_TYPE_MG = $0008;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MR = 9;</code>
+
| <code>DNS_TYPE_MR = $0009;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_RT_NULL = 10;</code>
+
| <code>DNS_TYPE_NULL = $000a;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_WKS = 11;</code>
+
| <code>DNS_TYPE_WKS = $000b;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_PTR = 12;</code>
+
| <code>DNS_TYPE_PTR = $000c;</code>
 
| A domain name ptr
 
| A domain name ptr
 
|-
 
|-
| <code>DNS_TYPE_HINFO = 13;</code>
+
| <code>DNS_TYPE_HINFO = $000d;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MINFO = 14;</code>
+
| <code>DNS_TYPE_MINFO = $000e;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_TYPE_MX = 15;</code>
+
| <code>DNS_TYPE_MX = $000f;</code>
 
| Mail exchange
 
| Mail exchange
 +
|-
 +
| <code>DNS_TYPE_TEXT = $0010;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_RP = $0011;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_AFSDB = $0012;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_X25 = $0013;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_ISDN = $0014;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_RT = $0015;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NSAP = $0016;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NSAPPTR = $0017;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_SIG = $0018;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_KEY = $0019;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_PX = $001a;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_GPOS = $001b;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_AAAA = $001c;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_LOC = $001d;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NXT = $001e;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_EID = $001f;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NIMLOC = $0020;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_SRV = $0021;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_ATMA = $0022;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NAPTR = $0023;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_KX = $0024;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_CERT = $0025;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_A6 = $0026;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_DNAME = $0027;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_SINK = $0028;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_OPT = $0029;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_DS = $002B;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_RRSIG = $002E;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NSEC = $002F;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_DNSKEY = $0030;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_DHCID = $0031;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_UINFO = $0064;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_UID = $0065;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_GID = $0066;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_UNSPEC = $0067;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_ADDRS = $00f8;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_TKEY = $00f9;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_TSIG = $00fa;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_IXFR = $00fb;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_AXFR = $00fc;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_MAILB = $00fd;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_MAILA = $00fe;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_ALL = $00ff;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_ANY = $00ff;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_WINS = $ff01;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_WINSR = $ff02;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_TYPE_NBSTAT = DNS_TYPE_WINSR;</code>
 +
| &nbsp;
 
|-
 
|-
 
|}
 
|}
Line 194: Line 341:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
| <code>DNS_CLASS_IN = 1;</code>
+
| <code>DNS_CLASS_INTERNET = $0001;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_CSNET = $0002;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_CHAOS = $0003;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_HESIOD = $0004;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_NONE = $00fe;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_ALL = $00ff;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_ANY = $00ff;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DNS_CLASS_IN = DNS_CLASS_INTERNET;</code>
 
| ARPA internet class
 
| ARPA internet class
 
|-
 
|-
| <code>DNS_CLASS_CS = 2;</code>
+
| <code>DNS_CLASS_CS = DNS_CLASS_CSNET;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>DNS_CLASS_WILD = 255;</code>
+
| <code>DNS_CLASS_WILD = DNS_CLASS_ANY;</code>
 
| Wildcard for several of the classifications
 
| Wildcard for several of the classifications
 
|-
 
|-
 
|}
 
|}
 
</div></div>
 
</div></div>
<br />  
+
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div style="font-size: 14px; padding-left: 12px;">'''DNS message compression''' <code> DNS_POINTER_* </code></div>
 
<div style="font-size: 14px; padding-left: 12px;">'''DNS message compression''' <code> DNS_POINTER_* </code></div>
Line 340: Line 508:
 
|-
 
|-
 
|}
 
|}
</div></div>
+
</div></div>
 +
 
 +
'''DNS client name'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
 +
<code>PDNSClientName = ^TDNSClientName;</code>
 +
 
 +
<code>TDNSClientName = array[0..MAX_NAME_SIZE - 1] of Char;</code>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| &nbsp;
 +
| style="width: 50%;"|&nbsp;
 +
|-
 +
|}
 +
</div></div> 
  
 
'''DNS client data'''
 
'''DNS client data'''
Line 358: Line 541:
 
| style="width: 50%;"|&nbsp;
 
| style="width: 50%;"|&nbsp;
 
|-
 
|-
| <code>HostEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code>
+
| <code>HostEntName:TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>HostAliasesPtr:PChar;</code>
+
| <code>HostAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar;</code>
| &nbsp;
+
| One extra for terminating null pointer
 
|-
 
|-
| <code>HostAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code>
+
| <code>HostAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>HostAddrListPtr:PChar;</code>
+
| <code>HostAddrListPtr:array[0..MAX_HOST_ALIASES] of PChar;</code>
| &nbsp;
+
| One extra for terminating null pointer
 
|-
 
|-
 
| <code>HostAddrList:array[0..MAX_HOST_ALIASES - 1] of TInAddr;</code>
 
| <code>HostAddrList:array[0..MAX_HOST_ALIASES - 1] of TInAddr;</code>
 +
| &nbsp;
 +
|-
 +
| <code>HostAddr6ListPtr:array[0..MAX_HOST_ALIASES] of PChar;</code>
 +
| One extra for terminating null pointer
 +
|-
 +
| <code>HostAddr6List:array[0..MAX_HOST_ALIASES - 1] of TIn6Addr;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 378: Line 567:
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>NetEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code>
+
| <code>NetEntName:TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>NetAliasesPtr:PChar;</code>
+
| <code>NetAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar;</code>
| &nbsp;
+
| One extra for terminating null pointer
 
|-
 
|-
| <code>NetAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code>
+
| <code>NetAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 392: Line 581:
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>ServEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code>
+
| <code>ServEntName:TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>ServAliasesPtr:PChar;</code>
+
| <code>ServAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar;</code>
| &nbsp;
+
| One extra for terminating null pointer
 
|-
 
|-
| <code>ServAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code>
+
| <code>ServAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>ServEntProto:array[0..MAX_NAME_SIZE - 1] of Char;</code>
+
| <code>ServEntProto:TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 409: Line 598:
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>ProtoEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code>
+
| <code>ProtoEntName:TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
| <code>ProtoAliasesPtr:PChar;</code>
+
| <code>ProtoAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar;</code>
| &nbsp;
+
| One extra for terminating null pointer
 
|-
 
|-
| <code>ProtoAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code>
+
| <code>ProtoAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;</code>
 
| &nbsp;
 
| &nbsp;
 
|-
 
|-
Line 426: Line 615:
  
  
'''DNS client'''
+
'''DNS specific classes'''
  
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;">
+
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 
+
<code> TDNSClient = class(TNetworkClient)</code>
+
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
+
{| class="wikitable" style="font-size: 14px; background: white;"
+
 
|-
 
|-
| <code>constructor Create(AProtocol:TNetworkProtocol);</code>
+
| [[TDNSClient|<code>TDNSClient = class(TNetworkClient)</code>]]
| style="width: 50%;"|&nbsp;
+
|-
+
| <code>destructor Destroy; override;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''private'''</div>
+
|-
+
| <code>FTlsIndex:LongWord;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetClientData:PDNSClientData;</code>
+
| &nbsp;
+
|-
+
| <code>function CreateClientData:Boolean;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function AddressEntryToHostEnt(AddressEntry:TIPAddressEntry; const AName:String; ACount:Integer):PHostEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function HostEntryToHostEnt(HostEntry:TIPHostEntry):PHostEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function NetworkEntryToNetEnt(NetworkEntry:TIPNetworkEntry):PNetEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function ServEntryToServEnt(ServEntry:TIPServEntry):PServEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function ProtoEntryToProtoEnt(ProtoEntry:TIPProtoEntry):PProtoEnt;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function InAddrToName(const AAddress:TInAddr):String;</code>
+
| &nbsp;
+
|-
+
| <code>function NameToInAddr(const AName:String):TInAddr;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function In6AddrToName(const AAddress:TIn6Addr):String;</code>
+
| &nbsp;
+
|-
+
| <code>function NameToIn6Addr(const AName:String):TIn6Addr;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetDNSMessageSize(AMessage:PDNSMessage):Integer;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetDNSNameSize(AMessage:PDNSMessage; AOffset:Word):Word;</code>
+
| &nbsp;
+
|-
+
| <code>function GetDNSQuestionSize(AMessage:PDNSMessage; AOffset:Word):Word;</code>
+
| &nbsp;
+
|-
+
| <code>function GetDNSResourceSize(AMessage:PDNSMessage; AOffset:Word):Word;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetDNSQuestionOffset(AMessage:PDNSMessage; ACount:Word):Word;</code>
+
| &nbsp;
+
|-
+
| <code>function GetDNSAnswerOffset(AMessage:PDNSMessage; ACount:Word):Word;</code>
+
| &nbsp;
+
|-
+
| <code>function GetDNSAuthorityOffset(AMessage:PDNSMessage; ACount:Word):Word;</code>
+
| &nbsp;
+
|-
+
| <code>function GetDNSAdditionalOffset(AMessage:PDNSMessage; ACount:Word):Word;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function CreateDNSQuery(AMessage:PDNSMessage; AIdentifier:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function CheckDNSResponse(AMessage:PDNSMessage; AIdentifier:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function HandleDNSResponse(AMessage:PDNSMessage; AIdentifier:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function SendDNSQuery(ASocket:TProtocolSocket; const AServer:TInAddr; AData:Pointer; ALength,AType,AClass,AIdentifier:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function RecvDNSResponse(ASocket:TProtocolSocket; AType,AClass,AIdentifier:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function InsertDNSName(AMessage:PDNSMessage; AOffset:Word; AName:Pointer; ALength:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function ExtractDNSName(AMessage:PDNSMessage; AOffset:Word; AName:Pointer; var ALength:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function ExtractDNSRData(AMessage:PDNSMessage; AOffset:Word; AData:Pointer; var ALength:Word; AType,AClass:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function InsertDNSQuestion(AMessage:PDNSMessage; ACount:Word; AData:Pointer; ALength,AType,AClass:Word):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function ExtractDNSAnswer(AMessage:PDNSMessage; ACount:Word; AName,AData:Pointer; var ANameLength,ADataLength,AType,AClass:Word; var ATtl:LongWord):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function ExtractDNSAuthority(AMessage:PDNSMessage; ACount:Word; AName,AData:Pointer; var ANameLength,ADataLength,AType,AClass:Word; var ATtl:LongWord):Boolean;</code>
+
| &nbsp;
+
|-
+
| <code>function ExtractDNSAdditional(AMessage:PDNSMessage; ACount:Word; AName,AData:Pointer; var ANameLength,ADataLength,AType,AClass:Word; var ATtl:LongWord):Boolean;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|<div style="font-family: monospace,courier;">'''public'''</div>
+
|-
+
| <code>function GetHostByAddr(AAddr:Pointer; ALength,AFamily:Integer):PHostEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function GetHostByName(AName:PChar):PHostEnt;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetHostName(AName:PChar; ALength:Integer):Integer;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetServByPort(APort:Integer; AProto:PChar):PServEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function GetServByName(AName,AProto:PChar):PServEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function GetProtoByNumber(AProto:Integer):PProtoEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function GetProtoByName(AName:PChar):PProtoEnt;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function GetNetByAddr(AAddr:Pointer; ALength,AStruct:Integer):PNetEnt;</code>
+
| &nbsp;
+
|-
+
| <code>function GetNetByName(AName:PChar):PNetEnt;</code>
+
| &nbsp;
+
|-
+
|colspan="2"|&nbsp;
+
|-
+
| <code>function StartClient:Boolean; override;</code>
+
| &nbsp;
+
|-
+
| <code>function StopClient:Boolean; override;</code>
+
| &nbsp;
+
 
|-
 
|-
 
|}
 
|}
</div></div>
 
 
<br />
 
<br />
  

Latest revision as of 02:24, 6 March 2025

Return to Unit Reference


Description


Ultibo DNS Client unit

Note: DNS Client is IPv4 based, for IPv6 see new Winsock2 functions

See RFC 1035 Section 4 for details

Constants



DNS specific constants DNS_*
DNS_TIMEOUT = 2000; We wait for 2 seconds for a DNS reply
DNS_RETRIES = 2; Try the request 2 times
 
DNS_HEADER_SIZE = 12; SizeOf(TDNSHeader);
 
DNS_QUESTION_SIZE = 4; SizeOf(TDNSQuestion);
DNS_RESOURCE_SIZE = 10; SizeOf(TDNSResource); Not including Record Data
 
MAX_DNS_NAME = 255;  
MAX_DNS_LABEL = 63;  
MAX_DNS_MESSAGE = 512; Maximum Size of DNS Message


DNS flag DNS_FLAG_*
DNS_FLAG_RESPONSE = $8000; query = 0, response = 1
DNS_FLAG_AUTHORITY = $0400; Authoritative answer
DNS_FLAG_TRUNCATED = $0200; Truncation, response was cut off at 512
DNS_FLAG_DO_RECURSE = $0100; Recursion desired
DNS_FLAG_CAN_RECURSE = $0080; Recursion available


DNS field mask DNS_*_MASK
DNS_OPCODE_MASK = $7800; Opcode
DNS_RESPONSE_MASK = $000F; Response code


DNS opcode DNS_OPCODE_*
DNS_OPCODE_QUERY = 0; A standard query
DNS_OPCODE_IQUERY = 1; An inverse query
DNS_OPCODE_SERVER_STATUS = 2;  
DNS_OPCODE_UNKNOWN = 3;  
DNS_OPCODE_NOTIFY = 4;  
DNS_OPCODE_UPDATE = 5;  


DNS response code DNS_RESPONSE_*
DNS_RESPONSE_NO_ERROR = 0;  
DNS_RESPONSE_FORMAT_ERROR = 1;  
DNS_RESPONSE_SERVER_FAILURE = 2;  
DNS_RESPONSE_NAME_ERROR = 3;  
DNS_RESPONSE_NOT_IMPLEMENTED = 4;  
DNS_RESPONSE_REFUSED = 5;  


DNS record type DNS_TYPE_*
DNS_TYPE_A = $0001; Host address resource record (RR)
DNS_TYPE_NS = $0002;  
DNS_TYPE_MD = $0003;  
DNS_TYPE_MF = $0004;  
DNS_TYPE_CNAME = $0005;  
DNS_TYPE_SOA = $0006;  
DNS_TYPE_MB = $0007;  
DNS_TYPE_MG = $0008;  
DNS_TYPE_MR = $0009;  
DNS_TYPE_NULL = $000a;  
DNS_TYPE_WKS = $000b;  
DNS_TYPE_PTR = $000c; A domain name ptr
DNS_TYPE_HINFO = $000d;  
DNS_TYPE_MINFO = $000e;  
DNS_TYPE_MX = $000f; Mail exchange
DNS_TYPE_TEXT = $0010;  
DNS_TYPE_RP = $0011;  
DNS_TYPE_AFSDB = $0012;  
DNS_TYPE_X25 = $0013;  
DNS_TYPE_ISDN = $0014;  
DNS_TYPE_RT = $0015;  
DNS_TYPE_NSAP = $0016;  
DNS_TYPE_NSAPPTR = $0017;  
DNS_TYPE_SIG = $0018;  
DNS_TYPE_KEY = $0019;  
DNS_TYPE_PX = $001a;  
DNS_TYPE_GPOS = $001b;  
DNS_TYPE_AAAA = $001c;  
DNS_TYPE_LOC = $001d;  
DNS_TYPE_NXT = $001e;  
DNS_TYPE_EID = $001f;  
DNS_TYPE_NIMLOC = $0020;  
DNS_TYPE_SRV = $0021;  
DNS_TYPE_ATMA = $0022;  
DNS_TYPE_NAPTR = $0023;  
DNS_TYPE_KX = $0024;  
DNS_TYPE_CERT = $0025;  
DNS_TYPE_A6 = $0026;  
DNS_TYPE_DNAME = $0027;  
DNS_TYPE_SINK = $0028;  
DNS_TYPE_OPT = $0029;  
DNS_TYPE_DS = $002B;  
DNS_TYPE_RRSIG = $002E;  
DNS_TYPE_NSEC = $002F;  
DNS_TYPE_DNSKEY = $0030;  
DNS_TYPE_DHCID = $0031;  
DNS_TYPE_UINFO = $0064;  
DNS_TYPE_UID = $0065;  
DNS_TYPE_GID = $0066;  
DNS_TYPE_UNSPEC = $0067;  
DNS_TYPE_ADDRS = $00f8;  
DNS_TYPE_TKEY = $00f9;  
DNS_TYPE_TSIG = $00fa;  
DNS_TYPE_IXFR = $00fb;  
DNS_TYPE_AXFR = $00fc;  
DNS_TYPE_MAILB = $00fd;  
DNS_TYPE_MAILA = $00fe;  
DNS_TYPE_ALL = $00ff;  
DNS_TYPE_ANY = $00ff;  
DNS_TYPE_WINS = $ff01;  
DNS_TYPE_WINSR = $ff02;  
DNS_TYPE_NBSTAT = DNS_TYPE_WINSR;  


DNS address class DNS_CLASS_*
DNS_CLASS_INTERNET = $0001;  
DNS_CLASS_CSNET = $0002;  
DNS_CLASS_CHAOS = $0003;  
DNS_CLASS_HESIOD = $0004;  
DNS_CLASS_NONE = $00fe;  
DNS_CLASS_ALL = $00ff;  
DNS_CLASS_ANY = $00ff;  
DNS_CLASS_IN = DNS_CLASS_INTERNET; ARPA internet class
DNS_CLASS_CS = DNS_CLASS_CSNET;  
DNS_CLASS_WILD = DNS_CLASS_ANY; Wildcard for several of the classifications


DNS message compression DNS_POINTER_*
DNS_POINTER_MASK = $C0; Mask to indicate pointer to previously used name


Type definitions



DNS specific types

PDNSHeader = ^TDNSHeader;

TDNSHeader = packed record

Note: All Network Order
Identifier:Word; unique identifier
Flags:Word; QD/Opcode/AA/TC/RD/RA/RCODE
QuestionCount:Word; question section, number of entries
AnswerCount:Word; answers, how many
AuthorityCount:Word; count of name server RRs
AdditionalCount:Word; number of "additional" records

DNS message

PDNSMessage = ^TDNSMessage;

TDNSMessage = packed record

DNS:TDNSHeader;  
Data:array[0..(MAX_DNS_MESSAGE - DNS_HEADER_SIZE) - 1] of Byte;  

DNS name

PDNSName = ^TDNSName;

TDNSName = array[0..MAX_DNS_NAME - 1] of Char;

   

DNS question

PDNSQuestion = ^TDNSQuestion;

TDNSQuestion = packed record

Note: All Network Order
Name:TDNSName; variable length question name
QuestionType:Word; question type (eg DNS_TYPE_A)
QuestionClass:Word; question class (eg DNS_CLASS_IN)

DNS resource

PDNSResource = ^TDNSResource;

TDNSResource = packed record

Note: All Network Order
Name:TDNSName; variable length resource name
RecordType:Word; resource record type (eg DNS_TYPE_A)
RecordClass:Word; resource record class (eg DNS_CLASS_IN)
Ttl:LongWord; time-to-live, changed to 32 bits
DataLength:Word; length of data field
RecordData:array[0..MAX_DNS_MESSAGE - 1] of Byte; data field

DNS client name

PDNSClientName = ^TDNSClientName;

TDNSClientName = array[0..MAX_NAME_SIZE - 1] of Char;

   

DNS client data

PDNSClientData = ^TDNSClientData;

TDNSClientData = record

Note: Used for TLS Data
Host Ent
HostEnt:THostEnt;  
HostEntName:TDNSClientName;  
HostAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar; One extra for terminating null pointer
HostAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;  
HostAddrListPtr:array[0..MAX_HOST_ALIASES] of PChar; One extra for terminating null pointer
HostAddrList:array[0..MAX_HOST_ALIASES - 1] of TInAddr;  
HostAddr6ListPtr:array[0..MAX_HOST_ALIASES] of PChar; One extra for terminating null pointer
HostAddr6List:array[0..MAX_HOST_ALIASES - 1] of TIn6Addr;  
Net Ent
NetEnt:TNetEnt;  
NetEntName:TDNSClientName;  
NetAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar; One extra for terminating null pointer
NetAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;  
Serv Ent
ServEnt:TServEnt;  
ServEntName:TDNSClientName;  
ServAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar; One extra for terminating null pointer
ServAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;  
ServEntProto:TDNSClientName;  
Proto Ent
ProtoEnt:TProtoEnt;  
ProtoEntName:TDNSClientName;  
ProtoAliasesPtr:array[0..MAX_NAME_ALIASES] of PChar; One extra for terminating null pointer
ProtoAliases:array[0..MAX_NAME_ALIASES - 1] of TDNSClientName;  


Class definitions



DNS specific classes

TDNSClient = class(TNetworkClient)


Public variables


None defined

Function declarations



Initialization functions

procedure DNSInit;
Description: To be documented
Note None documented


function DNSStart:LongWord;
Description: To be documented
Note None documented


function DNSStop:LongWord;
Description: To be documented
Note None documented


Return to Unit Reference