1Net::DNS::ZoneFile(3) User Contributed Perl DocumentationNet::DNS::ZoneFile(3)
2
3
4
6 Net::DNS::ZoneFile - DNS zone file
7
9 use Net::DNS::ZoneFile;
10
11 $zonefile = new Net::DNS::ZoneFile( 'named.example' );
12
13 while ( $rr = $zonefile->read ) {
14 $rr->print;
15 }
16
17 @zone = $zonefile->read;
18
20 Each Net::DNS::ZoneFile object instance represents a zone file together
21 with any subordinate files introduced by the $INCLUDE directive. Zone
22 file syntax is defined by RFC1035.
23
24 A program may have multiple zone file objects, each maintaining its own
25 independent parser state information.
26
27 The parser supports both the $TTL directive defined by RFC2308 and the
28 BIND $GENERATE syntax extension.
29
30 All RRs in a zone file must have the same class, which may be specified
31 for the first RR encountered and is then propagated automatically to
32 all subsequent records.
33
35 new
36 $zonefile = new Net::DNS::ZoneFile( 'filename', ['example.com'] );
37
38 $handle = new IO::File( 'filename', '<:encoding(ISO8859-7)' );
39 $zonefile = new Net::DNS::ZoneFile( $handle, ['example.com'] );
40
41 The new() constructor returns a Net::DNS::ZoneFile object which
42 represents the zone file specified in the argument list.
43
44 The specified file or file handle is open for reading and closed when
45 exhausted or all references to the ZoneFile object cease to exist.
46
47 The optional second argument specifies $ORIGIN for the zone file.
48
49 Character encoding is specified indirectly by creating a file handle
50 with the desired encoding layer, which is then passed as an argument to
51 new(). The specified encoding is propagated to files introduced by
52 $include directives.
53
54 read
55 $rr = $zonefile->read;
56 @rr = $zonefile->read;
57
58 When invoked in scalar context, read() returns a Net::DNS::RR object
59 representing the next resource record encountered in the zone file, or
60 undefined if end of data has been reached.
61
62 When invoked in list context, read() returns the list of Net::DNS::RR
63 objects in the order that they appear in the zone file.
64
65 Comments and blank lines are silently disregarded.
66
67 $INCLUDE, $ORIGIN, $TTL and $GENERATE directives are processed
68 transparently.
69
70 name
71 $filename = $zonefile->name;
72
73 Returns the name of the current zone file. Embedded $INCLUDE
74 directives will cause this to differ from the filename argument
75 supplied when the object was created.
76
77 line
78 $line = $zonefile->line;
79
80 Returns the number of the last line read from the current zone file.
81
82 origin
83 $origin = $zonefile->origin;
84
85 Returns the fully qualified name of the current origin within the zone
86 file.
87
88 ttl
89 $ttl = $zonefile->ttl;
90
91 Returns the default TTL as specified by the $TTL directive.
92
94 Applications which depended on the defunct Net::DNS::ZoneFile 1.04 CPAN
95 distribution will continue to operate with minimal change using the
96 compatibility interface described below. New application code should
97 use the object-oriented interface.
98
99 use Net::DNS::ZoneFile;
100
101 $listref = Net::DNS::ZoneFile->read( $filename );
102 $listref = Net::DNS::ZoneFile->read( $filename, $include_dir );
103
104 $listref = Net::DNS::ZoneFile->readfh( $filehandle );
105 $listref = Net::DNS::ZoneFile->readfh( $filehandle, $include_dir );
106
107 $listref = Net::DNS::ZoneFile->parse( $string );
108 $listref = Net::DNS::ZoneFile->parse( \$string );
109 $listref = Net::DNS::ZoneFile->parse( $string, $include_dir );
110 $listref = Net::DNS::ZoneFile->parse( \$string, $include_dir );
111
112 $_->print for @$listref;
113
114 The optional second argument specifies the default path for filenames.
115 The current working directory is used by default.
116
117 Although not available in the original implementation, the RR list can
118 be obtained directly by calling any of these methods in list context.
119
120 @rr = Net::DNS::ZoneFile->read( $filename, $include_dir );
121
122 The partial result is returned if an error is encountered by the
123 parser.
124
125 read
126 $listref = Net::DNS::ZoneFile->read( $filename );
127 $listref = Net::DNS::ZoneFile->read( $filename, $include_dir );
128
129 read() parses the contents of the specified file and returns a
130 reference to the list of Net::DNS::RR objects. The return value is
131 undefined if an error is encountered by the parser.
132
133 readfh
134 $listref = Net::DNS::ZoneFile->readfh( $filehandle );
135 $listref = Net::DNS::ZoneFile->readfh( $filehandle, $include_dir );
136
137 readfh() parses data from the specified file handle and returns a
138 reference to the list of Net::DNS::RR objects. The return value is
139 undefined if an error is encountered by the parser.
140
141 parse
142 $listref = Net::DNS::ZoneFile->parse( $string );
143 $listref = Net::DNS::ZoneFile->parse( \$string );
144 $listref = Net::DNS::ZoneFile->parse( $string, $include_dir );
145 $listref = Net::DNS::ZoneFile->parse( \$string, $include_dir );
146
147 parse() interprets the text in the argument string and returns a
148 reference to the list of Net::DNS::RR objects. The return value is
149 undefined if an error is encountered by the parser.
150
152 This package is designed as an improved and compatible replacement for
153 Net::DNS::ZoneFile 1.04 which was created by Luis Munoz in 2002 as a
154 separate CPAN module.
155
156 The present implementation is the result of an agreement to merge our
157 two different approaches into one package integrated into Net::DNS.
158 The contribution of Luis Munoz is gratefully acknowledged.
159
160 Thanks are also due to Willem Toorop for his constructive criticism of
161 the initial version and invaluable assistance during testing.
162
164 Copyright (c)2011-2012 Dick Franks.
165
166 All rights reserved.
167
169 Permission to use, copy, modify, and distribute this software and its
170 documentation for any purpose and without fee is hereby granted,
171 provided that the above copyright notice appear in all copies and that
172 both that copyright notice and this permission notice appear in
173 supporting documentation, and that the name of the author not be used
174 in advertising or publicity pertaining to distribution of the software
175 without specific prior written permission.
176
177 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
178 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
179 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
180 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
181 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
182 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
183 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
184
186 perl, Net::DNS, Net::DNS::RR, RFC1035 Section 5.1, RFC2308, BIND 9
187 Administrator Reference Manual
188
189
190
191perl v5.30.1 2020-01-30 Net::DNS::ZoneFile(3)