1Net::DNS::RR(3) User Contributed Perl Documentation Net::DNS::RR(3)
2
3
4
6 Net::DNS::RR - DNS Resource Record class
7
9 "use Net::DNS::RR"
10
12 "Net::DNS::RR" is the base class for DNS Resource Record (RR) objects.
13 See also the manual pages for each RR type.
14
16 WARNING!!! Don't assume the RR objects you receive from a query are of
17 a particular type -- always check an object's type before calling any
18 of its methods. If you call an unknown method, you'll get a nasty
19 warning message and "Net::DNS::RR" will return "undef" to the caller.
20
21 new (from string)
22 $a = Net::DNS::RR->new("foo.example.com. 86400 A 10.1.2.3");
23 $mx = Net::DNS::RR->new("example.com. 7200 MX 10 mailhost.example.com.");
24 $cname = Net::DNS::RR->new("www.example.com 300 IN CNAME www1.example.com");
25 $txt = Net::DNS::RR->new('baz.example.com 3600 HS TXT "text record"');
26
27 Returns a "Net::DNS::RR" object of the appropriate type and initialized
28 from the string passed by the user. The format of the string is that
29 used in zone files, and is compatible with the string returned by
30 "Net::DNS::RR->string".
31
32 The name and RR type are required; all other information is optional.
33 If omitted, the TTL defaults to 0 and the RR class defaults to IN.
34 Omitting the optional fields is useful for creating the empty RDATA
35 sections required for certain dynamic update operations. See the
36 "Net::DNS::Update" manual page for additional examples.
37
38 All names must be fully qualified. The trailing dot (.) is optional.
39
40 new (from hash)
41 $rr = Net::DNS::RR->new(
42 name => "foo.example.com",
43 ttl => 86400,
44 class => "IN",
45 type => "A",
46 address => "10.1.2.3",
47 );
48
49 $rr = Net::DNS::RR->new(
50 name => "foo.example.com",
51 type => "A",
52 );
53
54 Returns an RR object of the appropriate type, or a "Net::DNS::RR"
55 object if the type isn't implemented. See the manual pages for each RR
56 type to see what fields the type requires.
57
58 The "Name" and "Type" fields are required; all others are optional. If
59 omitted, "TTL" defaults to 0 and "Class" defaults to IN. Omitting the
60 optional fields is useful for creating the empty RDATA sections
61 required for certain dynamic update operations.
62
63 The fields are case-insensitive, but starting each with uppercase is
64 recommended.
65
66 parse
67 ($rrobj, $offset) = Net::DNS::RR->parse(\$data, $offset);
68
69 Parses a DNS resource record at the specified location within a DNS
70 packet. The first argument is a reference to the packet data. The
71 second argument is the offset within the packet where the resource
72 record begins.
73
74 Returns a Net::DNS::RR object and the offset of the next location in
75 the packet.
76
77 Parsing is aborted if the object could not be created (e.g., corrupt or
78 insufficient data).
79
80 print
81 $rr->print;
82
83 Prints the record to the standard output. Calls the string method to
84 get the RR's string representation.
85
86 string
87 print $rr->string, "\n";
88
89 Returns a string representation of the RR. Calls the rdatastr method
90 to get the RR-specific data. Domain names are returned in RFC1035
91 format, i.e. all non letter, digit, hyphen characters are represented
92 as \DDD.
93
94 rdatastr
95 $s = $rr->rdatastr;
96
97 Returns a string containing RR-specific data. Subclasses will need to
98 implement this method.
99
100 name
101 $name = $rr->name;
102
103 Returns the record's domain name.
104
105 type
106 $type = $rr->type;
107
108 Returns the record's type.
109
110 class
111 $class = $rr->class;
112
113 Returns the record's class.
114
115 ttl
116 $ttl = $rr->ttl;
117
118 Returns the record's time-to-live (TTL).
119
120 rdlength
121 $rdlength = $rr->rdlength;
122
123 Returns the length of the record's data section.
124
125 rdata
126 $rdata = $rr->rdata
127
128 Returns the record's data section as binary data.
129
131 As of version 0.55 there is functionality to help you sort RR arrays.
132 The sorting is done by Net::DNS::rrsort(), see the Net::DNS
133 documentation. This package provides class methods to set the sorting
134 functions used for a particular RR based on a particular attribute.
135
136 set_rrsort_func
137 Net::DNS::RR::SRV->set_rrsort_func("priority",
138 sub { my ($a,$b)=($Net::DNS::a,$Net::DNS::b);
139 $a->priority <=> $b->priority
140 || $b->weight <=>
141 $a->weight
142 }
143
144 Net::DNS::RR::SRV->set_rrsort_func("default_sort",
145 sub { my ($a,$b)=($Net::DNS::a,$Net::DNS::b);
146 $a->priority <=> $b->priority
147 || $b->weight <=>
148 $a->weight
149 }
150
151 set_rrsort_func needs to be called as a class method. The first
152 argument is the attribute name on which the sorting will need to take
153 place. If you specify "default_sort" than that is the sort algorithm
154 that will be used in the case that rrsort() is called without an RR
155 attribute as argument.
156
157 The second argument is a reference to a function that uses the
158 variables $a and $b global to the "from Net::DNS"(!!)package for the
159 sorting. During the sorting $a and $b will contain references to
160 objects from the class you called the set_prop_sort from. In other
161 words, you can rest assured that the above sorting function will only
162 get Net::DNS::RR::SRV objects.
163
164 The above example is the sorting function that actually is implemented
165 in SRV.
166
168 This version of "Net::DNS::RR" does little sanity checking on user-
169 created RR objects.
170
172 Copyright (c) 1997-2002 Michael Fuhr.
173
174 Portions Copyright (c) 2002-2004 Chris Reinhardt.
175
176 Portions Copyright (c) 2005-2007 Olaf Kolkman
177
178 Portions Copyright (c) 2007 Dick Franks
179
180 All rights reserved. This program is free software; you may
181 redistribute it and/or modify it under the same terms as Perl itself.
182
183 EDNS0 extensions by Olaf Kolkman.
184
186 perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Packet,
187 Net::DNS::Update, Net::DNS::Header, Net::DNS::Question, RFC 1035
188 Section 4.1.3
189
190
191
192perl v5.10.1 2009-01-26 Net::DNS::RR(3)