… | |
… | |
19 | |
19 | |
20 | =cut |
20 | =cut |
21 | |
21 | |
22 | package AnyEvent::DNS; |
22 | package AnyEvent::DNS; |
23 | |
23 | |
|
|
24 | no warnings; |
24 | use strict; |
25 | use strict; |
25 | |
26 | |
26 | use AnyEvent::Util (); |
27 | use 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 | |
609 | Sends a single request (a hash-ref formated as specified for |
610 | Sends a single request (a hash-ref formated as specified for |
610 | C<AnyEvent::DNS::dns_pack>) to the configured nameservers including |
611 | C<dns_pack>) to the configured nameservers including |
611 | retries. Calls the callback with the decoded response packet if a reply |
612 | retries. Calls the callback with the decoded response packet if a reply |
612 | was received, or no arguments on timeout. |
613 | was received, or no arguments on timeout. |
613 | |
614 | |
614 | =cut |
615 | =cut |
615 | |
616 | |
616 | sub request($$) { |
617 | sub 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 | |
628 | The callback will be invoked with a list of matching result records or |
629 | The callback will be invoked with a list of matching result records or |
629 | none on any error or if the name could not be found. |
630 | none on any error or if the name could not be found. |
630 | |
631 | |
631 | CNAME chains (although illegal) are followed up to a length of 8. |
632 | CNAME chains (although illegal) are followed up to a length of 8. |
|
|
633 | |
|
|
634 | Note that this resolver is just a stub resolver: it requires a nameserver |
|
|
635 | supporting recursive queries, will not do any recursive queries itself and |
|
|
636 | is not secure when used against an untrusted name server. |
632 | |
637 | |
633 | The following options are supported: |
638 | The following options are supported: |
634 | |
639 | |
635 | =over 4 |
640 | =over 4 |
636 | |
641 | |