File Coverage

blib/lib/Net/LDNS/Packet.pm
Criterion Covered Total %
statement 11 13 84.6
branch n/a
condition n/a
subroutine 4 5 80.0
pod 0 2 0.0
total 15 20 75.0


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