… | |
… | |
698 | been resolved. |
698 | been resolved. |
699 | |
699 | |
700 | =item reuse => $seconds |
700 | =item reuse => $seconds |
701 | |
701 | |
702 | The number of seconds (default: C<300>) that a query id cannot be re-used |
702 | The number of seconds (default: C<300>) that a query id cannot be re-used |
703 | after a timeout. If there as no time-out then query id's can be reused |
703 | after a timeout. If there was no time-out then query ids can be reused |
704 | immediately. |
704 | immediately. |
705 | |
705 | |
706 | =back |
706 | =back |
707 | |
707 | |
708 | =cut |
708 | =cut |
… | |
… | |
723 | server => [], |
723 | server => [], |
724 | timeout => [2, 5, 5], |
724 | timeout => [2, 5, 5], |
725 | search => [], |
725 | search => [], |
726 | ndots => 1, |
726 | ndots => 1, |
727 | max_outstanding => 10, |
727 | max_outstanding => 10, |
728 | reuse => 300, # reuse id's after 5 minutes only, if possible |
728 | reuse => 300, |
729 | %arg, |
729 | %arg, |
730 | reuse_q => [], |
730 | reuse_q => [], |
731 | }, $class; |
731 | }, $class; |
732 | |
732 | |
733 | # search should default to gethostname's domain |
733 | # search should default to gethostname's domain |
… | |
… | |
838 | # - the registry thing needs separate code on win32 native vs. cygwin |
838 | # - the registry thing needs separate code on win32 native vs. cygwin |
839 | # - the registry layout differs between windows versions |
839 | # - the registry layout differs between windows versions |
840 | # - calling windows api functions doesn't work on cygwin |
840 | # - calling windows api functions doesn't work on cygwin |
841 | # - ipconfig uses locale-specific messages |
841 | # - ipconfig uses locale-specific messages |
842 | |
842 | |
843 | # we use ipconfig parsing because, despite all it's brokenness, |
843 | # we use ipconfig parsing because, despite all its brokenness, |
844 | # it seems most stable in practise. |
844 | # it seems most stable in practise. |
845 | # for good measure, we append a fallback nameserver to our list. |
845 | # for good measure, we append a fallback nameserver to our list. |
846 | |
846 | |
847 | if (open my $fh, "ipconfig /all |") { |
847 | if (open my $fh, "ipconfig /all |") { |
848 | # parsing strategy: we go through the output and look for |
848 | # parsing strategy: we go through the output and look for |
… | |
… | |
857 | } elsif (/^\S/ || /^\s[^:]{16,}: /) { |
857 | } elsif (/^\S/ || /^\s[^:]{16,}: /) { |
858 | $dns = 0; |
858 | $dns = 0; |
859 | } |
859 | } |
860 | if ($dns && /^\s*(\S+)\s*$/) { |
860 | if ($dns && /^\s*(\S+)\s*$/) { |
861 | my $s = $1; |
861 | my $s = $1; |
862 | $s =~ s/%\d+(?!\S)//; # get rid of scope id |
862 | $s =~ s/%\d+(?!\S)//; # get rid of ipv6 scope id |
863 | if (my $ipn = AnyEvent::Socket::parse_address ($s)) { |
863 | if (my $ipn = AnyEvent::Socket::parse_address ($s)) { |
864 | push @{ $self->{server} }, $ipn; |
864 | push @{ $self->{server} }, $ipn; |
865 | } else { |
865 | } else { |
866 | push @{ $self->{search} }, $s; |
866 | push @{ $self->{search} }, $s; |
867 | } |
867 | } |
… | |
… | |
884 | } |
884 | } |
885 | |
885 | |
886 | =item $resolver->timeout ($timeout, ...) |
886 | =item $resolver->timeout ($timeout, ...) |
887 | |
887 | |
888 | Sets the timeout values. See the C<timeout> constructor argument (and note |
888 | Sets the timeout values. See the C<timeout> constructor argument (and note |
889 | that this method uses the values itselt, not an array-reference). |
889 | that this method uses the values itself, not an array-reference). |
890 | |
890 | |
891 | =cut |
891 | =cut |
892 | |
892 | |
893 | sub timeout { |
893 | sub timeout { |
894 | my ($self, @timeout) = @_; |
894 | my ($self, @timeout) = @_; |
… | |
… | |
1094 | } |
1094 | } |
1095 | } |
1095 | } |
1096 | |
1096 | |
1097 | =item $resolver->request ($req, $cb->($res)) |
1097 | =item $resolver->request ($req, $cb->($res)) |
1098 | |
1098 | |
|
|
1099 | This is the main low-level workhorse for sending DNS requests. |
|
|
1100 | |
1099 | Sends a single request (a hash-ref formated as specified for |
1101 | This function sends a single request (a hash-ref formated as specified |
1100 | C<dns_pack>) to the configured nameservers including |
1102 | for C<dns_pack>) to the configured nameservers in turn until it gets a |
|
|
1103 | response. It handles timeouts, retries and automatically falls back to |
|
|
1104 | virtual circuit mode (TCP) when it receives a truncated reply. |
|
|
1105 | |
1101 | retries. Calls the callback with the decoded response packet if a reply |
1106 | Calls the callback with the decoded response packet if a reply was |
1102 | was received, or no arguments on timeout. |
1107 | received, or no arguments in case none of the servers answered. |
1103 | |
1108 | |
1104 | =cut |
1109 | =cut |
1105 | |
1110 | |
1106 | sub request($$) { |
1111 | sub request($$) { |
1107 | my ($self, $req, $cb) = @_; |
1112 | my ($self, $req, $cb) = @_; |
… | |
… | |
1112 | |
1117 | |
1113 | =item $resolver->resolve ($qname, $qtype, %options, $cb->($rcode, @rr)) |
1118 | =item $resolver->resolve ($qname, $qtype, %options, $cb->($rcode, @rr)) |
1114 | |
1119 | |
1115 | Queries the DNS for the given domain name C<$qname> of type C<$qtype>. |
1120 | Queries the DNS for the given domain name C<$qname> of type C<$qtype>. |
1116 | |
1121 | |
1117 | A C<$qtype> is either a numerical query type (e.g. C<1> for A recods) or |
1122 | A C<$qtype> is either a numerical query type (e.g. C<1> for A records) or |
1118 | a lowercase name (you have to look at the source to see which aliases are |
1123 | a lowercase name (you have to look at the source to see which aliases are |
1119 | supported, but all types from RFC 1035, C<aaaa>, C<srv>, C<spf> and a few |
1124 | supported, but all types from RFC 1035, C<aaaa>, C<srv>, C<spf> and a few |
1120 | more are known to this module). A qtype of "*" is supported and means |
1125 | more are known to this module). A C<$qtype> of "*" is supported and means |
1121 | "any" record type. |
1126 | "any" record type. |
1122 | |
1127 | |
1123 | The callback will be invoked with a list of matching result records or |
1128 | The callback will be invoked with a list of matching result records or |
1124 | none on any error or if the name could not be found. |
1129 | none on any error or if the name could not be found. |
1125 | |
1130 | |