Reference

std/dns/record

std/dns/src/record.trb

Record and RecordData: a resource record of RFC 1035 section 3.2.1 with its data typed by its type - addresses of std/ip, names as DomainNames, numbers as Ints - and Unknown for every type this package does not model.

type RecordData

type RecordData with Show, Equals, Hash

The data of a record, one case per type: the closed set of docs/design/DNS.md section 4. A number is an Int in the range its field has on the wire - 16 bits for a preference, a port, a priority and a weight, 32 bits for the numbers of an SOA record - and encoding refuses one outside it.

Examples

const mail = RecordData.Mx(10, DomainName.tryFrom("mail.example.test")?)
print mail

case A

case A(address: Ipv4Address)

An IPv4 address (RFC 1035 section 3.4.1).

case Aaaa

case Aaaa(address: Ipv6Address)

An IPv6 address (RFC 3596).

case Cname

case Cname(target: DomainName)

The canonical name the owner is an alias of (RFC 1035 section 3.3.1).

case Mx

case Mx(preference: Int, exchange: DomainName)

A mail exchange: the lower preference is tried first (RFC 1035 section 3.3.9).

case Txt

case Txt(strings: List<Bytes>)

Strings of up to 255 bytes each, in order; a long text is split across several (RFC 1035 section 3.3.14).

case Srv

case Srv(priority: Int, weight: Int, port: Int, target: DomainName)

The location of a service (RFC 2782): the lowest priority first, and among equal priorities a choice weighted by weight. A target of . says the service is not offered.

case Ns

case Ns(server: DomainName)

An authoritative name server of the owner's zone (RFC 1035 section 3.3.11).

case Soa

case Soa(primaryServer: DomainName, responsibleMailbox: DomainName, serial: Int, refresh: Int, retry: Int, expire: Int, minimum: Int)

The start of a zone (RFC 1035 section 3.3.13): its primary server, the mailbox of the person responsible written as a name, the serial of the zone, the three intervals in seconds that secondaries follow, and minimum, the time to live of a negative answer (RFC 2308 section 4).

case Ptr

case Ptr(target: DomainName)

A pointer to another name: the answer of a reverse lookup (RFC 1035 section 3.3.12).

case Caa

case Caa(flags: Int, tag: String, value: Bytes)

Which certification authority may issue for the owner (RFC 8659): flags with 128 for "critical", a tag of ASCII letters and digits (issue, issuewild, iodef) and its value.

case Svcb

case Svcb(priority: Int, target: DomainName, parameters: List<ServiceParameter>)

A service binding (RFC 9460): priority 0 is the alias form, whose target names where to look instead; any other priority is a service at target - . for the owner itself - with its parameters, in the order of their keys.

case Https

case Https(priority: Int, target: DomainName, parameters: List<ServiceParameter>)

The service binding for HTTPS (RFC 9460 section 9): the same data as Svcb, for the https scheme.

case Unknown

case Unknown(recordType: RecordType, data: Bytes)

The data of any other type, as the bytes it is on the wire (RFC 3597).

fn recordType

fn recordType(): RecordType

The type of a record with this data.

fn address

fn address(): IpAddress?

The address of an A or an AAAA record, and None for every other type.

fn show

fn show(): String

The data in the presentation format of a zone file: 93.184.216.34, 10 mail.example.test., "v=spf1 -all", 1 . alpn="h2,h3", and \# 4 0a000001 for an unknown type (RFC 3597 section 5).

type ServiceParameter

type ServiceParameter with Show, Equals, Hash

One parameter of a service binding (RFC 9460 section 7, and section 14.3's registry): the keys RFC 9460 defines, typed, and Other for every other key with its value as bytes.

case Mandatory

case Mandatory(keys: List<Int>)

mandatory, key 0: the keys a client has to understand to use the record.

case Alpn

case Alpn(protocols: List<String>)

alpn, key 1: the protocols of RFC 7301 the service speaks, h2 and h3. An identifier that is not UTF-8 keeps the whole parameter as Other(1, ...), so decoding loses nothing.

case NoDefaultAlpn

case NoDefaultAlpn

no-default-alpn, key 2: the protocol of the scheme is not offered unless Alpn names it.

case Port

case Port(port: Int)

port, key 3: the port of the service.

case Ipv4Hint

case Ipv4Hint(addresses: List<Ipv4Address>)

ipv4hint, key 4: addresses a client may use before it has resolved the target.

case EncryptedClientHello

case EncryptedClientHello(configurations: Bytes)

ech, key 5: an ECHConfigList for encrypted client hello, as its bytes.

case Ipv6Hint

case Ipv6Hint(addresses: List<Ipv6Address>)

ipv6hint, key 6: addresses a client may use before it has resolved the target.

case Other

case Other(key: Int, value: Bytes)

Any other key, from 0 to 65535, with its value as the bytes it is on the wire.

fn key

fn key(): Int

The key on the wire.

fn show

fn show(): String

The presentation format of RFC 9460 section 2.1: alpn="h2,h3", port=443, key65000="...".

type Record

type Record with Show, Equals, Hash

A resource record: the name it belongs to, its class, how many seconds it may be cached, and its data, whose case says the type.

Examples

const name = DomainName.tryFrom("example.test")?
print Record(name, timeToLive: 300, data: RecordData.A(Ipv4Address.of(192, 0, 2, 1)))

field name

name: DomainName

The owner: the name the record belongs to.

field recordClass

recordClass: RecordClass = RecordClass.Internet

Internet everywhere but in a Chaosnet query.

field timeToLive

timeToLive: Int

How long the record may be cached, in seconds, from 0 to 4294967295 (RFC 2181 section 8).

field data

data: RecordData

The data, whose case says the type.

fn recordType

fn recordType(): RecordType

The type of the record: the case of its data.

fn show

fn show(): String

A line of a zone file: example.test. 300 IN A 192.0.2.1.