dnsjit.core.object.dns(3)
π dnsjit.core.object.dns β the manual page bestie π
okay so you're reading the dnsjit.core.object.dns page from the Library Functions Manual, and honestly? it's giving container-of-a-DNS-message energy and I am obsessed. let's get into it π¦
β¨ NAME β¨
dnsjit.core.object.dns β the container of a DNS message. that's it, that's the whole vibe π
πΈ SYNOPSIS πΈ
parse a DNS header and check if it's a query or a response
local dns = require("dnsjit.core.object.dns").new(payload)
if dns:parse_header() == 0 then
if dns.qr == 0 then
print(dns.id, dns.opcode_tostring(dns.opcode))
else
print(dns.id, dns.rcode_tostring(dns.rcode))
end
end
print a DNS payload
local dns = require("dnsjit.core.object.dns").new(payload)
dns:print()
parse a DNS payload
local dns = require("dnsjit.core.object.dns").new(payload)
local qs, q_labels, rrs, rr_labels = dns:parse()
if qs and q_labels then
...
if rrs and rr_labels then
...
end
end
π DESCRIPTION π
so this is the object that describes a DNS message. the main character, fr fr. π
π Attributes
includes_dnslenβ if this is non-zero, that means the DNS length is included in the payload (like, for example, when the transport is TCP) and it affects how the payload gets parsed. lowkey important.have_dnslenβ set when the dnslen was actually included in the payload and could be read.have_idβ set if there's a DNS ID.have_qrβ set if there's a QR flag.have_opcodeβ set if there's an OPCODE.have_aaβ set if there's an AA flag.have_tcβ set if there's a TC flag.have_rdβ set if there's a RD flag.have_raβ set if there's a RA flag.have_zβ set if there's a Z flag.have_adβ set if there's an AD flag.have_cdβ set if there's a CD flag.have_rcodeβ set if there's a RCODE.have_qdcountβ set if there's a QDCOUNT.have_ancountβ set if there's an ANCOUNT.have_nscountβ set if there's a NSCOUNT.have_arcountβ set if there's an ARCOUNT.dnslenβ the DNS length that was found in the payload.idβ the DNS ID.qrβ the QR flag.opcodeβ the OPCODE.aaβ the AA flag.tcβ the TC flag.rdβ the RD flag.raβ the RA flag.zβ the Z flag.adβ the AD flag.cdβ the CD flag.rcodeβ the RCODE.qdcountβ the QDCOUNT.ancountβ the ANCOUNT.nscountβ the NSCOUNT.arcountβ the ARCOUNT.
π§ Constants
these tables exist for DNS parameters, and they were taken from https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml on the 2016-12-09. periodt, that's the source date, no cap.
CLASS, CLASS_STR, TYPE, TYPE_STR, OPCODE, OPCODE_STR, RCODE, RCODE_STR, AFSDB, AFSDB_STR, DHCID, DHCID_STR, ENDS0, ENDS0_STR
the *_STR tables are the ones you use to turn numbers into their textual glow-up β¨ see also class_tostring(), type_tostring(), opcode_tostring(), rcode_tostring(), afsdb_tostring(), dhcid_tostring() and edns0_tostring().
π«Ά Functions
Dns.new(obj)β create a fresh new DNS object, optionally sitting on top of another object.Dns:type()β returns the textual type of the object.Dns:prev()β returns the previous object.Dns:cast()β casts the object to the underlining object module and hands it back to you.Dns:uncast()β casts the object to the generic object module and returns it.Dns:copy()β makes a copy of the object and returns it.Dns:free()β frees the object. only use this on copies or stuff that was otherwise allocated, bestie, I'm serious.Dns:reset()β resets the object, getting it all ready for reuse.Dns:log()β returns the Log object so you can control the logging of this module.Dns:parse_header()β starts parsing the underlaying object: first the header gets parsed, then you optionally keep callingparse_q()for however many questions there are (checkqdcount). after that you keep callingparse_rr()for the number of answers, authorities and additionals resource records (checkancount,nscountandarcount). returns0on success, or a negative integer on error β which can be malformed or truncated DNS (-2), or needing more space for labels (-3).Dns:parse_q(q, labels, num_labels)β parses the next resource record as a question. returns0on success, or a negative integer on error β malformed or truncated DNS (-2), or needing more space for labels (-3).Dns:parse_rr(rr, labels, num_labels)β parses the next resource record. returns0on success, or a negative integer on error β malformed or truncated DNS (-2), or needing more space for labels (-3).Dns:parse(num_labels)β starts parsing the underlaying object usingparse_header(),parse_q()andparse_rr(). the optionalnum_labelslets you set a specific number of labels used for each question and resource record (default is16). returns a result code, an array of questions, an array of question labels, an array of resource records, and an array of resource records labels. the result code is0on success, or a negative integer on error β malformed or truncated DNS (-2), or needing more space for labels (-3).Dns:print(num_labels)β starts parsing the underlaying object usingparse_header(),parse_q()andparse_rr(), and prints its content. the optionalnum_labelslets you set a specific number of labels used for each question and resource record (default is16).Dns.class_tostring(class)β returns the textual name for a class. unknown classes come back as"CLASS<NUM>", exactly as described in RFC 3597.Dns.type_tostring(type)β returns the textual name for a type. unknown types come back as"TYPE<NUM>", as described in RFC 3597.Dns.opcode_tostring(opcode)β returns the textual name for an opcode.Dns.rcode_tostring(rcode)β returns the textual name for a rcode.Dns.afsdb_tostring(afsdb)β returns the textual name for an afsdb subtype.Dns.dhcid_tostring(dhcid)β returns the textual name for a dhcid type.Dns.edns0_tostring(edns0)β returns the textual name for an EDNS0 OPT record.
π₯ SEE ALSO π₯
dnsjit.core.object(3), dnsjit.core.object.payload(3), dnsjit.core.object.dns.label(3), dnsjit.core.object.dns.q(3), dnsjit.core.object.dns.rr(3)
go read your siblings, they're iconic too π
π« AUTHORS and CONTRIBUTORS π«
Jerry LundstrΓΆm (DNS-OARC), TomΓ‘Ε‘ KΕΓΕΎek (CZ.NIC), Petr Ε paΔek (ISC)
maintained by DNS-OARC π«Ά
π BUGS π
for issues and feature requests please use:
https://codeberg.org/DNS-OARC/dnsjit/issues
for questions and help please use:
admin@dns-oarc.net
okay bestie that's the whole page, you ate it, no crumbs left π this was dnsjit 1.5.1, page dnsjit.core.object.dns(3), and yes it's the version from the Library Functions Manual β now go parse something and slay π
β¨π¦
π¦ where this page comes from
- epel 10: dnsjit 1.5.1-2.el10_2 Β· GPL-3.0-or-later
- epel 9: dnsjit 1.5.1-2.el9 Β· GPL-3.0-or-later
- fedora 43: dnsjit 1.5.1-2.fc43 Β· GPL-3.0-or-later
- fedora 43: dnsjit 1.5.1-2.fc43 Β· GPL-3.0-or-later
- fedora 44: dnsjit 1.5.1-2.fc44 Β· GPL-3.0-or-later
- fedora 44: dnsjit 1.5.1-2.fc44 Β· GPL-3.0-or-later
- ubuntu resolute: dnsjit 1.5.1-2 Β· GPL-3.0-or-later
- ubuntu stonking: dnsjit-dev 1.5.1-6 Β· GPL-3.0-or-later
- Copyright (c) 2018-2026 OARC, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms