Oberon || Library || Module Index || Search Engine || Definition || Module

Ulm's Oberon Library:


DNSHeaders - DNS header structure according to RFC 1035


CONST headerlen = 12;
TYPE Header = ARRAY headerlen OF CHAR;

CONST minval = 0; maxval = 65535; (* of header ID and record counts *)

CONST query = 0; CONST response = 1; TYPE QRValue = SHORTINT; (* query or response *)

CONST standardQuery = 0; CONST inverseQuery = 1; CONST serverStatusRequest = 2; CONST update = 5; (* RFC 2136 *) TYPE OpCode = SHORTINT; (* standardQuery .. *)

CONST noError = 0; CONST formatError = 1; CONST serverFailure = 2; CONST nameError = 3; CONST notImplemented = 4; CONST refused = 5; CONST yxDomain = 6; (* RFC 2136 *) CONST yxRrset = 7; (* RFC 2136 *) CONST notAuth = 8; (* RFC 2136 *) CONST notZone = 9; (* RFC 2136 *) TYPE ResponseCode = SHORTINT; (* noError .. *)

PROCEDURE Init(VAR header: Header);

PROCEDURE SetID(VAR header: Header; id: INTEGER); PROCEDURE GetID(header: Header) : INTEGER;

PROCEDURE SetQR(VAR header: Header; qr: QRValue); PROCEDURE GetQR(header: Header) : QRValue;

PROCEDURE SetOpCode(VAR header: Header; opcode: OpCode); PROCEDURE GetOpCode(header: Header) : OpCode;

PROCEDURE SetAAFlag(VAR header: Header; aa: BOOLEAN); PROCEDURE GetAAFlag(header: Header) : BOOLEAN;

PROCEDURE SetTCFlag(VAR header: Header; tc: BOOLEAN); PROCEDURE GetTCFlag(header: Header) : BOOLEAN;

PROCEDURE SetRDFlag(VAR header: Header; rd: BOOLEAN); PROCEDURE GetRDFlag(header: Header) : BOOLEAN;

PROCEDURE SetRAFlag(VAR header: Header; ra: BOOLEAN); PROCEDURE GetRAFlag(header: Header) : BOOLEAN;

PROCEDURE SetResponseCode(VAR header: Header; rc: ResponseCode); PROCEDURE GetResponseCode(header: Header) : ResponseCode;

PROCEDURE SetQDCount(VAR header: Header; qdcount: INTEGER); PROCEDURE GetQDCount(header: Header) : INTEGER;

PROCEDURE SetANCount(VAR header: Header; ancount: INTEGER); PROCEDURE GetANCount(header: Header) : INTEGER;

PROCEDURE SetNSCount(VAR header: Header; nscount: INTEGER); PROCEDURE GetNSCount(header: Header) : INTEGER;

PROCEDURE SetARCount(VAR header: Header; arcount: INTEGER); PROCEDURE GetARCount(header: Header) : INTEGER;


DNSHeaders supports DNS header structures according to RFC 1035, section 4.1.1. DNS headers are at the beginning of each DNS packet and consist of headerlen bytes.

Headers of type Header can be read or written directly from or to streams. However, to avoid alignment pitfalls, Streams.ReadPart and Streams.WritePart with an explicitly given length of headerlen are to be used instead of Streams.Read and Streams.Write.

Init initializes a header with default values (all zeroes).

SetID and GetID set or retrieve a 16 bit identifier that is used to match responses to outstanding queries.

SetQR and GetQR set or retrieve a value of type QRValue that specifies the message type. Possible values are query and response.

SetOpCode and GetOpCode set or retrieve the opcode of a query (of type OpCode). Possible values are standardQuery, inverseQuery, serverStatusRequest, and update (RFC 2136).

SetAAFlag and GetAAFlag set or retrieve a flag that is set to TRUE if a response comes from an authoritative source.

SetTCFlag and GetTCFlag set or retrieve a flag that tells whether a response packet was truncated or not.

SetRDFlag and GetRDFlag set or retrieve a flag for query packets that is to be set to TRUE if recursion is desired.

SetRAFlag and GetRAFlag set or retrieve a flag for response packets that tells whether recursive queries are supported or not.

SetResponseCode and GetResponseCode set or retrieve the response code of type ResponseCode. Possible values are noError, formatError, serverFailure, nameError, notImplemented, refused, and the response codes of extensions like that of RFC 2136.

The number of records in various sections can be set or retrieved using following procedures:

SetQDCount, GetQDCount
query records section
SetANCount, SetANCount
answer records section
SetNSCount, GetNSCount
authority records section
SetARCount, GetARCount
additional records section


construction and retrieval of DNS records.

Edited by: borchert, last change: 2004/03/10, revision: 1.1, converted to HTML: 2004/03/10

Oberon || Library || Module Index || Search Engine || Definition || Module