1Net::DNS::Packet(3)   User Contributed Perl Documentation  Net::DNS::Packet(3)
2
3
4

NAME

6       Net::DNS::Packet - DNS packet object class
7

SYNOPSIS

9       "use Net::DNS::Packet;"
10

DESCRIPTION

12       A "Net::DNS::Packet" object represents a DNS packet.
13

METHODS

15       new
16
17           $packet = Net::DNS::Packet->new("example.com");
18           $packet = Net::DNS::Packet->new("example.com", "MX", "IN");
19
20           $packet = Net::DNS::Packet->new(\$data);
21           $packet = Net::DNS::Packet->new(\$data, 1);  # set debugging
22
23           ($packet, $err) = Net::DNS::Packet->new(\$data);
24
25       If passed a domain, type, and class, "new" creates a packet object
26       appropriate for making a DNS query for the requested information.  The
27       type and class can be omitted; they default to A and IN.
28
29       If passed a reference to a scalar containing DNS packet data, "new"
30       creates a packet object from that data.  A second argument can be
31       passed to turn on debugging output for packet parsing.
32
33       If called in array context, returns a packet object and an error
34       string.  The error string will only be defined if the packet object is
35       undefined (i.e., couldn't be created).
36
37       Returns undef if unable to create a packet object (e.g., if the packet
38       data is truncated).'
39
40       data
41
42           $data = $packet->data;
43
44       Returns the packet data in binary format, suitable for sending to a
45       nameserver.
46
47       header
48
49           $header = $packet->header;
50
51       Returns a "Net::DNS::Header" object representing the header section of
52       the packet.
53
54       question, zone
55
56           @question = $packet->question;
57
58       Returns a list of "Net::DNS::Question" objects representing the ques‐
59       tion section of the packet.
60
61       In dynamic update packets, this section is known as "zone" and speci‐
62       fies the zone to be updated.
63
64       answer, pre, prerequisite
65
66           @answer = $packet->answer;
67
68       Returns a list of "Net::DNS::RR" objects representing the answer sec‐
69       tion of the packet.
70
71       In dynamic update packets, this section is known as "pre" or "prerequi‐
72       site" and specifies the RRs or RRsets which must or must not preexist.
73
74       authority, update
75
76           @authority = $packet->authority;
77
78       Returns a list of "Net::DNS::RR" objects representing the authority
79       section of the packet.
80
81       In dynamic update packets, this section is known as "update" and speci‐
82       fies the RRs or RRsets to be added or delted.
83
84       additional
85
86           @additional = $packet->additional;
87
88       Returns a list of "Net::DNS::RR" objects representing the additional
89       section of the packet.
90
91       print
92
93           $packet->print;
94
95       Prints the packet data on the standard output in an ASCII format simi‐
96       lar to that used in DNS zone files.
97
98       string
99
100           print $packet->string;
101
102       Returns a string representation of the packet.
103
104       answerfrom
105
106           print "packet received from ", $packet->answerfrom, "\n";
107
108       Returns the IP address from which we received this packet.  User-cre‐
109       ated packets will return undef for this method.
110
111       answersize
112
113           print "packet size: ", $packet->answersize, " bytes\n";
114
115       Returns the size of the packet in bytes as it was received from a name‐
116       server.  User-created packets will return undef for this method (use
117       "length $packet->data" instead).
118
119       push
120
121           $packet->push(pre        => $rr);
122           $packet->push(update     => $rr);
123           $packet->push(additional => $rr);
124
125           $packet->push(update => $rr1, $rr2, $rr3);
126           $packet->push(update => @rr);
127
128       Adds RRs to the specified section of the packet.
129
130       unique_push
131
132           $packet->unique_push(pre        => $rr);
133           $packet->unique_push(update     => $rr);
134           $packet->unique_push(additional => $rr);
135
136           $packet->unique_push(update => $rr1, $rr2, $rr3);
137           $packet->unique_push(update => @rr);
138
139       Adds RRs to the specified section of the packet provided that the RRs
140       do not already exist in the packet.
141
142       safe_push
143
144       A deprecated name for "unique_push()".
145
146       pop
147
148           my $rr = $packet->pop("pre");
149           my $rr = $packet->pop("update");
150           my $rr = $packet->pop("additional");
151           my $rr = $packet->pop("question");
152
153       Removes RRs from the specified section of the packet.
154
155       dn_comp
156
157           $compname = $packet->dn_comp("foo.example.com", $offset);
158
159       Returns a domain name compressed for a particular packet object, to be
160       stored beginning at the given offset within the packet data.  The name
161       will be added to a running list of compressed domain names for future
162       use.
163
164       dn_expand
165
166           use Net::DNS::Packet qw(dn_expand);
167           ($name, $nextoffset) = dn_expand(\$data, $offset);
168
169           ($name, $nextoffset) = Net::DNS::Packet::dn_expand(\$data, $offset);
170
171       Expands the domain name stored at a particular location in a DNS
172       packet.  The first argument is a reference to a scalar containing the
173       packet data.  The second argument is the offset within the packet where
174       the (possibly compressed) domain name is stored.
175
176       Returns the domain name and the offset of the next location in the
177       packet.
178
179       Returns (undef, undef) if the domain name couldn't be expanded.
180
181       sign_tsig
182
183           $key_name = "tsig-key";
184           $key      = "awwLOtRfpGE+rRKF2+DEiw==";
185
186           $update = Net::DNS::Update->new("example.com");
187           $update->push("update", rr_add("foo.example.com A 10.1.2.3"));
188
189           $update->sign_tsig($key_name, $key);
190
191           $response = $res->send($update);
192
193       Signs a packet with a TSIG resource record (see RFC 2845).  Uses the
194       following defaults:
195
196           algorithm   = HMAC-MD5.SIG-ALG.REG.INT
197           time_signed = current time
198           fudge       = 300 seconds
199
200       If you wish to customize the TSIG record, you'll have to create it
201       yourself and call the appropriate Net::DNS::RR::TSIG methods.  The fol‐
202       lowing example creates a TSIG record and sets the fudge to 60 seconds:
203
204           $key_name = "tsig-key";
205           $key      = "awwLOtRfpGE+rRKF2+DEiw==";
206
207           $tsig = Net::DNS::RR->new("$key_name TSIG $key");
208           $tsig->fudge(60);
209
210           $query = Net::DNS::Packet->new("www.example.com");
211           $query->sign_tsig($tsig);
212
213           $response = $res->send($query);
214
215       You shouldn't modify a packet after signing it; otherwise authentica‐
216       tion will probably fail.
217
218       sign_sig0
219
220       SIG0 support is provided through the Net::DNS::RR::SIG class. This
221       class is not part of the default Net::DNS distribution but resides in
222       the Net::DNS::SEC distribution.
223
224           $update = Net::DNS::Update->new("example.com");
225           $update->push("update", rr_add("foo.example.com A 10.1.2.3"));
226           $update->sign_sig0("Kexample.com+003+25317.private");
227
228       SIG0 support is experimental see Net::DNS::RR::SIG for details.
229
230       The method will call "Carp::croak()" if Net::DNS::RR::SIG cannot be
231       found.
232
234       Copyright (c) 1997-2002 Michael Fuhr.
235
236       Portions Copyright (c) 2002-2004 Chris Reinhardt.
237
238       Portions Copyright (c) 2002-2005 Olaf Kolkman
239
240       All rights reserved.  This program is free software; you may redis‐
241       tribute it and/or modify it under the same terms as Perl itself.
242

SEE ALSO

244       perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Update,
245       Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 1035 Section
246       4.1, RFC 2136 Section 2, RFC 2845
247
248
249
250perl v5.8.8                       2007-08-01               Net::DNS::Packet(3)
Impressum