home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / DNS.pm < prev    next >
Encoding:
Perl POD Document  |  2004-02-24  |  18.0 KB  |  712 lines

  1. package Net::DNS;
  2. #
  3. # $Id: DNS.pm,v 2.107 2004/02/21 12:44:18 ctriv Exp $
  4. #
  5. use strict;
  6. use vars qw(
  7.     $HAVE_XS
  8.     $VERSION
  9.     $DNSSEC
  10.     @ISA
  11.     @EXPORT
  12.     %typesbyname
  13.     %typesbyval
  14.     %qtypesbyname
  15.     %qtypesbyval
  16.     %metatypesbyname
  17.     %metatypesbyval
  18.     %classesbyname
  19.     %classesbyval
  20.     %opcodesbyname
  21.     %opcodesbyval
  22.     %rcodesbyname
  23.     %rcodesbyval
  24. );
  25.  
  26.  
  27.  
  28. BEGIN {
  29.     require DynaLoader;
  30.     require Exporter;
  31.     
  32.     @ISA     = qw(Exporter DynaLoader);
  33.     $VERSION = '0.46';
  34.     $HAVE_XS = eval { __PACKAGE__->bootstrap(); 1 } ? 1 : 0;
  35. }
  36.  
  37. use Net::DNS::Resolver;
  38. use Net::DNS::Packet;
  39. use Net::DNS::Update;
  40. use Net::DNS::Header;
  41. use Net::DNS::Question;
  42. use Net::DNS::RR;
  43.  
  44. BEGIN {
  45.     $DNSSEC = eval { require Net::DNS::RR::SIG; 1 } ? 1 : 0;
  46. }
  47.  
  48.  
  49.  
  50. @EXPORT = qw(mx yxrrset nxrrset yxdomain nxdomain rr_add rr_del);
  51.  
  52. #
  53. # If you implement an RR record make sure you also add it to 
  54. # %Net::DNS::RR::RR hash otherwise it will be treated as unknown type.
  55.  
  56. # Do not use these tybesby hashes directly. Use the interface
  57. # functions, see below.
  58.  
  59. %typesbyname = (
  60.      'SIGZERO'   => 0,       # RFC2931 consider this a pseudo type
  61.     'A'            => 1,        # RFC 1035, Section 3.4.1
  62.     'NS'        => 2,        # RFC 1035, Section 3.3.11
  63.     'MD'        => 3,        # RFC 1035, Section 3.3.4 (obsolete)
  64.     'MF'        => 4,        # RFC 1035, Section 3.3.5 (obsolete)
  65.     'CNAME'        => 5,        # RFC 1035, Section 3.3.1
  66.     'SOA'        => 6,        # RFC 1035, Section 3.3.13
  67.     'MB'        => 7,        # RFC 1035, Section 3.3.3
  68.     'MG'        => 8,        # RFC 1035, Section 3.3.6
  69.     'MR'        => 9,        # RFC 1035, Section 3.3.8
  70.     'NULL'        => 10,        # RFC 1035, Section 3.3.10
  71.     'WKS'        => 11,        # RFC 1035, Section 3.4.2 (deprecated)
  72.     'PTR'        => 12,        # RFC 1035, Section 3.3.12
  73.     'HINFO'        => 13,        # RFC 1035, Section 3.3.2
  74.     'MINFO'     => 14,        # RFC 1035, Section 3.3.7
  75.     'MX'        => 15,        # RFC 1035, Section 3.3.9
  76.     'TXT'        => 16,        # RFC 1035, Section 3.3.14
  77.     'RP'        => 17,        # RFC 1183, Section 2.2
  78.     'AFSDB'        => 18,        # RFC 1183, Section 1
  79.     'X25'        => 19,        # RFC 1183, Section 3.1
  80.     'ISDN'        => 20,        # RFC 1183, Section 3.2
  81.     'RT'        => 21,        # RFC 1183, Section 3.3
  82.     'NSAP'        => 22,        # RFC 1706, Section 5
  83.     'NSAP_PTR'    => 23,        # RFC 1348 (obsolete)
  84.     # The following 2 RRs are impemented in Net::DNS::SEC
  85.      'SIG'        => 24,        # RFC 2535, Section 4.1
  86.      'KEY'        => 25,        # RFC 2535, Section 3.1
  87.      'PX'        => 26,        # RFC 2163,
  88.     'GPOS'        => 27,        # RFC 1712 (obsolete)
  89.     'AAAA'        => 28,        # RFC 1886, Section 2.1
  90.     'LOC'        => 29,        # RFC 1876
  91.     # The following RR is impemented in Net::DNS::SEC
  92.     'NXT'        => 30,        # RFC 2535, Section 5.2
  93.     'EID'        => 31,        # draft-ietf-nimrod-dns-xx.txt
  94.     'NIMLOC'    => 32,        # draft-ietf-nimrod-dns-xx.txt
  95.     'SRV'        => 33,        # RFC 2052
  96.     'ATMA'        => 34,        # ???
  97.     'NAPTR'        => 35,        # RFC 2168
  98.     'KX'        => 36,        # RFC 2230
  99.      'CERT'        => 37,        # RFC 2538
  100.     'DNAME'        => 39,        # RFC 2672
  101.     'OPT'          => 41,        # RFC 2671
  102.     # The following 4 RRs are impemented in Net::DNS::SEC
  103.     # Aug 2003: These RRs will be published as RFCs shortly 
  104.     'DS'        => 43,        # draft-ietf-dnsext-delegation-signer
  105.     'RRSIG'        => 46,        # draft-ietf-dnsext-dnssec-2535typecode-change
  106.     'NSEC'        => 47,        # draft-ietf-dnsext-dnssec-2535typecode-change
  107.     'DNSKEY'    => 48,        # draft-ietf-dnsext-dnssec-2535typecode-change
  108.     'UINFO'        => 100,        # non-standard
  109.     'UID'        => 101,        # non-standard
  110.     'GID'        => 102,        # non-standard
  111.     'UNSPEC'    => 103,        # non-standard
  112.     'TKEY'        => 249,        # RFC 2930
  113.     'TSIG'        => 250,        # RFC 2931
  114.     'IXFR'        => 251,        # RFC 1995
  115.     'AXFR'        => 252,        # RFC 1035
  116.     'MAILB'        => 253,        # RFC 1035 (MB, MG, MR)
  117.     'MAILA'        => 254,        # RFC 1035 (obsolete - see MX)
  118.     'ANY'        => 255,        # RFC 1035
  119. );
  120. %typesbyval = reverse %typesbyname;
  121.  
  122.  
  123. #
  124. # typesbyval and typesbyname functions are wrappers around the similarly named
  125. # hashes. They are used for 'unknown' DNS RR types (RFC3597)
  126.  
  127. # typesbyname returns they TYPEcode as a function of the TYPE
  128. # mnemonic. If the TYPE mapping is not specified the generic mnemonic
  129. # TYPE### is returned.
  130.  
  131.  
  132. # typesbyval returns they TYPE mnemonic as a function of the TYPE
  133. # code. If the TYPE mapping is not specified the generic mnemonic
  134. # TYPE### is returned.
  135. #
  136.  
  137. sub typesbyname {
  138.     my $name = uc shift;
  139.  
  140.     return $typesbyname{$name} if $typesbyname{$name};
  141.     
  142.     die "Net::DNS::typesbyval() argument is not TYPE### ($name)" unless 
  143.         $name =~ m/^\s*TYPE(\d+)\s*$/;  
  144.     
  145.     my $val = $1;
  146.     
  147.     die 'Net::DNS::typesbyval() argument larger than ' . 0xffff if $val > 0xffff;
  148.     
  149.     return $val;
  150. }
  151.  
  152.  
  153.  
  154. sub typesbyval {
  155.     my $val = shift;
  156.     
  157.     die "Net::DNS::typesbyname() argument is not numeric ($val)" unless 
  158.         $val =~ m/^\s*\d+\s*$/;  
  159.     
  160.     $val =~ s/\s*//g; 
  161.     $val =~ s/^0*//; 
  162.     
  163.     return $typesbyval{$val} if $typesbyval{$val};
  164.     
  165.     die 'Net::DNS::typesbyname() argument larger than '. 0xffff if 
  166.         $val > 0xffff;
  167.     
  168.     return "TYPE$val";
  169. }
  170.  
  171.  
  172.  
  173. #
  174. # Do not use these classesby hashes directly. See below. 
  175. #
  176.  
  177. %classesbyname = (
  178.     'IN'        => 1,        # RFC 1035
  179.     'CH'        => 3,        # RFC 1035
  180.     'HS'        => 4,        # RFC 1035
  181.     'NONE'        => 254,        # RFC 2136
  182.     'ANY'        => 255,        # RFC 1035
  183. );
  184. %classesbyval = reverse %classesbyname;
  185.  
  186.  
  187.  
  188. # classesbyval and classesbyname functions are wrappers around the
  189. # similarly named hashes. They are used for 'unknown' DNS RR classess
  190. # (RFC3597)
  191.  
  192. # See typesbyval and typesbyname, these beasts have the same functionality
  193.  
  194. sub classesbyname {
  195.     my $name = uc shift;
  196.     return $classesbyname{$name} if $classesbyname{$name};
  197.     
  198.     die "Net::DNS::classesbyval() argument is not CLASS### ($name)" unless 
  199.         $name =~ m/^\s*CLASS(\d+)\s*$/;
  200.     
  201.     my $val = $1;
  202.     
  203.     die 'Net::DNS::classesbyval() argument larger than '. 0xffff if $val > 0xffff;
  204.     
  205.     return $val;
  206. }
  207.  
  208.  
  209.  
  210. sub classesbyval {
  211.     my $val = shift;
  212.     
  213.     die "Net::DNS::classesbyname() argument is not numeric ($val)" unless 
  214.         $val=~/^\s*\d+\s*$/;
  215.     
  216.     $val =~ s/\s*//g;
  217.     $val =~ s/^0*//;
  218.     
  219.     return $classesbyval{$val} if $classesbyval{$val};
  220.     
  221.     die 'Net::DNS::classesbyname() argument larger than ' . 0xffff if $val > 0xffff;
  222.     
  223.     return "CLASS$val";
  224. }
  225.  
  226.  
  227.  
  228. # The qtypesbyval and metatypesbyval specify special typecodes
  229. # See rfc2929 and the relevant IANA registry
  230. # http://www.iana.org/assignments/dns-parameters
  231.  
  232.  
  233. %qtypesbyname = (
  234.     'IXFR'   => 251,  # incremental transfer                [RFC1995]
  235.     'AXFR'   => 252,  # transfer of an entire zone          [RFC1035]
  236.     'MAILB'  => 253,  # mailbox-related RRs (MB, MG or MR)     [RFC1035]
  237.     'MAILA'  => 254,  # mail agent RRs (Obsolete - see MX)     [RFC1035]
  238.     'ANY'    => 255,  # all records                         [RFC1035]
  239. );
  240. %qtypesbyval = reverse %qtypesbyname;
  241.  
  242.  
  243. %metatypesbyname = (
  244.     'TKEY'        => 249,    # Transaction Key   [RFC2930]
  245.     'TSIG'        => 250,    # Transaction Signature  [RFC2845]
  246.     'OPT'         => 41,     # RFC 2671
  247. );
  248. %metatypesbyval = reverse %metatypesbyname;
  249.  
  250.  
  251. %opcodesbyname = (
  252.     'QUERY'           => 0,        # RFC 1035
  253.     'IQUERY'       => 1,        # RFC 1035
  254.     'STATUS'       => 2,        # RFC 1035
  255.     'NS_NOTIFY_OP' => 4,        # RFC 1996
  256.     'UPDATE'       => 5,        # RFC 2136
  257. );
  258. %opcodesbyval = reverse %opcodesbyname;
  259.  
  260.  
  261. %rcodesbyname = (
  262.     'NOERROR'    => 0,        # RFC 1035
  263.     'FORMERR'    => 1,        # RFC 1035
  264.     'SERVFAIL'    => 2,        # RFC 1035
  265.     'NXDOMAIN'    => 3,        # RFC 1035
  266.     'NOTIMP'    => 4,        # RFC 1035
  267.     'REFUSED'    => 5,        # RFC 1035
  268.     'YXDOMAIN'    => 6,        # RFC 2136
  269.     'YXRRSET'    => 7,        # RFC 2136
  270.     'NXRRSET'    => 8,        # RFC 2136
  271.     'NOTAUTH'    => 9,        # RFC 2136
  272.     'NOTZONE'    => 10,        # RFC 2136
  273. );
  274. %rcodesbyval = reverse %rcodesbyname;
  275.  
  276.  
  277. sub version      { $VERSION; }
  278. sub PACKETSZ  () { 512; }
  279. sub HFIXEDSZ  () {  12; }
  280. sub QFIXEDSZ  () {   4; }
  281. sub RRFIXEDSZ () {  10; }
  282. sub INT32SZ   () {   4; }
  283. sub INT16SZ   () {   2; }
  284.  
  285.  
  286.  
  287. # mx()
  288. #
  289. # Usage:
  290. #    my @mxes = mx('example.com', 'IN');
  291. #
  292. sub mx {
  293.     my $res = ref $_[0] ? shift : Net::DNS::Resolver->new;
  294.  
  295.     my ($name, $class) = @_;
  296.     $class ||= 'IN';
  297.  
  298.     my $ans = $res->query($name, 'MX', $class) || return;
  299.  
  300.     # This construct is best read backwords.
  301.     #
  302.     # First we take the answer secion of the packet.
  303.     # Then we take just the MX records from that list
  304.     # Then we sort the list by preference
  305.     # Then we return it.
  306.     # We do this into an array to force list context.
  307.     my @ret = sort { $a->preference <=> $b->preference } 
  308.                  grep { $_->type eq 'MX'} $ans->answer;
  309.  
  310.  
  311.     return @ret;
  312. }
  313.  
  314. sub yxrrset {
  315.     return Net::DNS::RR->new_from_string(shift, 'yxrrset');
  316. }
  317.  
  318. sub nxrrset {
  319.     return Net::DNS::RR->new_from_string(shift, 'nxrrset');
  320. }
  321.  
  322. sub yxdomain {
  323.     return Net::DNS::RR->new_from_string(shift, 'yxdomain');
  324. }
  325.  
  326. sub nxdomain {
  327.     return Net::DNS::RR->new_from_string(shift, 'nxdomain');
  328. }
  329.  
  330. sub rr_add {
  331.     return Net::DNS::RR->new_from_string(shift, 'rr_add');
  332. }
  333.  
  334. sub rr_del {
  335.     return Net::DNS::RR->new_from_string(shift, 'rr_del');
  336. }
  337.  
  338. 1;
  339. __END__
  340.  
  341. =head1 NAME
  342.  
  343. Net::DNS - Perl interface to the DNS resolver
  344.  
  345. =head1 SYNOPSIS
  346.  
  347. C<use Net::DNS;>
  348.  
  349. =head1 DESCRIPTION
  350.  
  351. Net::DNS is a collection of Perl modules that act as a Domain
  352. Name System (DNS) resolver.  It allows the programmer to perform
  353. DNS queries that are beyond the capabilities of C<gethostbyname>
  354. and C<gethostbyaddr>.
  355.  
  356. The programmer should be somewhat familiar with the format of
  357. a DNS packet and its various sections.  See RFC 1035 or
  358. I<DNS and BIND> (Albitz & Liu) for details.
  359.  
  360. =head2 Resolver Objects
  361.  
  362. A resolver object is an instance of the
  363. L<Net::DNS::Resolver|Net::DNS::Resolver> class. A program can have
  364. multiple resolver objects, each maintaining its own state information
  365. such as the nameservers to be queried, whether recursion is desired,
  366. etc.
  367.  
  368. =head2 Packet Objects
  369.  
  370. L<Net::DNS::Resolver|Net::DNS::Resolver> queries return
  371. L<Net::DNS::Packet|Net::DNS::Packet> objects.  Packet objects have five
  372. sections:
  373.  
  374. =over 3
  375.  
  376. =item *
  377.  
  378. The header section, a L<Net::DNS::Header|Net::DNS::Header> object.
  379.  
  380. =item *
  381.  
  382. The question section, a list of L<Net::DNS::Question|Net::DNS::Question>
  383. objects.
  384.  
  385. =item *
  386.  
  387. The answer section, a list of L<Net::DNS::RR|Net::DNS::RR> objects.
  388.  
  389. =item *
  390.  
  391. The authority section, a list of L<Net::DNS::RR|Net::DNS::RR> objects.
  392.  
  393. =item *
  394.  
  395. The additional section, a list of L<Net::DNS::RR|Net::DNS::RR> objects.
  396.  
  397. =back
  398.  
  399. =head2 Update Objects
  400.  
  401. The L<Net::DNS::Update|Net::DNS::Update> package is a subclass of
  402. L<Net::DNS::Packet|Net::DNS::Packet> for creating packet objects to be
  403. used in dynamic updates.  
  404.  
  405. =head2 Header Objects
  406.  
  407. L<Net::DNS::Header|Net::DNS::Header> objects represent the header
  408. section of a DNS packet.
  409.  
  410. =head2 Question Objects
  411.  
  412. L<Net::DNS::Question|Net::DNS::Question> objects represent the question
  413. section of a DNS packet.
  414.  
  415. =head2 RR Objects
  416.  
  417. L<Net::DNS::RR|Net::DNS::RR> is the base class for DNS resource record
  418. (RR) objects in the answer, authority, and additional sections of a DNS
  419. packet.
  420.  
  421. Don't assume that RR objects will be of the type you requested -- always
  422. check an RR object's type before calling any of its methods.
  423.  
  424. =head1 METHODS
  425.  
  426. See the manual pages listed above for other class-specific methods.
  427.  
  428. =head2 version
  429.  
  430.     print Net::DNS->version, "\n";
  431.  
  432. Returns the version of Net::DNS.
  433.  
  434. =head2 mx
  435.  
  436.     # Use a default resolver -- can't get an error string this way.
  437.     use Net::DNS;
  438.     my @mx = mx("example.com");
  439.  
  440.     # Use your own resolver object.
  441.     use Net::DNS;
  442.     my $res = Net::DNS::Resolver->new;
  443.     my  @mx = mx($res, "example.com");
  444.  
  445. Returns a list of L<Net::DNS::RR::MX|Net::DNS::RR::MX> objects
  446. representing the MX records for the specified name; the list will be
  447. sorted by preference. Returns an empty list if the query failed or no MX
  448. records were found.
  449.  
  450. This method does not look up A records -- it only performs MX queries.
  451.  
  452. See L</EXAMPLES> for a more complete example.
  453.  
  454. =head2 yxrrset
  455.  
  456. Use this method to add an "RRset exists" prerequisite to a dynamic
  457. update packet.  There are two forms, value-independent and
  458. value-dependent:
  459.  
  460.     # RRset exists (value-independent)
  461.     $update->push(pre => yxrrset("host.example.com A"));
  462.  
  463. Meaning:  At least one RR with the specified name and type must
  464. exist.
  465.  
  466.     # RRset exists (value-dependent)
  467.     $packet->push(pre => yxrrset("host.example.com A 10.1.2.3"));
  468.  
  469. Meaning:  At least one RR with the specified name and type must
  470. exist and must have matching data.
  471.  
  472. Returns a C<Net::DNS::RR> object or C<undef> if the object couldn't
  473. be created.
  474.  
  475. =head2 nxrrset
  476.  
  477. Use this method to add an "RRset does not exist" prerequisite to
  478. a dynamic update packet.
  479.  
  480.     $packet->push(pre => nxrrset("host.example.com A"));
  481.  
  482. Meaning:  No RRs with the specified name and type can exist.
  483.  
  484. Returns a C<Net::DNS::RR> object or C<undef> if the object couldn't
  485. be created.
  486.  
  487. =head2 yxdomain
  488.  
  489. Use this method to add a "name is in use" prerequisite to a dynamic
  490. update packet.
  491.  
  492.     $packet->push(pre => yxdomain("host.example.com"));
  493.  
  494. Meaning:  At least one RR with the specified name must exist.
  495.  
  496. Returns a C<Net::DNS::RR> object or C<undef> if the object couldn't
  497. be created.
  498.  
  499. =head2 nxdomain
  500.  
  501. Use this method to add a "name is not in use" prerequisite to a
  502. dynamic update packet.
  503.  
  504.     $packet->push(pre => nxdomain("host.example.com"));
  505.  
  506. Meaning:  No RR with the specified name can exist.
  507.  
  508. Returns a C<Net::DNS::RR> object or C<undef> if the object couldn't
  509. be created.
  510.  
  511. =head2 rr_add
  512.  
  513. Use this method to add RRs to a zone.
  514.  
  515.     $packet->push(update => rr_add("host.example.com A 10.1.2.3"));
  516.  
  517. Meaning:  Add this RR to the zone.
  518.  
  519. RR objects created by this method should be added to the "update"
  520. section of a dynamic update packet.  The TTL defaults to 86400
  521. seconds (24 hours) if not specified.
  522.  
  523. Returns a C<Net::DNS::RR> object or C<undef> if the object couldn't
  524. be created.
  525.  
  526. =head2 rr_del
  527.  
  528. Use this method to delete RRs from a zone.  There are three forms:
  529. delete an RRset, delete all RRsets, and delete an RR.
  530.  
  531.     # Delete an RRset.
  532.     $packet->push(update => rr_del("host.example.com A"));
  533.  
  534. Meaning:  Delete all RRs having the specified name and type.
  535.  
  536.     # Delete all RRsets.
  537.     $packet->push(update => rr_del("host.example.com"));
  538.  
  539. Meaning:  Delete all RRs having the specified name.
  540.  
  541.     # Delete an RR.
  542.     $packet->push(update => rr_del("host.example.com A 10.1.2.3"));
  543.  
  544. Meaning:  Delete all RRs having the specified name, type, and data.
  545.  
  546. RR objects created by this method should be added to the "update"
  547. section of a dynamic update packet.
  548.  
  549. Returns a C<Net::DNS::RR> object or C<undef> if the object couldn't
  550. be created.
  551.  
  552. =head1 EXAMPLES
  553.  
  554. The following examples show how to use the C<Net::DNS> modules.
  555. See the other manual pages and the demo scripts included with the
  556. source code for additional examples.
  557.  
  558. See the C<Net::DNS::Update> manual page for an example of performing
  559. dynamic updates.
  560.  
  561. =head2 Look up a host's addresses.
  562.  
  563.   use Net::DNS;
  564.   my $res   = Net::DNS::Resolver->new;
  565.   my $query = $res->search("host.example.com");
  566.  
  567.   if ($query) {
  568.       foreach my $rr ($query->answer) {
  569.           next unless $rr->type eq "A";
  570.           print $rr->address, "\n";
  571.       }
  572.   } else {
  573.       warn "query failed: ", $res->errorstring, "\n";
  574.   }
  575.  
  576. =head2 Find the nameservers for a domain.
  577.  
  578.   use Net::DNS;
  579.   my $res   = Net::DNS::Resolver->new;
  580.   my $query = $res->query("example.com", "NS");
  581.  
  582.   if ($query) {
  583.       foreach $rr (grep { $_->type eq 'NS' } $query->answer) {
  584.           print $rr->nsdname, "\n";
  585.       }
  586.   }
  587.   else {
  588.       warn "query failed: ", $res->errorstring, "\n";
  589.   }
  590.  
  591. =head2 Find the MX records for a domain.
  592.  
  593.   use Net::DNS;
  594.   my $name = "example.com";
  595.   my $res  = Net::DNS::Resolver->new;
  596.   my @mx   = mx($res, $name);
  597.  
  598.   if (@mx) {
  599.       foreach $rr (@mx) {
  600.           print $rr->preference, " ", $rr->exchange, "\n";
  601.       }
  602.   } else {
  603.       warn "Can't find MX records for $name: ", $res->errorstring, "\n";
  604.   }
  605.  
  606.  
  607. =head2 Print a domain's SOA record in zone file format.
  608.  
  609.   use Net::DNS;
  610.   my $res   = Net::DNS::Resolver->new;
  611.   my $query = $res->query("example.com", "SOA");
  612.  
  613.   if ($query) {
  614.       ($query->answer)[0]->print;
  615.   } else {
  616.       print "query failed: ", $res->errorstring, "\n";
  617.   }
  618.  
  619. =head2 Perform a zone transfer and print all the records.
  620.  
  621.   use Net::DNS;
  622.   my $res  = Net::DNS::Resolver->new;
  623.   $res->nameservers("ns.example.com");
  624.  
  625.   my @zone = $res->axfr("example.com");
  626.  
  627.   foreach $rr (@zone) {
  628.       $rr->print;
  629.   }
  630.  
  631. =head2 Perform a background query and do some other work while waiting
  632. for the answer.
  633.  
  634.   use Net::DNS;
  635.   my $res    = Net::DNS::Resolver->new;
  636.   my $socket = $res->bgsend("host.example.com");
  637.  
  638.   until ($res->bgisready($socket)) {
  639.       # do some work here while waiting for the answer
  640.       # ...and some more here
  641.   }
  642.  
  643.   my $packet = $res->bgread($socket);
  644.   $packet->print;
  645.  
  646.  
  647. =head2 Send a background query and use select to determine when the answer
  648. has arrived.
  649.  
  650.   use Net::DNS;
  651.   use IO::Select;
  652.  
  653.   my $timeout = 5;
  654.   my $res     = Net::DNS::Resolver->new;
  655.   my $bgsock  = $res->bgsend("host.example.com");
  656.   my $sel     = IO::Select->new($bgsock);
  657.  
  658.   # Add more sockets to $sel if desired.
  659.   my @ready = $sel->can_read($timeout);
  660.   if (@ready) {
  661.       foreach my $sock (@ready) {
  662.           if ($sock == $bgsock) {
  663.               my $packet = $res->bgread($bgsock);
  664.               $packet->print;
  665.               $bgsock = undef;
  666.           }
  667.           # Check for the other sockets.
  668.           $sel->remove($sock);
  669.           $sock = undef;
  670.       }
  671.   } else {
  672.       warn "timed out after $timeout seconds\n";
  673.   }
  674.  
  675. =head1 BUGS
  676.  
  677. C<Net::DNS> is slow.
  678.  
  679. For other items to be fixed, please see the TODO file included with
  680. the source distribution.
  681.  
  682. =head1 COPYRIGHT
  683.  
  684. Copyright (c) 1997-2002 Michael Fuhr. 
  685.  
  686. Portions Copyright (c) 2002-2003 Chris Reinhardt.
  687.  
  688. All rights reserved.  This program is free software; you may redistribute
  689. it and/or modify it under the same terms as Perl itself.
  690.  
  691. =head1 AUTHOR INFORMATION
  692.  
  693. Net::DNS is currently maintained by a group, led by:
  694.     Chris Reinhardt
  695.     ctriv@net-dns.org
  696.  
  697. Net::DNS was created by:
  698.     Michael Fuhr
  699.     mike@fuhr.org
  700.  
  701. For more information see:
  702.     http://www.net-dns.org/
  703.  
  704. =head1 SEE ALSO
  705.  
  706. L<perl(1)>, L<Net::DNS::Resolver>, L<Net::DNS::Packet>, L<Net::DNS::Update>,
  707. L<Net::DNS::Header>, L<Net::DNS::Question>, L<Net::DNS::RR>, RFC 1035,
  708. I<DNS and BIND> by Paul Albitz & Cricket Liu
  709.  
  710. =cut
  711.