DNS::LDNS::Packet(3)

✨ NAME ✨

DNS::LDNS::Packet β€” a DNS packet. that's it, that's the whole thing, she's a packet bestie πŸ’–

and yeah she's living in section 3 of the User Contributed Perl Documentation, which is exactly where you'd expect a Perl module to be. iconic behaviour, no notes.


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's the whole vibe. read it like a menu, pick what you need, slay.

πŸ¦‹ the constructor & the basics

use DNS::LDNS ':all'

my pkt = new DNS::LDNS::Packet(name => rdata, type => LDNS_RR_TYPE_...,
  class => LDNS_RR_CLASS_..., flags => ...)
my pkt = new DNS::LDNS::Packet

pkt2 = pkt->clone

pkt->to_string

so you can build a packet with name, type, class and flags all at once, or just... make an empty one, no pressure. then clone her (twins!!), or to_string her and see what she's giving ✨

🌸 the four sections (+ extras)

rrlist = pkt->question
pkt->set_question(rrlist)
'
rrlist = pkt->answer
pkt->set_answer(rrlist)

rrlist = pkt->authority
pkt->set_authority(rrlist)

rrlist = pkt->additional
pkt->set_additional(rrlist)

rrlist = pkt->all
rrlist = pkt->all_noquestion

question, answer, authority, additional β€” the four main character sections 🫢 every one of them gets a getter and a setter, because balance. all grabs literally everything, and all_noquestion is the same but skips the question section, iykyk.

(yes, that lone ' up there is in the original. she's part of the family now. we don't question her πŸ™ˆ)

πŸ’… flags, ids & counts

for (qw/qr aa tc rd cd ra ad/) {
  bool = pkt->$_
  pkt->set_$_(bool)
}

id = pkt->id
pkt->set_id(id)
pkt->set_random_id

count = pkt->qdcount
count = pkt->ancount
count = pkt->nscount
count = pkt->arcount

opcode = pkt->opcode
pkt->set_opcode(opcode)

rcode = pkt->rcode                  # Response code
pkt->set_rcode(rcode)

size = pkt->size

epoch = pkt->querytime
pkt->set_querytime(epoch)

rdata = pkt->answerfrom
pkt->set_answerfrom(rdata)

(sec, usec) = pkt->timestamp
pkt->set_timestamp(sec, usec)

the whole flag squad β€” qr, aa, tc, rd, cd, ra, ad β€” loops through them and gives each one a getter and a setter, periodt. then you've got your id (set it yourself or let set_random_id pick for you, chaos queen 🌈), the four counts qdcount / ancount / nscount / arcount, opcode, rcode (the Response code, that's the comment's words not mine), size, querytime, answerfrom, and the timestamp which hands you back a (sec, usec) pair and takes them right back in set_timestamp. symmetric. we love her.

🧚 EDNS era

bool = pkt->edns

size = pkt->edns_udp_size
pkt->set_edns_udp_size(size)

rcode = pkt->edns_extended_rcode
pkt->set_edns_extended_rcode(rcode)

v = pkt->edns_version
pkt->set_edns_version(v)

z = pkt->edns_z
pkt->set_edns_z(z)

do = pkt->edns_do
pkt->set_edns_do(do)

rdata = pkt->edns_data
pkt->set_edns_data(rdata)

edns girlies rise 🧚 edns tells you if it's there, then it's the full roster: edns_udp_size, edns_extended_rcode, edns_version, edns_z, edns_do, and edns_data β€” every single one with its matching setter. no cap.

⭐ flags, rr wrangling & tsig

pkt->set_flags(flags)

rrlist = pkt->rr_list_by_name(rdata, section)
rrlist = pkt->rr_list_by_type(type, section)
rrlist = pkt->rr_list_by_name_and_type(rdata, type, section)

bool = pkt->rr(section, rr)       # Check if rr exists

pkt->push_rr(section, rr)
pkt->safe_push_rr(section, rr)

count = pkt->section_count(section)
bool = pkt->empty

rr = pkt->tsig
pkt->set_tsig(rr)

type = pkt->reply_type

rrlist = pkt->get_rrsigs_for_name_and_type(rdata, rrtype)
rrlist = pkt->get_rrsigs_for_type(rrtype)

set_flags for the bulk flag moment. then three ways to hunt down records: by rdata, by type, or both at once, each taking a section. rr checks if an rr exists (that's the comment's exact energy β€” "Check if rr exists" πŸ’€), push_rr and safe_push_rr shove one in, section_count counts a section, and empty tells you if the whole thing is giving nothing. then tsig + set_tsig, reply_type, and the two rrsig collectors β€” get_rrsigs_for_name_and_type (needs rdata and rrtype) and get_rrsigs_for_type (just rrtype). ate. πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

http://www.nlnetlabs.nl/projects/ldns

go, bestie, click it. the ldns girlies have so much lore over there πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Erik Pihl Ostlyngen, <erik.ostlyngen@uninett.no>

give her the credit she deserves 🫢


Copyright (C) 2013 by UNINETT Norid AS

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.

translation: free software, remix it, redistribute it, do your thing β€” same terms as Perl itself, Perl 5.14.2 or literally any later Perl 5 you've got lying around. open source royalty πŸ’–


and that's the page babes β€” this one's from perl v5.42.2, dated 2026-06-11, so it's fresh out the group chat. go build a packet, you're gonna slay πŸŽ€βœ¨

πŸ“¦ where this page comes from