Zonemaster::LDNS::Packet(3p)

NAME
Zonemaster::LDNS::Packet - objects representing DNS packets

SYNOPSIS
    my $p = $resolver->query('www.iis.se');
    foreach my $rr ($p->answer) {
        say $rr->string if $rr->type eq 'A';
    }

CLASS METHODS

new($name, $type, $class)
    Creates a new Zonemaster::LDNS::Packet object, holding nothing but a query record for the provided triplet. $name corresponds to the QNAME. $type and $class are optional, and default to A and IN respectively.

new_from_wireformat($data)
    Creates a new Zonemaster::LDNS::Packet object from the given wireformat data, if possible. Throws an exception if not.

INSTANCE METHODS

rcode([$string])
    Returns the packet RCODE. If given an argument, tries to set the RCODE to the relevant value. If the given string isn't recognized as an RCODE, an exception will be thrown.

opcode([$string])
    Returns the packet OPCODE. If given an argument, tries to set the OPCODE to the relevant value. If the given string isn't recognized as an OPCODE, an exception will be thrown.

id([$value])
    Returns the packet id number. If given an argument, sets the ID value to that value.

qr()
aa()
tc()
rd()
cd()
ra()
ad()
do()
    Reads and/or sets the equivalently named flags.

size()
    Returns the length of the packet's wireformat form in octets.

edns_size()
    Gets and/or sets the EDNS0 UDP size.

edns_rcode()
    Gets and/or sets the EDNS0 Extended RCODE field.

edns_z()
    Gets and/or sets the EDNS0 Z bits.

edns_data()
    Gets and/or sets the EDNS0 RDATA. See LDNS.xs for more details.

needs_edns()
    This method returns true if the packet has the DO flag set, an EDNS0 size set, and EDNS0 extended RCODE set or if the OPT pseudo-RR has one or more RDATA fields. It can fail to correctly flag a packet with an OPT pseudo-RR as having EDNS, if the pseudo-RR specifies an UDP size of zero, an extended RCODE of zero and the DO flag is unset. Since any UDP size less than 512 must be interpreted as 512, packets like that should be very rare in practice if they exist at all.

    Note that the OPT pseudo-RR is not visible as an RR in the packet, nor is it included in the RR count header fields.

has_edns()
    An alias for needs_edns().

edns_version($version)
    Get or set the EDNS version in the packet. For incoming packets, returns 0 if the packet does not have an OPT pseudo-RR and 0 if it's an EDNS0 packet. It's thus rather pointless until such time as EDNS1 is defined.

set_edns_present
    Set edns_present flag to true.

    This flag can be set when creating a packet with EDNS corner cases data that could not be detected by need_edns/has_edns methods.

    When set, need_edns/has_edns methods return true value.

unset_edns_present
    Set edns_present flag to false.

querytime([$value])
    Returns the time the query this packet is the answer to took to execute, in milliseconds. If given a value, sets the querytime to that value.

answerfrom($ipaddr)
    Returns and optionally sets the IP address the packet was received from. If an attempt is made to set it to a string that cannot be parsed as an IPv4 or IPv6 address, an exception is thrown.

timestamp($time)
    The time when the query was sent or received (the ldns docs don't specify), as a floating-point value on the Unix time_t scale (that is, the same kind of value used by Time::HiRes::time()). Conversion effects between floating-point and "struct timeval" means that the precision of the value is probably not reliable at the microsecond level, even if you computer's clock happen to be.

all()
    Returns a Zonemaster::LDNS::RRList object, containing the resource records from all sections except for the question section.

question()
    Returns a list of objects representing the RRs in the question section. They will be of classes appropriate to their types, but all will have Zonemaster::LDNS::RR as a base class.

question_rrlist()
    Similar to question(), but instead returns a single (and sorted) Zonemaster::LDNS::RRList object.

answer()
    Similar to answer_unfiltered(), but ignores incomplete resource records.

answer_rrlist()
    Similar to answer(), but instead returns a single (and sorted) Zonemaster::LDNS::RRList object.

answer_unfiltered()
    Returns a list of objects representing the RRs in the answer section. They will be of classes appropriate to their types, but all will have Zonemaster::LDNS::RR as a base class.

authority()
    Similar to authority_unfiltered(), but ignores incomplete resource records.

authority_rrlist()
    Similar to authority(), but instead returns a single (and sorted) Zonemaster::LDNS::RRList object.

authority_unfiltered()
    Returns a list of objects representing the RRs in the authority section. They will be of classes appropriate to their types, but all will have Zonemaster::LDNS::RR as a base class.

additional()
    Similar to additional_unfiltered(), but ignores incomplete resource records.

additional_rrlist()
    Similar to additional(), but instead returns a single (and sorted) Zonemaster::LDNS::RRList object.

additional_unfiltered()
    Returns a list of objects representing the RRs in the additional section. They will be of classes appropriate to their types, but all will have Zonemaster::LDNS::RR as a base class.

unique_push($section, $rr)
    Push 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 will be thrown. $rr must be a Zonemaster::LDNS::RR subclass.

string()
    Returns a string with the packet and its contents in common presentation format.

wireformat()
    Returns a Perl string holding the packet in wire format.

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".

first_ede( [ $error_code, [ $extra_text ] ] )
    Gets (if called without any arguments) or sets (if called with one or two arguments) the first Extended DNS Error (EDE) in the packet.

    As a setter, always returns "undef".

    As a getter, the return value depends on the context.

    In scalar context, returns the value of the EDE INFO-CODE field, or "undef" if the packet contains no EDE.

    In list context, returns:

    •   an empty list if there is no EDE;

    •   a list of one item, the EDE INFO-CODE, if there is an EDE without EXTRA-TEXT;

    •   a list of two items, the EDE INFO-CODE and the EXTRA-TEXT, if there is an EDE with EXTRA-TEXT.

    This list can be unpacked into a pair of variables, like this:

        my ( $code, $extra_text ) = $packet->first_ede();

    The EDE EXTRA-TEXT is specified in RFC 8914 to be UTF-8 encoded text. When retrieving the EXTRA-TEXT from a packet, UTF-8 valid text is returned as a Unicode character string, and UTF-8 invalid text, although forbidden, is returned as a (binary) byte string. Trailing NUL bytes are preserved both when setting the EXTRA-TEXT in a packet or when getting a packet’s EXTRA-TEXT.