Difference between revisions of "Unit DNS"
From Ultibo.org
(10 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
---- | ---- | ||
− | '''Ultibo DNS | + | '''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 54: | Line 54: | ||
<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 flag | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS flag''' <code> DNS_FLAG_* </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 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 | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS field masks''' <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;" | ||
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 | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS query code''' <code> DNS_QUERY* </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 111: | Line 111: | ||
<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 | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS response code''' <code> DNS_NO_* </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 137: | Line 137: | ||
<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 record type | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS record type''' <code> DNS_TYPE_* </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 190: | Line 190: | ||
<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 address class | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS address class''' <code> DNS_CLASS_* </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 207: | Line 207: | ||
<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 | + | <div style="font-size: 14px; padding-left: 12px;">'''DNS message compression''' <code> DNS_POINTER_* </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 221: | Line 221: | ||
---- | ---- | ||
− | '' | + | |
+ | '''DNS specific types''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PDNSHeader = ^TDNSHeader;</code> | ||
+ | |||
+ | <code>TDNSHeader = packed record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|Note: All Network Order | ||
+ | |- | ||
+ | | <code>Identifier:Word;</code> | ||
+ | | unique identifier | ||
+ | |- | ||
+ | | <code>Flags:Word;</code> | ||
+ | | QD/Opcode/AA/TC/RD/RA/RCODE | ||
+ | |- | ||
+ | | <code>QuestionCount:Word;</code> | ||
+ | | question section, number of entries | ||
+ | |- | ||
+ | | <code>AnswerCount:Word;</code> | ||
+ | | answers, how many | ||
+ | |- | ||
+ | | <code>AuthorityCount:Word;</code> | ||
+ | | count of name server RRs | ||
+ | |- | ||
+ | | <code>AdditionalCount:Word;</code> | ||
+ | | number of "additional" records | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''DNS message''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PDNSMessage = ^TDNSMessage;</code> | ||
+ | |||
+ | <code>TDNSMessage = packed record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>DNS:TDNSHeader;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | | <code>Data:array[0..(MAX_DNS_MESSAGE - DNS_HEADER_SIZE) - 1] of Byte;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''DNS name''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PDNSName = ^TDNSName;</code> | ||
+ | |||
+ | <code>TDNSName = array[0..MAX_DNS_NAME - 1] of Char;</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''DNS question''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PDNSQuestion = ^TDNSQuestion;</code> | ||
+ | |||
+ | <code>TDNSQuestion = packed record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|Note: All Network Order | ||
+ | |- | ||
+ | | <code>Name:TDNSName;</code> | ||
+ | | variable length question name | ||
+ | |- | ||
+ | | <code>QuestionType:Word;</code> | ||
+ | | question type (eg DNS_TYPE_A) | ||
+ | |- | ||
+ | | <code>QuestionClass:Word;</code> | ||
+ | | question class (eg DNS_CLASS_IN) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''DNS resource''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PDNSResource = ^TDNSResource;</code> | ||
+ | |||
+ | <code>TDNSResource = packed record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|Note: All Network Order | ||
+ | |- | ||
+ | | <code>Name:TDNSName;</code> | ||
+ | | variable length resource name | ||
+ | |- | ||
+ | | <code>RecordType:Word;</code> | ||
+ | | resource record type (eg DNS_TYPE_A) | ||
+ | |- | ||
+ | | <code>RecordClass:Word;</code> | ||
+ | | resource record class (eg DNS_CLASS_IN) | ||
+ | |- | ||
+ | | <code>Ttl:LongWord;</code> | ||
+ | | time-to-live, changed to 32 bits | ||
+ | |- | ||
+ | | <code>DataLength:Word;</code> | ||
+ | | length of data field | ||
+ | |- | ||
+ | | <code>RecordData:array[0..MAX_DNS_MESSAGE - 1] of Byte;</code> | ||
+ | | data field | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''DNS client data''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PDNSClientData = ^TDNSClientData;</code> | ||
+ | |||
+ | <code>TDNSClientData = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|Note: Used for TLS Data | ||
+ | |- | ||
+ | |colspan="2"|''Host Ent'' | ||
+ | |- | ||
+ | | <code>HostEnt:THostEnt;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | | <code>HostEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>HostAliasesPtr:PChar;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>HostAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>HostAddrListPtr:PChar;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>HostAddrList:array[0..MAX_HOST_ALIASES - 1] of TInAddr;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Net Ent'' | ||
+ | |- | ||
+ | | <code>NetEnt:TNetEnt;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>NetEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>NetAliasesPtr:PChar;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>NetAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Serv Ent'' | ||
+ | |- | ||
+ | | <code>ServEnt:TServEnt;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ServEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ServAliasesPtr:PChar;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ServAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ServEntProto:array[0..MAX_NAME_SIZE - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Proto Ent'' | ||
+ | |- | ||
+ | | <code>ProtoEnt:TProtoEnt;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ProtoEntName:array[0..MAX_NAME_SIZE - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ProtoAliasesPtr:PChar;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ProtoAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | |||
+ | === Class definitions === | ||
+ | ---- | ||
+ | |||
+ | |||
+ | '''DNS specific classes''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | [[TDNSClient|<code>TDNSClient = class(TNetworkClient)</code>]] | ||
+ | |- | ||
+ | |} | ||
+ | <br /> | ||
=== Public variables === | === Public variables === | ||
---- | ---- | ||
− | '' | + | ''None defined'' |
=== Function declarations === | === Function declarations === | ||
Line 240: | Line 452: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 252: | Line 464: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- | ||
Line 264: | Line 476: | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Note |
| None documented | | None documented | ||
|- | |- |
Latest revision as of 05:21, 31 August 2021
Return to Unit Reference
Contents
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 = 5000;
|
We wait for 5 seconds for a DNS reply |
DNS_RETRIES = 4;
|
Try the request 4 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 masks
DNS_OPCODE_*
DNS_OPCODE_MASK = $7800;
|
Opcode |
DNS_RESPONSE_MASK = $000F;
|
Response code |
DNS query code
DNS_QUERY*
DNS_QUERY = 0;
|
A standard query |
DNS_INV_QUERY = 1;
|
An inverse query |
DNS_COMP_QUERY_MULTI = 2;
|
A completion query, multiple reply (Obsolete) |
DNS_COMP_QUERY_SINGLE = 3;
|
A completion query, single reply (Obsolete) |
DNS response code
DNS_NO_*
DNS_NO_ERROR = 0;
|
|
DNS_FORMAT_ERROR = 1;
|
|
DNS_SERVER_FAILURE = 2;
|
|
DNS_NAME_ERROR = 3;
|
|
DNS_NOT_IMPLEMENTED = 4;
|
|
DNS_REFUSED = 5;
|
DNS record type
DNS_TYPE_*
DNS_TYPE_A = 1;
|
Host address resource record (RR) |
DNS_TYPE_NS = 2;
|
|
DNS_TYPE_MD = 3;
|
|
DNS_TYPE_MF = 4;
|
|
DNS_TYPE_CNAME = 5;
|
|
DNS_TYPE_SOA = 6;
|
|
DNS_TYPE_MB = 7;
|
|
DNS_TYPE_MG = 8;
|
|
DNS_TYPE_MR = 9;
|
|
DNS_TYPE_RT_NULL = 10;
|
|
DNS_TYPE_WKS = 11;
|
|
DNS_TYPE_PTR = 12;
|
A domain name ptr |
DNS_TYPE_HINFO = 13;
|
|
DNS_TYPE_MINFO = 14;
|
|
DNS_TYPE_MX = 15;
|
Mail exchange |
DNS address class
DNS_CLASS_*
DNS_CLASS_IN = 1;
|
ARPA internet class |
DNS_CLASS_CS = 2;
|
|
DNS_CLASS_WILD = 255;
|
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 data
PDNSClientData = ^TDNSClientData;
TDNSClientData = record
Note: Used for TLS Data | |
Host Ent | |
HostEnt:THostEnt;
|
|
HostEntName:array[0..MAX_NAME_SIZE - 1] of Char;
|
|
HostAliasesPtr:PChar;
|
|
HostAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;
|
|
HostAddrListPtr:PChar;
|
|
HostAddrList:array[0..MAX_HOST_ALIASES - 1] of TInAddr;
|
|
Net Ent | |
NetEnt:TNetEnt;
|
|
NetEntName:array[0..MAX_NAME_SIZE - 1] of Char;
|
|
NetAliasesPtr:PChar;
|
|
NetAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;
|
|
Serv Ent | |
ServEnt:TServEnt;
|
|
ServEntName:array[0..MAX_NAME_SIZE - 1] of Char;
|
|
ServAliasesPtr:PChar;
|
|
ServAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;
|
|
ServEntProto:array[0..MAX_NAME_SIZE - 1] of Char;
|
|
Proto Ent | |
ProtoEnt:TProtoEnt;
|
|
ProtoEntName:array[0..MAX_NAME_SIZE - 1] of Char;
|
|
ProtoAliasesPtr:PChar;
|
|
ProtoAliases:array[0..(MAX_NAME_SIZE * MAX_NAME_ALIASES) - 1] of Char;
|
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