ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/DNS.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/DNS.pm (file contents):
Revision 1.13 by root, Fri May 23 06:42:53 2008 UTC vs.
Revision 1.14 by root, Fri May 23 16:00:36 2008 UTC

526our $RESOLVER; 526our $RESOLVER;
527 527
528sub resolver() { 528sub resolver() {
529 $RESOLVER || do { 529 $RESOLVER || do {
530 $RESOLVER = new AnyEvent::DNS; 530 $RESOLVER = new AnyEvent::DNS;
531 $RESOLVER->load_resolv_conf; 531 $RESOLVER->os_config;
532 $RESOLVER 532 $RESOLVER
533 } 533 }
534} 534}
535 535
536=item $resolver = new AnyEvent::DNS key => value... 536=item $resolver = new AnyEvent::DNS key => value...
611} 611}
612 612
613=item $resolver->parse_resolv_conv ($string) 613=item $resolver->parse_resolv_conv ($string)
614 614
615Parses the given string a sif it were a F<resolv.conf> file. The following 615Parses the given string a sif it were a F<resolv.conf> file. The following
616directives are supported: 616directives are supported (but not neecssarily implemented).
617 617
618C<#>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>, 618C<#>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>,
619C<options> (C<timeout>, C<attempts>, C<ndots>). 619C<options> (C<timeout>, C<attempts>, C<ndots>).
620 620
621Everything else is silently ignored. 621Everything else is silently ignored.
665 if $attempts; 665 if $attempts;
666 666
667 $self->_compile; 667 $self->_compile;
668} 668}
669 669
670=item $resolver->load_resolv_conf 670=item $resolver->os_config
671 671
672Tries to load and parse F</etc/resolv.conf>. If there will ever be windows 672Tries so load and parse F</etc/resolv.conf> on portable opertaing systems. Tries various
673support, then this function will do the right thing under windows, too. 673egregious hacks on windows to force the dns servers and searchlist out of the config.
674 674
675=cut 675=cut
676 676
677sub load_resolv_conf { 677sub os_config {
678 my ($self) = @_; 678 my ($self) = @_;
679 679
680 if ($^O =~ /mswin32|cygwin/i) {
681 # yeah, it suxx... lets hope DNS is DNS in all locales
682
683 if (open my $fh, "ipconfig /all |") {
684 delete $self->{server};
685 delete $self->{search};
686
687 while (<$fh>) {
688 # first DNS.* is suffix list
689 if (/^\s*DNS/) {
690 while (/\s+([[:alnum:].\-]+)\s*$/) {
691 push @{ $self->{search} }, $1;
692 $_ = <$fh>;
693 }
694 last;
695 }
696 }
697
698 while (<$fh>) {
699 # second DNS.* is server address list
700 if (/^\s*DNS/) {
701 while (/\s+(\d+\.\d+\.\d+\.\d+)\s*$/) {
702 my $ip = $1;
703 push @{ $self->{server} }, AnyEvent::Util::socket_inet_aton $ip
704 if AnyEvent::Util::dotted_quad $ip;
705 $_ = <$fh>;
706 }
707 last;
708 }
709 }
710
711 $self->_compile;
712 }
713 } else {
714 # try resolv.conf everywhere
715
680 open my $fh, "</etc/resolv.conf" 716 if (open my $fh, "</etc/resolv.conf") {
681 or return;
682
683 local $/; 717 local $/;
684 $self->parse_resolv_conf (<$fh>); 718 $self->parse_resolv_conf (<$fh>);
719 }
720 }
685} 721}
686 722
687sub _compile { 723sub _compile {
688 my $self = shift; 724 my $self = shift;
689 725

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines