line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNS::ToolKit::RR::TXT; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
861
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
263
|
|
4
|
|
|
|
|
|
|
#use warnings; |
5
|
|
|
|
|
|
|
#use diagnostics; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
|
|
595
|
use Net::DNS::ToolKit qw( |
8
|
|
|
|
|
|
|
get16 |
9
|
|
|
|
|
|
|
put16 |
10
|
|
|
|
|
|
|
get1char |
11
|
|
|
|
|
|
|
put1char |
12
|
|
|
|
|
|
|
dn_comp |
13
|
|
|
|
|
|
|
dn_expand |
14
|
|
|
|
|
|
|
putstring |
15
|
|
|
|
|
|
|
getstring |
16
|
6
|
|
|
6
|
|
28
|
); |
|
6
|
|
|
|
|
10
|
|
17
|
6
|
|
|
6
|
|
34
|
use Net::DNS::Codes qw(:constants); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
1838
|
|
18
|
6
|
|
|
6
|
|
56
|
use vars qw($VERSION); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
3030
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 0.03 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Net::DNS::ToolKit::RR::TXT - Resource Record Handler |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
DO NOT use Net::DNS::ToolKit::RR::TXT |
29
|
|
|
|
|
|
|
DO NOT require Net::DNS::ToolKit::RR::TXT |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Net::DNS::ToolKit::RR::TXT is autoloaded by |
32
|
|
|
|
|
|
|
class Net::DNS::ToolKit::RR and its methods |
33
|
|
|
|
|
|
|
are instantiated in a 'special' manner. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Net::DNS::ToolKit::RR; |
36
|
|
|
|
|
|
|
($get,$put,$parse) = new Net::DNS::ToolKit::RR; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
($newoff,$name,$type,$class,$ttl,$rdlength, |
39
|
|
|
|
|
|
|
$textdata) = $get->TXT(\$buffer,$offset); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Note: the $get->TXT method is normally called |
42
|
|
|
|
|
|
|
via: @stuff = $get->next(\$buffer,$offset); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
($newoff,@dnptrs)=$put->TXT(\$buffer,$offset,\@dnptrs, |
45
|
|
|
|
|
|
|
$name,$type,$class,$ttl,$textdata,$textdata,$textdata,...); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$NAME,$TYPE,$CLASS,$TTL,$rdlength,$textdata) |
48
|
|
|
|
|
|
|
= $parse->TXT($name,$type,$class,$ttl,$rdlength, |
49
|
|
|
|
|
|
|
$textdata); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 DESCRIPTION |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
B appends an TXT resource record to a DNS packet under |
54
|
|
|
|
|
|
|
construction, recovers an TXT resource record from a packet being decoded, and |
55
|
|
|
|
|
|
|
converts the numeric/binary portions of the resource record to human |
56
|
|
|
|
|
|
|
readable form. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Description from RFC1035.txt |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
3.2.1. Format |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
All RRs have the same top level format shown below: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1 1 1 1 1 1 |
65
|
|
|
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
66
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
67
|
|
|
|
|
|
|
| NAME | |
68
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
69
|
|
|
|
|
|
|
| TYPE | |
70
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
71
|
|
|
|
|
|
|
| CLASS | |
72
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
73
|
|
|
|
|
|
|
| TTL | |
74
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
75
|
|
|
|
|
|
|
| RDLENGTH | |
76
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--| |
77
|
|
|
|
|
|
|
| RDATA | |
78
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
NAME an owner name, i.e., the name of the node to which this |
81
|
|
|
|
|
|
|
resource record pertains. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
TYPE two octets containing one of the RR TYPE codes. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
CLASS two octets containing one of the RR CLASS codes. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
TTL a 32 bit signed integer that specifies the time interval |
88
|
|
|
|
|
|
|
that the resource record may be cached before the source |
89
|
|
|
|
|
|
|
of the information should again be consulted. Zero |
90
|
|
|
|
|
|
|
values are interpreted to mean that the RR can only be |
91
|
|
|
|
|
|
|
used for the transaction in progress, and should not be |
92
|
|
|
|
|
|
|
cached. For example, SOA records are always distributed |
93
|
|
|
|
|
|
|
with a zero TTL to prohibit caching. Zero values can |
94
|
|
|
|
|
|
|
also be used for extremely volatile data. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
RDLENGTH an unsigned 16 bit integer that specifies the length |
97
|
|
|
|
|
|
|
in octets of the RDATA field. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
RDATA a variable length string of octets that describes the |
100
|
|
|
|
|
|
|
resource. The format of this information varies |
101
|
|
|
|
|
|
|
according to the TYPE and CLASS of the resource record. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
3.3.14. TXT RDATA format |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
106
|
|
|
|
|
|
|
/ TXT-DATA / |
107
|
|
|
|
|
|
|
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
where: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
TXT-DATA One or more s. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
TXT RRs are used to hold descriptive text. The semantics of the text |
114
|
|
|
|
|
|
|
depends on the domain where it is found. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Note: Each character string consists of up to 255 characters. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * @stuff = $get->TXT(\$buffer,$offset); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Get the contents of the resource record. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
USE: @stuff = $get->next(\$buffer,$offset); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
where: @stuff = ( |
127
|
|
|
|
|
|
|
$newoff $name,$type,$class,$ttl,@textdata ); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
All except the last item, B<$textdata>, is provided by |
130
|
|
|
|
|
|
|
the class loader, B. The code in this method knows |
131
|
|
|
|
|
|
|
how to retrieve B<$textdata>. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
input: pointer to buffer, |
134
|
|
|
|
|
|
|
offset into buffer |
135
|
|
|
|
|
|
|
returns: offset to next resource, |
136
|
|
|
|
|
|
|
@common RR elements, |
137
|
|
|
|
|
|
|
text string(s) |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub get { |
142
|
4
|
|
|
4
|
0
|
1244
|
my($self,$bp,$offset) = @_; |
143
|
4
|
|
|
|
|
19
|
(my $rdend,$offset) = get16($bp,$offset); # get rdlength |
144
|
4
|
|
|
|
|
8
|
$rdend += $offset; # end pointer |
145
|
4
|
|
|
|
|
7
|
my @tdata; |
146
|
4
|
|
|
|
|
13
|
while($offset < $rdend) { |
147
|
6
|
|
|
|
|
18
|
my $len = get1char($bp,$offset); |
148
|
6
|
|
|
|
|
23
|
(my $string,$offset) = getstring($bp,$offset+1,$len); |
149
|
6
|
|
|
|
|
27
|
push @tdata, $string; |
150
|
|
|
|
|
|
|
} |
151
|
4
|
|
|
|
|
19
|
return($offset,@tdata); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * ($newoff,@dnptrs)=$put->TXT(\$buffer,$offset,\@dnptrs, |
155
|
|
|
|
|
|
|
$name,$type,$class,$ttl,@textdata); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Append a TXT record to $buffer. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
where @common = ( |
160
|
|
|
|
|
|
|
$name,$type,$class,$ttl); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The method will insert the $rdlength and $textdata, then |
163
|
|
|
|
|
|
|
pass through the updated pointer to the array of compressed names |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The class loader, B, inserts the @common elements and |
166
|
|
|
|
|
|
|
returns updated @dnptrs. This module knows how to insert its RDATA and |
167
|
|
|
|
|
|
|
calculate the $rdlength. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
input: pointer to buffer, |
170
|
|
|
|
|
|
|
offset (normally end of buffer), |
171
|
|
|
|
|
|
|
pointer to compressed name array, |
172
|
|
|
|
|
|
|
@common RR elements, |
173
|
|
|
|
|
|
|
text string(s) =< 255 characters. |
174
|
|
|
|
|
|
|
output: offset to next RR, |
175
|
|
|
|
|
|
|
new compressed name pointer array, |
176
|
|
|
|
|
|
|
or empty list () on error. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Note: Double quotes embedded in the text |
179
|
|
|
|
|
|
|
should be escaped. i.e. \" |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub put { |
184
|
7
|
50
|
|
7
|
0
|
347
|
return () unless @_; # always return on error |
185
|
7
|
|
|
|
|
32
|
my($self,$bp,$off,$dnp,@textdata) = @_; |
186
|
7
|
|
|
|
|
12
|
my $rdlp = $off; # save pointer to rdlength |
187
|
7
|
|
|
|
|
8
|
my $doff; |
188
|
7
|
50
|
|
|
|
34
|
return () unless # check for valid offset and get |
189
|
|
|
|
|
|
|
($off = $doff = put16($bp,$off,0)); # offset to text string |
190
|
7
|
|
|
|
|
20
|
foreach(0..$#textdata) { |
191
|
9
|
|
|
|
|
19
|
$textdata[$_] =~ s/\\"/"/g; # unescape embedded quotes |
192
|
9
|
|
|
|
|
16
|
my $len = length($textdata[$_]); |
193
|
9
|
50
|
|
|
|
27
|
return () if $len > 255; |
194
|
9
|
|
|
|
|
30
|
$off = put1char($bp,$off,$len); |
195
|
9
|
|
|
|
|
43
|
$off = putstring($bp,$off,\$textdata[$_]); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
# rdlength = new offset - previous offset |
198
|
7
|
|
|
|
|
25
|
put16($bp,$rdlp, $off - $doff); |
199
|
7
|
|
|
|
|
77
|
return($off,@$dnp); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * (@COMMON,@textdata) = $parse->TXT(@common,@textdata); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Converts binary/numeric field data into human readable form. The common RR |
205
|
|
|
|
|
|
|
elements are supplied by the class loader, B. |
206
|
|
|
|
|
|
|
For TXT RR's, this returns the text strings, each surrounded by double quotes. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
input: text string(s) |
209
|
|
|
|
|
|
|
returns: "text string(s)" |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=back |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub parse { |
216
|
6
|
|
|
6
|
0
|
3154
|
shift; # $self |
217
|
6
|
|
|
|
|
11
|
my @ret; |
218
|
6
|
|
|
|
|
14
|
foreach(@_) { |
219
|
8
|
|
|
|
|
16
|
$_ =~ s/"/\\"/g; # escape embedded quotes |
220
|
8
|
|
|
|
|
25
|
push @ret, '"'.$_.'"'; |
221
|
|
|
|
|
|
|
} |
222
|
6
|
100
|
|
|
|
40
|
return wantarray ? @ret : $ret[0]; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Net::DNS::ToolKit |
228
|
|
|
|
|
|
|
Net::DNS::Codes |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 EXPORT |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
none |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Michael Robinton |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Copyright 2003 - 2011, Michael Robinton |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Michael Robinton |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
All rights reserved. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
247
|
|
|
|
|
|
|
it under the terms of either: |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
a) the GNU General Public License as published by the Free |
250
|
|
|
|
|
|
|
Software Foundation; either version 2, or (at your option) any |
251
|
|
|
|
|
|
|
later version, or |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
b) the "Artistic License" which comes with this distribution. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
256
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
257
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either |
258
|
|
|
|
|
|
|
the GNU General Public License or the Artistic License for more details. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
You should have received a copy of the Artistic License with this |
261
|
|
|
|
|
|
|
distribution, in the file named "Artistic". If not, I'll be glad to provide |
262
|
|
|
|
|
|
|
one. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
You should also have received a copy of the GNU General Public License |
265
|
|
|
|
|
|
|
along with this program in the file named "Copying". If not, write to the |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Free Software Foundation, Inc. |
268
|
|
|
|
|
|
|
59 Temple Place, Suite 330 |
269
|
|
|
|
|
|
|
Boston, MA 02111-1307, USA |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
or visit their web page on the internet at: |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
http://www.gnu.org/copyleft/gpl.html. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 See also: |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Net::DNS::Codes(3), Net::DNS::ToolKit(3) |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |