# ignored, NYI
} elsif (/^\s*options\s+(.*?)\s*$/i) {
for (split /\s+/, $1) {
if (/^timeout:(\d+)$/) {
$self->{timeout} = [$1];
} elsif (/^attempts:(\d+)$/) {
$attempts = $1;
} elsif (/^ndots:(\d+)$/) {
$self->{ndots} = $1;
} else {
# debug, rotate, no-check-names, inet6
}
}
}
}
$self->{timeout} = [($self->{timeout}[0]) x $attempts]
if $attempts;
$self->_compile;
}
=item $resolver->os_config
Tries so load and parse F</etc/resolv.conf> on portable operating systems. Tries various
egregious hacks on windows to force the DNS servers and searchlist out of the system.
=cut
sub os_config {
my ($self) = @_;
$self->{server} = [];
$self->{search} = [];
if (AnyEvent::WIN32 || $^O =~ /cygwin/i) {
no strict 'refs';
# there are many options to find the current nameservers etc. on windows
# all of them don't work consistently:
# - the registry thing needs separate code on win32 native vs. cygwin
# - the registry layout differs between windows versions
# - calling windows api functions doesn't work on cygwin
# - ipconfig uses locale-specific messages
# we use ipconfig parsing because, despite all its brokenness,
# it seems most stable in practise.
# for good measure, we append a fallback nameserver to our list.
if (open my $fh, "ipconfig /all |") {
# parsing strategy: we go through the output and look for
# :-lines with DNS in them. everything in those is regarded as
# either a nameserver (if it parses as an ip address), or a suffix
# (all else).
my $dns;
while (<$fh>) {
if (s/^\s.*\bdns\b.*://i) {
$dns = 1;
} elsif (/^\S/ || /^\s[^:]{16,}: /) {
$dns = 0;
}
if ($dns && /^\s*(\S+)\s*$/) {
my $s = $1;
$s =~ s/%\d+(?!\S)//; # get rid of ipv6 scope id
if (my $ipn = AnyEvent::Socket::parse_address ($s)) {
push @{ $self->{server} }, $ipn;
} else {
push @{ $self->{search} }, $s;
}
}
}
# always add one fallback server
push @{ $self->{server} }, $DNS_FALLBACK[rand @DNS_FALLBACK];
$self->_compile;
}
} else {
# try resolv.conf everywhere
if (open my $fh, "</etc/resolv.conf") {
local $/;
$self->parse_resolv_conf (<$fh>);
}
}
}
=item $resolver->timeout ($timeout, ...)
Sets the timeout values. See the C<timeout> constructor argument (and note
that this method uses the values itself, not an array-reference).
=cut
sub timeout {
my ($self, @timeout) = @_;
$self->{timeout} = \@timeout;
$self->_compile;
=9= |