PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|AnyEvent|DNS.pm =

page 9 of 14



         # 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=

1|2|3|4|5|6|7|8| < PREV = PAGE 9 = NEXT > |10|11|12|13|14

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.006634 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)