hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3fbc8c57af743be541b7d872eef000c16bdd419e
parent fc56d11a80c5f672c1780d72e43d2d479ab192a3
Author: Conrad Hoffmann <ch@bitfehler.net>
Date:   Tue, 13 Jun 2023 21:55:17 +0200

net::dns: add support for PTR records

Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>

Diffstat:
Mnet/dns/decode.ha | 8++++++++
Mnet/dns/types.ha | 9++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/net/dns/decode.ha b/net/dns/decode.ha @@ -201,6 +201,8 @@ fn decode_rdata(dec: *decoder, rtype: rtype, rlen: size) (rdata | format) = { return decode_mx(&sub); case rtype::NS => return decode_ns(&sub); + case rtype::PTR => + return decode_ptr(&sub); case rtype::SOA => return decode_soa(&sub); case rtype::SRV => @@ -278,6 +280,12 @@ fn decode_ns(dec: *decoder) (rdata | format) = { }; }; +fn decode_ptr(dec: *decoder) (rdata | format) = { + return ptr { + name = decode_name(dec)?, + }; +}; + fn decode_soa(dec: *decoder) (rdata | format) = { return soa { mname = decode_name(dec)?, diff --git a/net/dns/types.ha b/net/dns/types.ha @@ -158,6 +158,11 @@ export type ns = struct { name: []str, }; +// A PTR record. +export type ptr = struct { + name: []str, +}; + // An SOA record. export type soa = struct { mname: []str, @@ -183,7 +188,7 @@ export type txt = [][]u8; export type unknown_rdata = []u8; // Tagged union of supported rdata types. -export type rdata = (a | aaaa | caa | cname | mx | ns | soa | srv | txt | unknown_rdata); +export type rdata = (a | aaaa | caa | cname | mx | ns | ptr | soa | srv | txt | unknown_rdata); // A DNS message, Hare representation. See [[encode]] and [[decode]] for the DNS // representation. @@ -235,6 +240,8 @@ fn rrecord_finish(rr: *rrecord) void = { strings::freeall(mx.name); case let ns: ns => strings::freeall(ns.name); + case let ptr: ptr => + strings::freeall(ptr.name); case let so: soa => strings::freeall(so.mname); strings::freeall(so.rname);