ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/DNS.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/DNS.pm (file contents):
Revision 1.2 by root, Fri May 23 02:59:32 2008 UTC vs.
Revision 1.3 by root, Fri May 23 03:20:53 2008 UTC

19 19
20=cut 20=cut
21 21
22package AnyEvent::DNS; 22package AnyEvent::DNS;
23 23
24no warnings;
24use strict; 25use strict;
25 26
26use AnyEvent::Util (); 27use AnyEvent::Util ();
27 28
28=back 29=back
529 while (my $peer = recv $self->{fh}, my $res, 1024, 0) { 530 while (my $peer = recv $self->{fh}, my $res, 1024, 0) {
530 my ($port, $host) = Socket::unpack_sockaddr_in $peer; 531 my ($port, $host) = Socket::unpack_sockaddr_in $peer;
531 532
532 return unless $port == 53 && grep $_ eq $host, @{ $self->{server} }; 533 return unless $port == 53 && grep $_ eq $host, @{ $self->{server} };
533 534
534 $res = AnyEvent::DNS::dns_unpack $res 535 $res = dns_unpack $res
535 or return; 536 or return;
536 537
537 my $id = $self->{id}{$res->{id}}; 538 my $id = $self->{id}{$res->{id}};
538 539
539 return unless ref $id; 540 return unless ref $id;
605} 606}
606 607
607=item $resolver->request ($req, $cb->($res)) 608=item $resolver->request ($req, $cb->($res))
608 609
609Sends a single request (a hash-ref formated as specified for 610Sends a single request (a hash-ref formated as specified for
610C<AnyEvent::DNS::dns_pack>) to the configured nameservers including 611C<dns_pack>) to the configured nameservers including
611retries. Calls the callback with the decoded response packet if a reply 612retries. Calls the callback with the decoded response packet if a reply
612was received, or no arguments on timeout. 613was received, or no arguments on timeout.
613 614
614=cut 615=cut
615 616
616sub request($$) { 617sub request($$) {
617 my ($self, $req, $cb) = @_; 618 my ($self, $req, $cb) = @_;
618 619
619 push @{ $self->{queue} }, [(AnyEvent::DNS::dns_pack $req), $cb]; 620 push @{ $self->{queue} }, [dns_pack $req, $cb];
620 $self->_scheduler; 621 $self->_scheduler;
621} 622}
622 623
623=item $resolver->resolve ($qname, $qtype, %options, $cb->($rcode, @rr)) 624=item $resolver->resolve ($qname, $qtype, %options, $cb->($rcode, @rr))
624 625
627 628
628The callback will be invoked with a list of matching result records or 629The callback will be invoked with a list of matching result records or
629none on any error or if the name could not be found. 630none on any error or if the name could not be found.
630 631
631CNAME chains (although illegal) are followed up to a length of 8. 632CNAME chains (although illegal) are followed up to a length of 8.
633
634Note that this resolver is just a stub resolver: it requires a nameserver
635supporting recursive queries, will not do any recursive queries itself and
636is not secure when used against an untrusted name server.
632 637
633The following options are supported: 638The following options are supported:
634 639
635=over 4 640=over 4
636 641

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines