dns.message — Lilush API

←index

← dns

Overview

Full DNS message encode and decode. Handles headers, question sections, resource records with RDATA codec dispatch, and EDNS OPT pseudo-record extraction/injection.

Functions

NameSignature
decode_headerdecode_header(r) -> hdr, err
encode_headerencode_header(w, hdr, qdcount, ancount, nscount, arcount)
decode_questiondecode_question(r) -> q, err
encode_questionencode_question(w, q)
decode_rrdecode_rr(r) -> rr, err
encode_rrencode_rr(w, rr)
extract_ednsextract_edns(additional) -> edns, filtered
build_opt_rrbuild_opt_rr(edns) -> rr
decodedecode(raw_bytes) -> msg, err
encodeencode(msg) -> raw_bytes

decode_header(r) -> hdr, err

Decode the 12-byte DNS header from a reader

encode_header(w, hdr, qdcount, ancount, nscount, arcount)

Encode a DNS header into a writer

decode_question(r) -> q, err

Decode a single question entry

encode_question(w, q)

Encode a single question entry

decode_rr(r) -> rr, err

Decode a single resource record

encode_rr(w, rr)

Encode a single resource record

extract_edns(additional) -> edns, filtered

Extract OPT pseudo-record from additional section into edns table

build_opt_rr(edns) -> rr

Build OPT pseudo-record RR from edns table

decode(raw_bytes) -> msg, err

Decode a raw DNS message into a structured table

Decodes a complete DNS message from a raw binary string. Returns a table with header, question, answer, authority, additional, and optionally edns fields. The OPT pseudo-record is extracted from the additional section into msg.edns.

Section counts from the header determine how many entries are parsed in each section. If any entry fails to parse, the entire decode fails with an error (strict mode).

encode(msg) -> raw_bytes

Encode a structured message table into raw DNS wire format

Encodes a complete DNS message from a structured table. Section counts are computed from the array lengths. If msg.edns is set, an OPT pseudo-record is appended to the additional section.