hare

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

commit 5fa89b1c48e0e97d97c22fadf458ca6e6571fb46
parent 56c604898433990a606a415892c1718f19024649
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 22 Jun 2021 17:00:15 -0400

net::dns: add decode_mx

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mnet/dns/decode.ha | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/net/dns/decode.ha b/net/dns/decode.ha @@ -216,4 +216,15 @@ export fn decode_aaaa(rdata: []u8) (ip::addr6 | format) = { return ip; }; +// Decodes the rdata field of an MX (mail exchange) record, returning the +// priority and the name. See [[decode_name]] to decode the name. The return +// value is borrowed from the rdata buffer. +export fn decode_mx(rdata: []u8) ((u16, []u8) | format) = { + if (len(rdata) < 2) { + return format; + }; + let prio = endian::begetu16(rdata); + return (prio, rdata[2..]); +}; + // TODO: Expand breadth of supported rdata decoders