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