Zonema...Packet(3pm)
π Zonemaster::LDNS::Packet β objects representing DNS packets π
okay bestie. this is the page for Zonemaster::LDNS::Packet (the manpage is filed under the kinda-truncated name Zonema...Packet(3pm), don't let that jump you π). it's a Perl thing, it lives in the User Contributed Perl Documentation pile, and it's literally just... a DNS packet as an object. every record, every flag, every vibe. let's go π¦
β¨ SYNOPSIS β¨
look, here's the whole entire mood in five lines:
my $p = $resolver->query('www.iis.se');
foreach my $rr ($p->answer) {
say $rr->string if $rr->type eq 'A';
}
you ask, you get a packet, you loop the answers, you print the A records. that's it that's the whole lifestyle π
πΈ CLASS METHODS πΈ
these ones you call on the class itself. constructor core.
new($name, $type, $class)β makes you a fresh newZonemaster::LDNS::Packetobject, and ngl it holds nothing except a query record for the triplet you gave it. nothing else. it's a whole packet that's just a question, main character energy.$nameis the QNAME.$typeand$classare optional and default toAandINrespectively β so if you don't say anything it's anAINquestion, periodt.new_from_wireformat($data)β builds a newZonemaster::LDNS::Packetout of the wireformat data you hand it, if possible. if it's not possible? it throws an exception. no cap. π
π INSTANCE METHODS π
everything below you call on a packet object. buckle up, there's a lot, and honestly? obsessed.
π the rcode / opcode / id trio
rcode([$string])β gives you the packet RCODE. hand it an argument and it tries to set the RCODE to the relevant value. if the string you gave isn't recognized as an RCODE, an exception gets thrown at you. so be normal about it πopcode([$string])β gives you the packet OPCODE. hand it an argument and it tries to set the OPCODE to the relevant value. if the string isn't recognized as an OPCODE, exception. same energy, different field. β¨id([$value])β returns the packet id number. hand it an argument and it sets the ID value to that value. simple. iconic. no notes.
π the flags crew
qr()aa()tc()rd()cd()ra()ad()do()
all of these read and/or set the equivalently named flags. that's the whole bit β flag name in, flag name out. one bullet because they're a little squad π
π size & EDNS stuff
size()β returns the length of the packet's wireformat form, in octets. yes, octets. not vibes. octets. πedns_size()β gets and/or sets the EDNS0 UDP size.edns_rcode()β gets and/or sets the EDNS0 Extended RCODE field.ends_z()β gets and/or sets the EDNS0 Z bits. (yes, the method really is spelledends_z, we don't make the rules, we just respect them π«Ά)edns_data()β gets and/or sets the EDNS0 RDATA. for the actual details on this one you gotta go look atLDNS.xs, that's where the lore lives.needs_edns()β returns true if the packet has theDOflag set, an EDNS0 size set, and an EDNS0 extended RCODE set β or if the OPT pseudo-RR has one or more RDATA fields.
β οΈ heads up bestie, this can fail to correctly flag a packet with an OPT pseudo-RR as having EDNS if the pseudo-RR specifies a UDP size of zero, an extended RCODE of zero, and the DO flag is unset. and because any UDP size less than 512 has to be interpreted as 512, packets like that should be super rare in practice β like, if they exist at all. π
also, important: the OPT pseudo-RR is not visible as an RR in the packet, and it is not included in the RR count header fields. it's lowkey hiding in there.
has_edns()β an alias forneeds_edns(). same method, different name, we love a rebrand. β¨edns_version($version)β get or set the EDNS version in the packet. for incoming packets it returns0if the packet doesn't have an OPT pseudo-RR, and0if it is an EDNS0 packet. so it's, um. rather pointless until such time as EDNS1 actually gets defined. it's giving placeholder. πset_edns_presentβ sets theedns_presentflag to true.
you can set this flag when you're creating a packet with EDNS corner cases data that the need_edns / has_edns methods couldn't detect on their own.
when it's set, the need_edns / has_edns methods return a true value. slay.
unset_edns_presentβ sets theedns_presentflag to false. the off switch. π
π timing & where it came from
querytime([$value])β returns how long the query that this packet is the answer to took to execute, in milliseconds. hand it a value and it sets the querytime to that value.answerfrom($ipaddr)β returns and optionally sets the IP address the packet was received from. if you try to set it to a string that can't be parsed as an IPv4 or IPv6 address, an exception gets thrown. don't try it. πtimestamp($time)β the time when the query was sent or received (the ldns docs don't specify which, so πΆ). it's a floating-point value on the Unixtime_tscale β meaning the same kind of value thatTime::HiRes::time()uses.
β οΈ conversion effects between floating-point and struct timeval mean the precision of this value is probably not reliable at the microsecond level, even if your computer's clock happens to be. so like... don't build your whole personality on that microsecond. π
π grabbing all the records
all()β returns aZonemaster::LDNS::RRListobject containing the resource records from all sections except the question section. everything but the question. the whole buffet minus the appetizer.question()β returns a list of objects representing the RRs in the question section. they'll be of classes appropriate to their types, but all of them haveZonemaster::LDNS::RRas a base class. found family π«Άquestion_rrlist()β similar toquestion(), but instead returns a single (and sorted)Zonemaster::LDNS::RRListobject.answer()β similar toanswer_unfiltered(), but it ignores incomplete resource records. picky in a good way. πanswer_rrlist()β similar toanswer(), but instead returns a single (and sorted)Zonemaster::LDNS::RRListobject.answer_unfiltered()β returns a list of objects representing the RRs in the answer section. they'll be of classes appropriate to their types, but all haveZonemaster::LDNS::RRas a base class.authority()β similar toauthority_unfiltered(), but ignores incomplete resource records.authority_rrlist()β similar toauthority(), but instead returns a single (and sorted)Zonemaster::LDNS::RRListobject.authority_unfiltered()β returns a list of objects representing the RRs in the authority section. classes appropriate to their types, all withZonemaster::LDNS::RRas a base class.additional()β similar toadditional_unfiltered(), but ignores incomplete resource records.additional_rrlist()β similar toadditional(), but instead returns a single (and sorted)Zonemaster::LDNS::RRListobject.additional_unfiltered()β returns a list of objects representing the RRs in the additional section. classes appropriate to their types, all withZonemaster::LDNS::RRas a base class.
π‘ notice the pattern? every section has a plain getter, a_rrlistsorted-single-object version, and an_unfilteredversion that keeps the incomplete records. the filtered ones drop incomplete RRs. iykyk. β¨
π§Ί pushing stuff in & spitting stuff out
unique_push($section, $rr)β pushes an RR object into the given section, if an identical RR isn't already present. if the section isn't one of"question","answer","authority"or"additional", an exception gets thrown. and$rrmust be aZonemaster::LDNS::RRsubclass. no impostors allowed. πstring()β returns a string with the packet and its contents in common presentation format. the readable one. the pretty one. πwireformat()β returns a Perl string holding the packet in wire format. the feral one. the bytes. πtype()β returns the ldns library's guess as to the content of the packet. one of the strings"question","referral","answer","nxdomain","nodata"or"unknown". note it says guess, bestie, the library is doing its best π«Ά
and that's the entire page, no skips, no cuts π
this beauty is Zonema...Packet(3pm) from the User Contributed Perl Documentation, running under perl v5.42.3, dated 2026-08-19. go forth and parse your packets, you absolute icon πβ¨
π¦ where this page comes from
- ubuntu stonking: libzonemaster-ldns-perl 5.0.2+ds-2build1 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms