commit c2f6ac88a7e113bed7c260c4286453936148fd1e
parent 263ea738f5af7f3f933654a0c54895eb77e74c9a
Author: Conrad Hoffmann <ch@bitfehler.net>
Date: Mon, 7 Aug 2023 16:37:43 +0200
net::dns: write label terminator in encode_labels
The zero-termination currently happening at the call sites of
`encode_labels()` is part of the name (i.e. list of labels), so move it
into the function.
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
Diffstat:
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/dns/encode.ha b/net/dns/encode.ha
@@ -80,18 +80,17 @@ fn encode_labels(enc: *encoder, names: []str) (void | error) = {
let label = fmt::bsprintf(enc.buf[enc.offs..], "{}", names[i]);
enc.offs += len(label);
};
+ encode_u8(enc, 0)?;
};
fn question_encode(enc: *encoder, q: *question) (void | error) = {
encode_labels(enc, q.qname)?;
- encode_u8(enc, 0)?;
encode_u16(enc, q.qtype)?;
encode_u16(enc, q.qclass)?;
};
fn rrecord_encode(enc: *encoder, r: *rrecord) (void | error) = {
encode_labels(enc, r.name)?;
- encode_u8(enc, 0)?;
encode_u16(enc, r.rtype)?;
encode_u16(enc, r.class)?;
encode_u32(enc, r.ttl)?;