File Coverage

blib/lib/Zonemaster/LDNS/Packet.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 3 4 75.0
pod 0 2 0.0
total 11 16 68.7


line stmt bran cond sub pod time code
1             package Zonemaster::LDNS::Packet;
2              
3 13     13   73 use Zonemaster::LDNS;
  13         25  
  13         565  
4              
5 13     13   2850 use MIME::Base64;
  13         6805  
  13         1673  
6              
7             sub TO_JSON {
8 2     2 0 2992 my ( $self ) = @_;
9              
10             return {
11 2         92 'Zonemaster::LDNS::Packet' => {
12             data => encode_base64( $self->wireformat, '' ),
13             answerfrom => $self->answerfrom,
14             timestamp => $self->timestamp,
15             querytime => $self->querytime,
16             }
17             };
18             }
19              
20             sub data {
21 0     0 0   my ( $self ) = @_;
22              
23 0           return $self->wireformat;
24             }
25              
26             1;
27              
28             =head1 NAME
29              
30             Zonemaster::LDNS::Packet - objects representing DNS packets
31              
32             =head1 SYNOPSIS
33              
34             my $p = $resolver->query('www.iis.se');
35             foreach my $rr ($p->answer) {
36             say $rr->string if $rr->type eq 'A';
37             }
38              
39             =head1 CLASS METHODS
40              
41             =over
42              
43             =item new($name, $type, $class)
44              
45             Create a new packet, holding nothing by a query record for the provided triplet. C<$type> and C<$class> are optional, and default to A and IN
46             respectively.
47              
48             =item new_from_wireformat($data)
49              
50             Creates a new L object from the given wireformat data, if possible. Throws an exception if not.
51              
52             =back
53              
54             =head1 INSTANCE METHODS
55              
56             =over
57              
58             =item rcode([$string])
59              
60             Returns the packet RCODE. If given an argument, tries to set the RCODE to the
61             relevant value. If the given string isn't recognized as an RCODE, an exception
62             will be thrown.
63              
64             =item opcode([$string])
65              
66             Returns the packet OPCODE. If given an argument, tries to set the OPCODE to the
67             relevant value. If the given string isn't recognized as an OPCODE, an exception
68             will be thrown.
69              
70             =item id([$value])
71              
72             Returns the packet id number. If given an argument, sets the ID value to that
73             value.
74              
75             =item qr()
76              
77             =item aa()
78              
79             =item tc()
80              
81             =item rd()
82              
83             =item cd()
84              
85             =item ra()
86              
87             =item ad()
88              
89             =item do()
90              
91             Reads and/or sets the equivalently named flags.
92              
93             =item size()
94              
95             Returns the length of the packet's wireformat form in octets.
96              
97             =item edns_size()
98              
99             Gets and/or sets the EDNS0 UDP size.
100              
101             =item edns_rcode()
102              
103             Gets and/or sets the EDNS0 Extended RCODE field.
104              
105             =item needs_edns()
106              
107             This method returns true if the packet has the DO flag set, an EDNS0 size set,
108             and EDNS0 extended RCODE set or if the OPT pseudo-RR has one or more RDATA
109             fields. It can fail to correctly flag a packet with an OPT pseudo-RR as having
110             EDNS, if the pseudo-RR specifies an UDP size of zero, an extended RCODE of zero
111             and the DO flag is unset. Since any UDP size less than 512 must be interpreted
112             as 512, packets like that should be very rare in practice if they exist at all.
113              
114             Note that the OPT pseudo-RR is not visible as an RR in the packet, nor is it
115             included in the RR count header fields.
116              
117             =item has_edns()
118              
119             An alias for needs_edns().
120              
121             =item edns_version($version)
122              
123             Get or set the EDNS version in the packet. For incoming packets, returns 0 if
124             the packet does not have an OPT pseudo-RR and 0 if it's an EDNS0 packet. It's
125             thus rather pointless until such time as EDNS1 is defined.
126              
127             =item querytime([$value])
128              
129             Returns the time the query this packet is the answer to took to execute, in
130             milliseconds. If given a value, sets the querytime to that value.
131              
132             =item answerfrom($ipaddr)
133              
134             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
135             IPv4 or IPv6 address, an exception is thrown.
136              
137             =item timestamp($time)
138              
139             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
140             kind of value used by L). Conversion effects between floating-point and C means that the precision of the
141             value is probably not reliable at the microsecond level, even if you computer's clock happen to be.
142              
143             =item question()
144              
145             =item answer()
146              
147             =item authority()
148              
149             =item additional()
150              
151             Returns list of objects representing the RRs in the named section. They will be of classes appropriate to their types, but all will have
152             C as a base class.
153              
154             =item unique_push($section, $rr)
155              
156             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"
157             or "additional" an exception will be thrown. C<$rr> must be a L subclass.
158              
159             =item string()
160              
161             Returns a string with the packet and its contents in common presentation format.
162              
163             =item wireformat()
164              
165             Returns a Perl string holding the packet in wire format.
166              
167             =item type()
168              
169             Returns the ldns library's guess as to the content of the packet. One of the strings C, C, C, C, C or C.
170              
171             =back