Table of Contents

Class RecordReader

Namespace
Ubiety.Dns.Core
Assembly
Ubiety.Dns.Core.dll

Provides utilities for reading DNS record data from a byte array.

public class RecordReader
Inheritance
RecordReader
Inherited Members

Constructors

RecordReader(byte[], int)

Provides utilities for reading DNS record data from a byte array.

public RecordReader(byte[] data, int position = 0)

Parameters

data byte[]
position int

Properties

Position

Gets or sets the current reading position within the byte array.

public int Position { get; set; }

Property Value

int

Remarks

The position represents the index in the byte array from which the next read operation will occur. Modifying this value directly affects subsequent read operations.

Methods

ReadByte()

Reads the next byte from the record.

public byte ReadByte()

Returns

byte

The next available byte of the record.

ReadBytes(int)

Reads a sequence of bytes from the record.

public byte[] ReadBytes(int length)

Parameters

length int

The number of bytes to read from the record.

Returns

byte[]

An array containing the bytes read from the record.

ReadChar()

Reads the next character from the record.

public char ReadChar()

Returns

char

The next available character of the record.

ReadDomainName()

Reads and returns the domain name from the current record.

public string ReadDomainName()

Returns

string

The domain name of the record.

Remarks

Compression pointers are followed iteratively and are bounded by Ubiety.Dns.Core.RecordReader.MaxCompressionJumps jumps and Ubiety.Dns.Core.RecordReader.MaxDomainNameLength octets, so a malformed or hostile response containing a pointer cycle terminates instead of looping. Reading stops early rather than throwing when either bound is reached.

ReadRecord(RecordType)

Reads a record of the specified type from the data.

public Record ReadRecord(RecordType type)

Parameters

type RecordType

The type of the record to be read.

Returns

Record

The record read from the data.

Remarks

Record types whose length is not implied by their own structure, currently only TXT, read nothing through this overload. Prefer ReadRecord(RecordType, int).

ReadRecord(RecordType, int)

Reads a record of the specified type from the data, bounded by the resource data length.

public Record ReadRecord(RecordType type, int length)

Parameters

type RecordType

The type of the record to be read.

length int

The length in octets of the resource data, from RDLENGTH.

Returns

Record

The record read from the data.

Remarks

A TXT record is a sequence of character-strings with no count of its own, so the only way to know where it ends is the resource record's length.

ReadString()

Reads a string from the record using its length, which is determined by reading a byte preceding the string data.

public string ReadString()

Returns

string

The string read from the record.

ReadUInt16()

Reads the next unsigned 16-bit integer from the record.

public ushort ReadUInt16()

Returns

ushort

The next available unsigned 16-bit integer of the record.

ReadUInt16(int)

Reads the next unsigned 16-bit integer from the record.

public ushort ReadUInt16(int offset)

Parameters

offset int

Offset to start reading from.

Returns

ushort

The next available unsigned 16-bit integer of the record from the offset.

ReadUInt32()

Reads the next unsigned 32-bit integer from the record.

public uint ReadUInt32()

Returns

uint

The next available unsigned 32-bit integer in the record.