… | |
… | |
32 | use strict; |
32 | use strict; |
33 | |
33 | |
34 | use Socket qw(AF_INET SOCK_DGRAM SOCK_STREAM); |
34 | use Socket qw(AF_INET SOCK_DGRAM SOCK_STREAM); |
35 | |
35 | |
36 | use AnyEvent (); |
36 | use AnyEvent (); |
37 | use AnyEvent::Handle (); |
|
|
38 | use AnyEvent::Util qw(AF_INET6); |
37 | use AnyEvent::Util qw(AF_INET6); |
39 | |
38 | |
40 | our $VERSION = 4.411; |
39 | our $VERSION = 4.452; |
41 | |
40 | |
42 | our @DNS_FALLBACK = (v208.67.220.220, v208.67.222.222); |
41 | our @DNS_FALLBACK = (v208.67.220.220, v208.67.222.222); |
43 | |
42 | |
44 | =item AnyEvent::DNS::a $domain, $cb->(@addrs) |
43 | =item AnyEvent::DNS::a $domain, $cb->(@addrs) |
45 | |
44 | |
… | |
… | |
295 | C<$ENV{PERL_ANYEVENT_EDNS0}>, but when set to C<1>, AnyEvent::DNS will use |
294 | C<$ENV{PERL_ANYEVENT_EDNS0}>, but when set to C<1>, AnyEvent::DNS will use |
296 | EDNS0 in all requests. |
295 | EDNS0 in all requests. |
297 | |
296 | |
298 | =cut |
297 | =cut |
299 | |
298 | |
300 | our $EDNS0 = $ENV{PERL_ANYEVENT_EDNS0} * 1; # set to 1 to enable (partial) edns0 |
299 | our $EDNS0 = $ENV{PERL_ANYEVENT_EDNS0}*1; # set to 1 to enable (partial) edns0 |
301 | |
300 | |
302 | our %opcode_id = ( |
301 | our %opcode_id = ( |
303 | query => 0, |
302 | query => 0, |
304 | iquery => 1, |
303 | iquery => 1, |
305 | status => 2, |
304 | status => 2, |
… | |
… | |
655 | |
654 | |
656 | our $RESOLVER; |
655 | our $RESOLVER; |
657 | |
656 | |
658 | sub resolver() { |
657 | sub resolver() { |
659 | $RESOLVER || do { |
658 | $RESOLVER || do { |
660 | $RESOLVER = new AnyEvent::DNS; |
659 | $RESOLVER = new AnyEvent::DNS untaint => 1; |
661 | $RESOLVER->os_config; |
660 | $RESOLVER->os_config; |
662 | $RESOLVER |
661 | $RESOLVER |
663 | } |
662 | } |
664 | } |
663 | } |
665 | |
664 | |
… | |
… | |
703 | =item reuse => $seconds |
702 | =item reuse => $seconds |
704 | |
703 | |
705 | The number of seconds (default: C<300>) that a query id cannot be re-used |
704 | The number of seconds (default: C<300>) that a query id cannot be re-used |
706 | after a timeout. If there was no time-out then query ids can be reused |
705 | after a timeout. If there was no time-out then query ids can be reused |
707 | immediately. |
706 | immediately. |
|
|
707 | |
|
|
708 | =item untaint => $boolean |
|
|
709 | |
|
|
710 | When true, then the resolver will automatically untaint results, and might |
|
|
711 | also ignore certain environment variables. |
708 | |
712 | |
709 | =back |
713 | =back |
710 | |
714 | |
711 | =cut |
715 | =cut |
712 | |
716 | |
… | |
… | |
822 | $self->_compile; |
826 | $self->_compile; |
823 | } |
827 | } |
824 | |
828 | |
825 | =item $resolver->os_config |
829 | =item $resolver->os_config |
826 | |
830 | |
827 | Tries so load and parse F</etc/resolv.conf> on portable operating systems. Tries various |
831 | Tries so load and parse F</etc/resolv.conf> on portable operating |
828 | egregious hacks on windows to force the DNS servers and searchlist out of the system. |
832 | systems. Tries various egregious hacks on windows to force the DNS servers |
|
|
833 | and searchlist out of the system. |
829 | |
834 | |
830 | =cut |
835 | =cut |
831 | |
836 | |
832 | sub os_config { |
837 | sub os_config { |
833 | my ($self) = @_; |
838 | my ($self) = @_; |
… | |
… | |
939 | } |
944 | } |
940 | |
945 | |
941 | sub _feed { |
946 | sub _feed { |
942 | my ($self, $res) = @_; |
947 | my ($self, $res) = @_; |
943 | |
948 | |
|
|
949 | ($res) = $res =~ /^(.*)$/s |
|
|
950 | if AnyEvent::TAINT && $self->{untaint}; |
|
|
951 | |
944 | $res = dns_unpack $res |
952 | $res = dns_unpack $res |
945 | or return; |
953 | or return; |
946 | |
954 | |
947 | my $id = $self->{id}{$res->{id}}; |
955 | my $id = $self->{id}{$res->{id}}; |
948 | |
956 | |
… | |
… | |
1011 | AnyEvent::Socket::tcp_connect (AnyEvent::Socket::format_address ($server), DOMAIN_PORT, sub { |
1019 | AnyEvent::Socket::tcp_connect (AnyEvent::Socket::format_address ($server), DOMAIN_PORT, sub { |
1012 | return unless $do_retry; # some other request could have invalidated us already |
1020 | return unless $do_retry; # some other request could have invalidated us already |
1013 | |
1021 | |
1014 | my ($fh) = @_ |
1022 | my ($fh) = @_ |
1015 | or return &$do_retry; |
1023 | or return &$do_retry; |
|
|
1024 | |
|
|
1025 | require AnyEvent::Handle; |
1016 | |
1026 | |
1017 | my $handle; $handle = new AnyEvent::Handle |
1027 | my $handle; $handle = new AnyEvent::Handle |
1018 | fh => $fh, |
1028 | fh => $fh, |
1019 | timeout => $timeout, |
1029 | timeout => $timeout, |
1020 | on_error => sub { |
1030 | on_error => sub { |