home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Net::DNS::Resolver - DNS resolver class</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::DNS::Resolver - DNS resolver class</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">new</A></LI>
- <LI><A HREF="#print">print</A></LI>
- <LI><A HREF="#string">string</A></LI>
- <LI><A HREF="#searchlist">searchlist</A></LI>
- <LI><A HREF="#nameservers">nameservers</A></LI>
- <LI><A HREF="#port">port</A></LI>
- <LI><A HREF="#search">search</A></LI>
- <LI><A HREF="#query">query</A></LI>
- <LI><A HREF="#send">send</A></LI>
- <LI><A HREF="#bgsend">bgsend</A></LI>
- <LI><A HREF="#bgread">bgread</A></LI>
- <LI><A HREF="#bgisready">bgisready</A></LI>
- <LI><A HREF="#axfr">axfr</A></LI>
- <LI><A HREF="#tcp_timeout">tcp_timeout</A></LI>
- <LI><A HREF="#retrans">retrans</A></LI>
- <LI><A HREF="#retry">retry</A></LI>
- <LI><A HREF="#recurse">recurse</A></LI>
- <LI><A HREF="#defnames">defnames</A></LI>
- <LI><A HREF="#dnsrch">dnsrch</A></LI>
- <LI><A HREF="#debug">debug</A></LI>
- <LI><A HREF="#usevc">usevc</A></LI>
- <LI><A HREF="#igntc">igntc</A></LI>
- <LI><A HREF="#errorstring">errorstring</A></LI>
- <LI><A HREF="#answerfrom">answerfrom</A></LI>
- <LI><A HREF="#answersize">answersize</A></LI>
- </UL>
-
- <LI><A HREF="#environment">ENVIRONMENT</A></LI>
- <UL>
-
- <LI><A HREF="#res_nameservers">RES_NAMESERVERS</A></LI>
- <LI><A HREF="#res_searchlist">RES_SEARCHLIST</A></LI>
- <LI><A HREF="#localdomain">LOCALDOMAIN</A></LI>
- <LI><A HREF="#res_options">RES_OPTIONS</A></LI>
- </UL>
-
- <LI><A HREF="#bugs">BUGS</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Net::DNS::Resolver - DNS resolver class</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::DNS::Resolver;</CODE></P>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>Instances of the <CODE>Net::DNS::Resolver</CODE> class represent resolver objects.
- A program can have multiple resolver objects, each maintaining its
- own state information such as the nameservers to be queried, whether
- recursion is desired, etc.</P>
- <P>Resolver configuration is read from the following files, in the
- order indicated:</P>
- <PRE>
- /etc/resolv.conf
- $HOME/.resolv.conf
- ./.resolv.conf</PRE>
- <P>The following keywords are recognized in resolver configuration files:</P>
- <DL>
- <DT><STRONG><A NAME="item_domain"><STRONG>domain</STRONG></A></STRONG><BR>
- <DD>
- The default domain.
- <P></P>
- <DT><STRONG><A NAME="item_search"><STRONG>search</STRONG></A></STRONG><BR>
- <DD>
- A space-separated list of domains to put in the search list.
- <P></P>
- <DT><STRONG><A NAME="item_nameserver"><STRONG>nameserver</STRONG></A></STRONG><BR>
- <DD>
- A space-separated list of nameservers to query.
- <P></P></DL>
- <P>Files except for <EM>/etc/resolv.conf</EM> must be owned by the effective
- userid running the program or they won't be read. In addition, several
- environment variables can also contain configuration information;
- see <A HREF="#environment">ENVIRONMENT</A>.</P>
- <P>
- <HR>
- <H1><A NAME="methods">METHODS</A></H1>
- <P>
- <H2><A NAME="new">new</A></H2>
- <PRE>
- $res = new Net::DNS::Resolver;</PRE>
- <P>Creates a new DNS resolver object.</P>
- <P>
- <H2><A NAME="print">print</A></H2>
- <PRE>
- $res->print;</PRE>
- <P>Prints the resolver state on the standard output.</P>
- <P>
- <H2><A NAME="string">string</A></H2>
- <PRE>
- print $res->string;</PRE>
- <P>Returns a string representation of the resolver state.</P>
- <P>
- <H2><A NAME="searchlist">searchlist</A></H2>
- <PRE>
- @searchlist = $res->searchlist;
- $res->searchlist("foo.com", "bar.com", "baz.org");</PRE>
- <P>Gets or sets the resolver search list.</P>
- <P>
- <H2><A NAME="nameservers">nameservers</A></H2>
- <PRE>
- @nameservers = $res->nameservers;
- $res->nameservers("192.168.1.1", "192.168.2.2", "192.168.3.3");</PRE>
- <P>Gets or sets the nameservers to be queried.</P>
- <P>
- <H2><A NAME="port">port</A></H2>
- <PRE>
- print "sending queries to port ", $res->port, "\n";
- $res->port(9732);</PRE>
- <P>Gets or sets the port to which we send queries. This can be useful
- for testing a nameserver running on a non-standard port. The
- default is port 53.</P>
- <P>
- <H2><A NAME="search">search</A></H2>
- <PRE>
- $packet = $res->search("mailhost");
- $packet = $res->search("mailhost.foo.com");
- $packet = $res->search("192.168.1.1");
- $packet = $res->search("foo.com", "MX");
- $packet = $res->search("user.passwd.foo.com", "TXT", "HS");</PRE>
- <P>Performs a DNS query for the given name, applying the searchlist
- if appropriate. The search algorithm is as follows:</P>
- <OL>
- <LI>
- If the name contains at least one dot, try it as is.
- <P></P>
- <LI>
- If the name doesn't end in a dot then append each item in
- the search list to the name. This is only done if <STRONG>dnsrch</STRONG>
- is true.
- <P></P>
- <LI>
- If the name doesn't contain any dots, try it as is.
- <P></P></OL>
- <P>The record type and class can be omitted; they default to A and
- IN. If the name looks like an IP address (4 dot-separated numbers),
- then an appropriate PTR query will be performed.</P>
- <P>Returns a <CODE>Net::DNS::Packet</CODE> object, or <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> if no answers
- were found.</P>
- <P>
- <H2><A NAME="query">query</A></H2>
- <PRE>
- $packet = $res->query("mailhost");
- $packet = $res->query("mailhost.foo.com");
- $packet = $res->query("192.168.1.1");
- $packet = $res->query("foo.com", "MX");
- $packet = $res->query("user.passwd.foo.com", "TXT", "HS");</PRE>
- <P>Performs a DNS query for the given name; the search list is not
- applied. If the name doesn't contain any dots and <STRONG>defnames</STRONG>
- is true then the default domain will be appended.</P>
- <P>The record type and class can be omitted; they default to A and
- IN. If the name looks like an IP address (4 dot-separated numbers),
- then an appropriate PTR query will be performed.</P>
- <P>Returns a <CODE>Net::DNS::Packet</CODE> object, or <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> if no answers
- were found.</P>
- <P>
- <H2><A NAME="send">send</A></H2>
- <PRE>
- $packet = $res->send($packet_object);
- $packet = $res->send("mailhost.foo.com");
- $packet = $res->send("foo.com", "MX");
- $packet = $res->send("user.passwd.foo.com", "TXT", "HS");</PRE>
- <P>Performs a DNS query for the given name. Neither the searchlist
- nor the default domain will be appended.</P>
- <P>The argument list can be either a <CODE>Net::DNS::Packet</CODE> object or a list
- of strings. The record type and class can be omitted; they default to
- A and IN. If the name looks like an IP address (4 dot-separated numbers),
- then an appropriate PTR query will be performed.</P>
- <P>Returns a <CODE>Net::DNS::Packet</CODE> object whether there were any answers or not.
- Use <CODE>$packet</CODE>-><CODE>header</CODE>-><CODE>ancount</CODE> or <CODE>$packet</CODE>-><CODE>answer</CODE> to find out
- if there were any records in the answer section. Returns <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> if there
- was an error.</P>
- <P>
- <H2><A NAME="bgsend">bgsend</A></H2>
- <PRE>
- $socket = $res->bgsend($packet_object);
- $socket = $res->bgsend("mailhost.foo.com");
- $socket = $res->bgsend("foo.com", "MX");
- $socket = $res->bgsend("user.passwd.foo.com", "TXT", "HS");</PRE>
- <P>Performs a background DNS query for the given name, i.e., sends a
- query packet to the first nameserver listed in <CODE>$res</CODE>-><CODE>nameservers</CODE>
- and returns immediately without waiting for a response. The program
- can then perform other tasks while waiting for a response from the
- nameserver.</P>
- <P>The argument list can be either a <CODE>Net::DNS::Packet</CODE> object or a list
- of strings. The record type and class can be omitted; they default to
- A and IN. If the name looks like an IP address (4 dot-separated numbers),
- then an appropriate PTR query will be performed.</P>
- <P>Returns an <CODE>IO::Socket</CODE> object. The program must determine when
- the socket is ready for reading and call <CODE>$res</CODE>-><CODE>bgread</CODE> to get
- the response packet. You can use <CODE>$res</CODE>-><CODE>bgisready</CODE> or <CODE>IO::Select</CODE>
- to find out if the socket is ready before reading it.</P>
- <P>
- <H2><A NAME="bgread">bgread</A></H2>
- <PRE>
- $packet = $res->bgread($socket);
- undef $socket;</PRE>
- <P>Reads the answer from a background query (see <A HREF="#bgsend">bgsend</A>). The argument
- is an <CODE>IO::Socket</CODE> object returned by <CODE>bgsend</CODE>.</P>
- <P>Returns a <CODE>Net::DNS::Packet</CODE> object or <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> on error.</P>
- <P>The programmer should close or destroy the socket object after reading it.</P>
- <P>
- <H2><A NAME="bgisready">bgisready</A></H2>
- <PRE>
- $socket = $res->bgsend("foo.bar.com");
- until ($res->bgisready($socket)) {
- # do some other processing
- }
- $packet = $res->bgread($socket);
- $socket = undef;</PRE>
- <P>Determines whether a socket is ready for reading. The argument is
- an <CODE>IO::Socket</CODE> object returned by <CODE>$res</CODE>-><CODE>bgsend</CODE>.</P>
- <P>Returns true if the socket is ready, false if not.</P>
- <P>
- <H2><A NAME="axfr">axfr</A></H2>
- <PRE>
- @zone = $res->axfr;
- @zone = $res->axfr("foo.com");
- @zone = $res->axfr("passwd.foo.com", "HS");</PRE>
- <P>Performs a zone transfer from the first nameserver listed in <CODE>nameservers</CODE>.
- If the zone is omitted, it defaults to the first zone listed in the resolver's
- search list. If the class is omitted, it defaults to IN.</P>
- <P>Returns a list of <CODE>Net::DNS::RR</CODE> objects, or <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> if the zone
- transfer failed.</P>
- <P>The redundant SOA record that terminates the zone transfer is not
- returned to the caller.</P>
- <P>Here's an example that uses a timeout:</P>
- <PRE>
- $res->tcp_timeout(10);
- @zone = $res->axfr("foo.com");
- if (@zone) {
- foreach $rr (@zone) {
- $rr->print;
- }
- }
- else {
- print "Zone transfer failed: ", $res->errorstring, "\n";
- }</PRE>
- <P>
- <H2><A NAME="tcp_timeout">tcp_timeout</A></H2>
- <PRE>
- print "TCP timeout: ", $res->tcp_timeout, "\n";
- $res->tcp_timeout(10);</PRE>
- <P>Get or set the TCP timeout in seconds. A timeout of <A HREF="../../../../lib/Pod/perlfunc.html#item_undef"><CODE>undef</CODE></A> means
- indefinite. The default is 120 seconds (2 minutes).</P>
- <P>
- <H2><A NAME="retrans">retrans</A></H2>
- <PRE>
- print "retrans interval: ", $res->retrans, "\n";
- $res->retrans(3);</PRE>
- <P>Get or set the retransmission interval. The default is 5.</P>
- <P>
- <H2><A NAME="retry">retry</A></H2>
- <PRE>
- print "number of tries: ", $res->retry, "\n";
- $res->retry(2);</PRE>
- <P>Get or set the number of times to try the query. The default is 4.</P>
- <P>
- <H2><A NAME="recurse">recurse</A></H2>
- <PRE>
- print "recursion flag: ", $res->recurse, "\n";
- $res->recurse(0);</PRE>
- <P>Get or set the recursion flag. If this is true, nameservers will
- be requested to perform a recursive query. The default is true.</P>
- <P>
- <H2><A NAME="defnames">defnames</A></H2>
- <PRE>
- print "defnames flag: ", $res->defnames, "\n";
- $res->defnames(0);</PRE>
- <P>Get or set the defnames flag. If this is true, calls to <STRONG>query</STRONG> will
- append the default domain to names that contain no dots. The default
- is true.</P>
- <P>
- <H2><A NAME="dnsrch">dnsrch</A></H2>
- <PRE>
- print "dnsrch flag: ", $res->dnsrch, "\n";
- $res->dnsrch(0);</PRE>
- <P>Get or set the dnsrch flag. If this is true, calls to <STRONG>search</STRONG> will
- apply the search list. The default is true.</P>
- <P>
- <H2><A NAME="debug">debug</A></H2>
- <PRE>
- print "debug flag: ", $res->debug, "\n";
- $res->debug(1);</PRE>
- <P>Get or set the debug flag. If set, calls to <STRONG>search</STRONG>, <STRONG>query</STRONG>,
- and <STRONG>send</STRONG> will print debugging information on the standard output.
- The default is false.</P>
- <P>
- <H2><A NAME="usevc">usevc</A></H2>
- <PRE>
- print "usevc flag: ", $res->usevc, "\n";
- $res->usevc(1);</PRE>
- <P>Get or set the usevc flag. If true, then queries will be performed
- using virtual circuits (TCP) instead of datagrams (UDP). The default
- is false.</P>
- <P>
- <H2><A NAME="igntc">igntc</A></H2>
- <PRE>
- print "igntc flag: ", $res->igntc, "\n";
- $res->igntc(1);</PRE>
- <P>Get or set the igntc flag. If true, truncated packets will be
- ignored. If false, truncated packets will cause the query to
- be retried using TCP. The default is false.</P>
- <P>
- <H2><A NAME="errorstring">errorstring</A></H2>
- <PRE>
- print "query status: ", $res->errorstring, "\n";</PRE>
- <P>Returns a string containing the status of the most recent query.</P>
- <P>
- <H2><A NAME="answerfrom">answerfrom</A></H2>
- <PRE>
- print "last answer was from: ", $res->answerfrom, "\n";</PRE>
- <P>Returns the IP address from which we received the last answer in
- response to a query.</P>
- <P>
- <H2><A NAME="answersize">answersize</A></H2>
- <PRE>
- print "size of last answer: ", $res->answersize, "\n";</PRE>
- <P>Returns the size in bytes of the last answer we received in
- response to a query.</P>
- <P>
- <HR>
- <H1><A NAME="environment">ENVIRONMENT</A></H1>
- <P>The following environment variables can also be used to configure
- the resolver:</P>
- <P>
- <H2><A NAME="res_nameservers">RES_NAMESERVERS</A></H2>
- <PRE>
- # Bourne Shell
- RES_NAMESERVERS="192.168.1.1 192.168.2.2 192.168.3.3"
- export RES_NAMESERVERS</PRE>
- <PRE>
- # C Shell
- setenv RES_NAMESERVERS "192.168.1.1 192.168.2.2 192.168.3.3"</PRE>
- <P>A space-separated list of nameservers to query.</P>
- <P>
- <H2><A NAME="res_searchlist">RES_SEARCHLIST</A></H2>
- <PRE>
- # Bourne Shell
- RES_SEARCHLIST="foo.com bar.com baz.org"
- export RES_SEARCHLIST</PRE>
- <PRE>
- # C Shell
- setenv RES_SEARCHLIST "foo.com bar.com baz.org"</PRE>
- <P>A space-separated list of domains to put in the search list.</P>
- <P>
- <H2><A NAME="localdomain">LOCALDOMAIN</A></H2>
- <PRE>
- # Bourne Shell
- LOCALDOMAIN=foo.com
- export LOCALDOMAIN</PRE>
- <PRE>
- # C Shell
- setenv LOCALDOMAIN foo.com</PRE>
- <P>The default domain.</P>
- <P>
- <H2><A NAME="res_options">RES_OPTIONS</A></H2>
- <PRE>
- # Bourne Shell
- RES_OPTIONS="retrans:3 retry:2 debug"
- export RES_OPTIONS</PRE>
- <PRE>
- # C Shell
- setenv RES_OPTIONS "retrans:3 retry:2 debug"</PRE>
- <P>A space-separated list of resolver options to set. Options that
- take values are specified as <EM>option</EM>:<EM>value</EM>.</P>
- <P>
- <HR>
- <H1><A NAME="bugs">BUGS</A></H1>
- <P>Error reporting and handling needs to be improved.</P>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>Copyright (c) 1997 Michael Fuhr. All rights reserved. This program is free
- software; you can redistribute it and/or modify it under the same terms as
- Perl itself.</P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><EM>perl(1)</EM>, <A HREF="../../../../site/lib/Net/DNS.html">the Net::DNS manpage</A>, <A HREF="../../../../site/lib/Net/DNS/Packet.html">the Net::DNS::Packet manpage</A>, <A HREF="../../../../site/lib/Net/DNS/Update.html">the Net::DNS::Update manpage</A>,
- <A HREF="../../../../site/lib/Net/DNS/Header.html">the Net::DNS::Header manpage</A>, <A HREF="../../../../site/lib/Net/DNS/Question.html">the Net::DNS::Question manpage</A>, <A HREF="../../../../site/lib/Net/DNS/RR.html">the Net::DNS::RR manpage</A>,
- <EM>resolver(5)</EM>, RFC 1035, RFC 1034 Section 4.3.5</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::DNS::Resolver - DNS resolver class</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-