DIRECTORY
ArpaBuf USING [Hdr],
ArpaUDPBuf USING [Hdr, maxBodyBytes],
Basics USING [FWORD, HWORD],
CommBuffer
USING [Overhead];
ArpaNameBuf:
CEDAR
DEFINITIONS =
BEGIN
HWORD: TYPE ~ Basics.HWORD;
FWORD: TYPE ~ Basics.FWORD;
Type:
TYPE =
MACHINE
DEPENDENT {
query(0),
response(1)};
Opcode:
TYPE =
MACHINE
DEPENDENT {
query(0),
iquery(1), -- inverse query (obsolete)
cquerym(2), -- completion query - multiple (obsolete)
cqueryu(3), -- completion query - unique (obsolete)
spare(15)};
ResponseCode:
TYPE =
MACHINE
DEPENDENT {
ok(0), -- no errors
format(1), -- format error
serverFailed(2), -- server failure
nameError(3), -- no such name exists
notImplemented(4), -- name server doesn't support query type
refused(5), -- name server refused operation
spare(15)};
Header
Port: TYPE ~ Basics.HWORD;
nullPort: Port ~ [0, 0];
domainPort: Port = [0, 53];
Hdr:
TYPE =
MACHINE
DEPENDENT
RECORD [
Defaults optimized for querys
id (0): CARD16, -- packet id
qr(1: 0..0): Type ← query, -- packet type
opcode (1: 1..4): Opcode ← query, -- operation
authoritative (1: 5..5): BOOL ← FALSE, -- authority asserted for answer resource records
truncated (1: 6..6): BOOL ← FALSE, -- packet truncated ( > 512 byte datagram)
recurDesired (1: 7..7): BOOL ← FALSE, -- recursion desired
recurAvail (1: 8..8): BOOL ← FALSE, -- recursion available
spare (1: 9..11): BOOL,
rcode (1: 12..15): ResponseCode ← ok, -- response code
qdCount(2): CARD16 ← 0, -- query record count
anCount(3): CARD16 ← 0, -- answer record count
nsCount(4): CARD16 ← 0, -- name server record count
arCount(5): CARD16 ← 0]; -- additional record count
hdrBytes: CARDINAL ~ BYTES[Hdr];
maxBytes: CARDINAL ~ ArpaUDPBuf.maxBodyBytes;
Body
Body:
TYPE ~
MACHINE
DEPENDENT
RECORD [
SELECT
OVERLAID *
FROM
bytes => [bytes: PACKED ARRAY [0..maxBodyBytes) OF BYTE],
chars => [chars: PACKED ARRAY [0..maxBodyChars) OF CHAR],
hWords => [hWords: PACKED ARRAY [0..maxBodyHWords) OF HWORD],
fWords => [fWords: PACKED ARRAY [0..maxBodyFWords) OF FWORD]
ENDCASE
];
maxBodyBytes: CARDINAL ~ maxBytes - hdrBytes;
maxBodyChars: CARDINAL ~ maxBodyBytes;
maxBodyHWords: CARDINAL ~ maxBodyBytes/BYTES[HWORD];
maxBodyFWords: CARDINAL ~ maxBodyBytes/BYTES[FWORD];
Packet
Packet: TYPE ~ REF PacketObject;
PacketObject:
TYPE ~
MACHINE
DEPENDENT
RECORD [
hdr: Hdr,
body: Body];
Buffer
All buffers start out as Driver.Buffer's. Clients may SmashType between Driver.Buffer and ArpaNameUDPBuf.Buffer, so the "right" module gets to do finalization. This is VERY delicate.
Buffer: TYPE ~ REF BufferObject;
BufferObject:
TYPE ~
MACHINE
DEPENDENT
RECORD [
ovh: CommBuffer.Overhead,
hdr1: ArpaBuf.Hdr,
hdr2: ArpaUDPBuf.Hdr,
hdr3: Hdr,
body: Body];
END.