home *** CD-ROM | disk | FTP | other *** search
Wrap
<HTML> <HEAD> <TITLE>Net::Bind::Resolv - a class to munge /etc/resolv.conf data.</TITLE> <LINK REL="stylesheet" HREF="../../../../Active.css" TYPE="text/css"> <LINK REV="made" HREF="mailto:"> </HEAD> <BODY> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc"> <STRONG><P CLASS=block> Net::Bind::Resolv - a class to munge /etc/resolv.conf data.</P></STRONG> </TD></TR> </TABLE> <A NAME="__index__"></A> <!-- INDEX BEGIN --> <UL> <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI> <LI><A HREF="#synopsis">SYNOPSIS</A></LI> <LI><A HREF="#description">DESCRIPTION</A></LI> <LI><A HREF="#methods">METHODS</A></LI> <UL> <LI><A HREF="#new([$filename])"><CODE>new([$filename])</CODE></A></LI> <LI><A HREF="#read_from_string($string)"><CODE>read_from_string($string)</CODE></A></LI> <LI><A HREF="#read_from_file($filename)"><CODE>read_from_file($filename)</CODE></A></LI> <LI><A HREF="#clear">clear</A></LI> <LI><A HREF="#domain([$domain])"><CODE>domain([$domain])</CODE></A></LI> <LI><A HREF="#nameservers([@values])"><CODE>nameservers([@values])</CODE></A></LI> <LI><A HREF="#searchlist([@values])"><CODE>searchlist([@values])</CODE></A></LI> <LI><A HREF="#sortlist([@values])"><CODE>sortlist([@values])</CODE></A></LI> <LI><A HREF="#options([@values])"><CODE>options([@values])</CODE></A></LI> <LI><A HREF="#comments([@strings])"><CODE>comments([@strings])</CODE></A></LI> <LI><A HREF="#as_string">as_string</A></LI> <LI><A HREF="#print($fh)"><A HREF="../../../../lib/Pod/perlfunc.html#item_print"><CODE>print($fh)</CODE></A></A></LI> <LI><A HREF="#check([$policy])"><CODE>check([$policy])</CODE></A></LI> <LI><A HREF="#default_policy_check">default_policy_check</A></LI> <LI><A HREF="#check_domain">check_domain</A></LI> <LI><A HREF="#check_searchlist">check_searchlist</A></LI> <LI><A HREF="#check_nameservers">check_nameservers</A></LI> <LI><A HREF="#check_sortlist">check_sortlist</A></LI> <LI><A HREF="#check_options">check_options</A></LI> <LI><A HREF="#qtynameservers">qtynameservers</A></LI> </UL> <LI><A HREF="#caveats">CAVEATS</A></LI> <LI><A HREF="#author">AUTHOR</A></LI> <LI><A HREF="#copyright">COPYRIGHT</A></LI> </UL> <!-- INDEX END --> <HR> <P> <H1><A NAME="name">NAME</A></H1> <P>Net::Bind::Resolv - a class to munge /etc/resolv.conf data.</P> <P> <HR> <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1> <UL> <LI>Linux</LI> <LI>Solaris</LI> <LI>Windows</LI> </UL> <HR> <H1><A NAME="synopsis">SYNOPSIS</A></H1> <P><CODE>use Net::Bind::Resolv;</CODE></P> <P> <HR> <H1><A NAME="description">DESCRIPTION</A></H1> <P>This class provides an object oriented perl interface to <CODE>/etc/resolv.conf</CODE> data.</P> <P>Here is an example snippet of code:</P> <PRE> use Net::Bind::Resolv; my $res = new Net::Bind::Resolv('/etc/resolv.conf'); print $res->domain, "\n";</PRE> <P>Or how about:</P> <PRE> use Net::Bind::Resolv; use IO::File; my $res = new Net::Bind::Resolv; $res->comment("Programmatically generated\nDo not edit by hand"); $res->domain('arf.fz'); $res->nameservers('0.0.0.0'); $res->options('debug'); print $res->as_string;</PRE> <P> <HR> <H1><A NAME="methods">METHODS</A></H1> <P> <H2><A NAME="new([$filename])"><CODE>new([$filename])</CODE></A></H2> <P>Returns a reference to a new <CODE>Net::Bind::Resolv</CODE> object. If <CODE>$filename</CODE> is given then use that pass the value to a call to <CODE>read_from_file</CODE>.</P> <P> <H2><A NAME="read_from_string($string)"><CODE>read_from_string($string)</CODE></A></H2> <P>Populates the object with the parsed contents of <CODE>$string</CODE>. Returns <CODE>1</CODE> is no errors were encounters, otherwise it returns <CODE>0</CODE>.</P> <P>The following directives are understood.</P> <UL> <LI><STRONG><A NAME="item_domain">domain DOMAIN</A></STRONG><BR> <LI><STRONG><A NAME="item_search_SEARCHLIST%2E%2E%2E">search SEARCHLIST...</A></STRONG><BR> If a <CODE>search</CODE> directive and domain directive are found in the same file, the last one encountered will be recorded and all previous ones will be ignored. <P></P> <LI><STRONG><A NAME="item_nameserver_IP_ADDR">nameserver IP_ADDR</A></STRONG><BR> Each instance of a <CODE>nameserver</CODE> directive will cause the given <CODE>IP_ADDR</CODE> to be remembered. <P></P> <LI><STRONG><A NAME="item_sortlist_SORTLIST%2E%2E%2E">sortlist SORTLIST...</A></STRONG><BR> <LI><STRONG><A NAME="item_options_OPTIONS%2E%2E%2E">options OPTIONS...</A></STRONG><BR> </UL> <P>There are very few requirements placed on the data in <CODE>$string</CODE>. Multiple entries of certain directives, while technically incorrect, will cause the last occurrence of the given directive to be the one remembered. If there is sufficient precedence for this to be otherwise, let me know.</P> <P>There is no requirement for the arguments to the directives to be valid pieces of data. That job is delagated to local policy methods to be applied against the object.</P> <P> <H2><A NAME="read_from_file($filename)"><CODE>read_from_file($filename)</CODE></A></H2> <P>Populates the object with the parsed contents of <CODE>$filename</CODE>. This really just a wrapper around <CODE>read_from_string</CODE>. Returns <CODE>0</CODE> if errors were encountered, otherwise it returns <CODE>1</CODE>.</P> <P> <H2><A NAME="clear">clear</A></H2> <P>Zeros out the internal data in the object. This needs to be done if multiple <CODE>read_from_string</CODE> methods are called on a given <CODE>Net::Bind::Resolv</CODE> object and you do not want to retain the previous values in the object.</P> <P> <H2><A NAME="domain([$domain])"><A HREF="#item_domain"><CODE>domain([$domain])</CODE></A></A></H2> <P>Returns the value of the <A HREF="#item_domain"><CODE>domain</CODE></A> directive. If <CODE>$domain</CODE> is specified, then set the domain to the given value and the <CODE>searchlist</CODE>, if defined in the object, is undefined.</P> <P> <H2><A NAME="nameservers([@values])"><CODE>nameservers([@values])</CODE></A></H2> <P>Returns (in order) the list of <CODE>nameserver</CODE> entries. If called in an array context it returns an array, otherwise it returns an array reference.</P> <P>If <CODE>@values</CODE> is specified, then set the nameserver list to the given values. Any items in <CODE>@values</CODE> that are list references are dereferences as they are added.</P> <P> <H2><A NAME="searchlist([@values])"><CODE>searchlist([@values])</CODE></A></H2> <P>Returns an array reference containing the items for the <CODE>search</CODE> directive. If called in an array context it returns an array, otherwise it returns an array reference.</P> <P>If a list of values is specified, then set the searchlist to those values and the <A HREF="#item_domain"><CODE>domain</CODE></A>, if defined in the object, is undefined. Any items in <CODE>@values</CODE> that are list references are dereferenced as they are added.</P> <P> <H2><A NAME="sortlist([@values])"><CODE>sortlist([@values])</CODE></A></H2> <P>Returns an array reference containing the items for the <CODE>sortlist</CODE> directive. If called in an array context it returns an array, otherwise it returns an array reference.</P> <P>If a list of values is specified, then set the sortlist to those values. Any items in <CODE>@values</CODE> that are list references are dereferenced as they are added.</P> <P> <H2><A NAME="options([@values])"><CODE>options([@values])</CODE></A></H2> <P>Returns the items for the <CODE>options</CODE> directive. If called in an array context it returns an array, otherwise it returns an array reference.</P> <P>If a list of values is specified, then set the options to those values. Any items in <CODE>@values</CODE> that are list references are dereferenced as they are added.</P> <P> <H2><A NAME="comments([@strings])"><CODE>comments([@strings])</CODE></A></H2> <P>Returns the comments for the object. If called in an array context it returns an array, otherwise it returns an array reference.</P> <P>If a list of strings is specified, then set the comments to those values after splitting the items on a <CODE>NEWLINE</CODE> boundary. This allows several combinations of arrays, array refs, or strings with embedded newlines to be specified. There is no need to prefix any of the comment lines with a comment character (<CODE>[;\#]</CODE>); the <CODE>as_string</CODE> automagically commentifies (:-) the comment strings.</P> <P>Any items in <CODE>@strings</CODE> that are list references are dereferenced as they are added.</P> <P> <H2><A NAME="as_string">as_string</A></H2> <P>Returns a string representing the contents of the object. Technically, this string could be used to populate a <CODE>resolv.conf</CODE> file, but use <A HREF="../../../../lib/Pod/perlfunc.html#item_print"><CODE>print</CODE></A> for that. The <print> method is a wrapper around this method. The data is generated in the following order:</P> <PRE> comments domain (mutually exclusive with search) search (mutually exclusive with domain) nameservers (one line for each nameserver entry) sortlist options</PRE> <P> <H2><A NAME="print($fh)"><A HREF="../../../../lib/Pod/perlfunc.html#item_print"><CODE>print($fh)</CODE></A></A></H2> <P>A wrapper around <CODE>as_string</CODE> that prints a valid <CODE>resolver(5)</CODE> representation of the data in the object to the given filehandle.</P> <P> <H2><A NAME="check([$policy])"><CODE>check([$policy])</CODE></A></H2> <P>Performs a policy/validity check of the data contained in the object using the given subroutine <CODE>&policy</CODE>. The given <CODE>$policy</CODE> routine is called as <CODE>&$policy($self)</CODE>. If <CODE>$policy</CODE> is not given it defaults to using <CODE>default_policy_check</CODE>. It returns the return status of the policy check routine.</P> <P> <H2><A NAME="default_policy_check">default_policy_check</A></H2> <P>A simple wrapper around various <CODE>check_*</CODE> methods.</P> <P> <H2><A NAME="check_domain">check_domain</A></H2> <P>Returns <CODE>1</CODE> if the domain member of the object is defined and is a valid rfc1035 domain name, otherwise returns <CODE>0</CODE>.</P> <P> <H2><A NAME="check_searchlist">check_searchlist</A></H2> <P>Returns <CODE>1</CODE> if the searchlist member of the object is defined and contains only valid rfc1035 domain names, otherwise returns <CODE>0</CODE>.</P> <P> <H2><A NAME="check_nameservers">check_nameservers</A></H2> <P>Returns <CODE>1</CODE> if the nameservers member of the object is defined and contains only ip-addresses, otherwise returns <CODE>0</CODE>.</P> <P>Uses <CODE>valid_ip</CODE> to do the real work.</P> <P> <H2><A NAME="check_sortlist">check_sortlist</A></H2> <P>Returns <CODE>1</CODE> if the sortlist member of the object is defined and contains only ip-address/netmasks, otherwise returns <CODE>0</CODE>.</P> <P>Uses <CODE>valid_netmask</CODE> to do the real work.</P> <P> <H2><A NAME="check_options">check_options</A></H2> <P>Returns <CODE>1</CODE> if the options member of the object is empty or contains only valid options, otherwise returns <CODE>0</CODE>.</P> <P>Currently recognized options are:</P> <UL> <LI><STRONG><A NAME="item_debug">debug</A></STRONG><BR> <LI><STRONG><A NAME="item_ndots%3AN">ndots:N</A></STRONG><BR> </UL> <P> <H2><A NAME="qtynameservers">qtynameservers</A></H2> <P>Returns the quantity of nameserver entries present.</P> <P> <HR> <H1><A NAME="caveats">CAVEATS</A></H1> <P>The <CODE>read_from_{file|string}</CODE> methods and the <A HREF="../../../../lib/Pod/perlfunc.html#item_print"><CODE>print</CODE></A> method are not isomorphic. Given an arbitrary file or string which is read in, the output of <A HREF="../../../../lib/Pod/perlfunc.html#item_print"><CODE>print</CODE></A> is not guaranteed to be an exact duplicate of the original file. In the special case of files that are generated with this module, the results will be isomorphic, assuming no modifications were made to the data between when it was read in and subsequently written back out.</P> <P>Since Net::Bind::Resolv does not impose many requirements on the values of the various directives present in a <CODE>/etc/resolv.conf</CODE> file, it is important to apply the appropriate policy methods against the object before writing it to a file that will be used by the resolver. Consider yourself warned!</P> <P> <HR> <H1><A NAME="author">AUTHOR</A></H1> <P>Kevin Johnson <<EM><A HREF="mailto:kjj@pobox.com">kjj@pobox.com</A></EM>></P> <P> <HR> <H1><A NAME="copyright">COPYRIGHT</A></H1> <P>Copyright (c) 1997 Kevin Johnson <<A HREF="mailto:kjj@pobox.com">kjj@pobox.com</A>>.</P> <P>All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</P> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc"> <STRONG><P CLASS=block> Net::Bind::Resolv - a class to munge /etc/resolv.conf data.</P></STRONG> </TD></TR> </TABLE> </BODY> </HTML>