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.24 by root, Sat May 24 02:50:45 2008 UTC vs.
Revision 1.25 by root, Sat May 24 17:21:50 2008 UTC

231 # resolve a records / provide sockaddr structures 231 # resolve a records / provide sockaddr structures
232 my $resolve = sub { 232 my $resolve = sub {
233 my @res; 233 my @res;
234 my $cv = AnyEvent->condvar (cb => sub { 234 my $cv = AnyEvent->condvar (cb => sub {
235 $cb->( 235 $cb->(
236 map $_->[1], 236 map $_->[2],
237 sort { 237 sort {
238 $AnyEvent::PROTOCOL{$a->[1][0]} <=> $AnyEvent::PROTOCOL{$b->[1][0]} 238 $AnyEvent::PROTOCOL{$a->[1]} <=> $AnyEvent::PROTOCOL{$b->[1]}
239 or $a->[0] <=> $b->[0] 239 or $a->[0] <=> $b->[0]
240 } 240 }
241 @res 241 @res
242 ) 242 )
243 }); 243 });
246 for my $idx (0 .. $#target) { 246 for my $idx (0 .. $#target) {
247 my ($node, $port) = @{ $target[$idx] }; 247 my ($node, $port) = @{ $target[$idx] };
248 248
249 if (my $noden = AnyEvent::Socket::parse_ip ($node)) { 249 if (my $noden = AnyEvent::Socket::parse_ip ($node)) {
250 if (4 == length $noden && $family != 6) { 250 if (4 == length $noden && $family != 6) {
251 push @res, [$idx, [Socket::AF_INET, $type, $proton, 251 push @res, [$idx, "ipv4", [Socket::AF_INET, $type, $proton,
252 AnyEvent::Socket::pack_sockaddr ($port, $noden)]] 252 AnyEvent::Socket::pack_sockaddr ($port, $noden)]]
253 } 253 }
254 254
255 if (16 == length $noden && $family != 4) { 255 if (16 == length $noden && $family != 4) {
256 push @res, [$idx, [&AnyEvent::Socket::AF_INET6, $type, $proton, 256 push @res, [$idx, "ipv6", [&AnyEvent::Socket::AF_INET6, $type, $proton,
257 AnyEvent::Socket::pack_sockaddr ( $port, $noden)]] 257 AnyEvent::Socket::pack_sockaddr ( $port, $noden)]]
258 } 258 }
259 } else { 259 } else {
260 # ipv4 260 # ipv4
261 if ($family != 6) { 261 if ($family != 6) {
262 $cv->begin; 262 $cv->begin;
263 a $node, sub { 263 a $node, sub {
264 push @res, [$idx, [Socket::AF_INET, $type, $proton, 264 push @res, [$idx, "ipv4", [Socket::AF_INET, $type, $proton,
265 AnyEvent::Socket::pack_sockaddr ($port, AnyEvent::Socket::parse_ipv4 ($_))]] 265 AnyEvent::Socket::pack_sockaddr ($port, AnyEvent::Socket::parse_ipv4 ($_))]]
266 for @_; 266 for @_;
267 $cv->end; 267 $cv->end;
268 }; 268 };
269 } 269 }
270 270
271 # ipv6 271 # ipv6
272 if ($family != 4) { 272 if ($family != 4) {
273 $cv->begin; 273 $cv->begin;
274 aaaa $node, sub { 274 aaaa $node, sub {
275 push @res, [$idx, [&AnyEvent::Socket::AF_INET6, $type, $proton, 275 push @res, [$idx, "ipv6", [&AnyEvent::Socket::AF_INET6, $type, $proton,
276 AnyEvent::Socket::pack_sockaddr ($port, AnyEvent::Socket::parse_ipv6 ($_))]] 276 AnyEvent::Socket::pack_sockaddr ($port, AnyEvent::Socket::parse_ipv6 ($_))]]
277 for @_; 277 for @_;
278 $cv->end; 278 $cv->end;
279 }; 279 };
280 } 280 }
785 for (split /\n/, $resolvconf) { 785 for (split /\n/, $resolvconf) {
786 if (/^\s*#/) { 786 if (/^\s*#/) {
787 # comment 787 # comment
788 } elsif (/^\s*nameserver\s+(\S+)\s*$/i) { 788 } elsif (/^\s*nameserver\s+(\S+)\s*$/i) {
789 my $ip = $1; 789 my $ip = $1;
790 if (AnyEvent::Util::dotted_quad $ip) { 790 if (my $ipn = AnyEvent::Socket::parse_ip ($ip)) {
791 push @{ $self->{server} }, AnyEvent::Util::socket_inet_aton $ip; 791 push @{ $self->{server} }, $ipn;
792 } else { 792 } else {
793 warn "nameserver $ip invalid and ignored\n"; 793 warn "nameserver $ip invalid and ignored\n";
794 } 794 }
795 } elsif (/^\s*domain\s+(\S*)\s+$/i) { 795 } elsif (/^\s*domain\s+(\S*)\s+$/i) {
796 $self->{search} = [$1]; 796 $self->{search} = [$1];
849 849
850 while (<$fh>) { 850 while (<$fh>) {
851 # second DNS.* is server address list 851 # second DNS.* is server address list
852 if (/^\s*DNS/) { 852 if (/^\s*DNS/) {
853 while (/\s+(\d+\.\d+\.\d+\.\d+)\s*$/) { 853 while (/\s+(\d+\.\d+\.\d+\.\d+)\s*$/) {
854 my $ipn = AnyEvent::Socket::parse_ip ("$1"); # "" is necessary here, apparently
855 push @{ $self->{server} }, $ipn
854 my $ip = $1; 856 if $ipn;
855 push @{ $self->{server} }, AnyEvent::Util::socket_inet_aton $ip
856 if AnyEvent::Util::dotted_quad $ip;
857 $_ = <$fh>; 857 $_ = <$fh>;
858 } 858 }
859 last; 859 last;
860 } 860 }
861 } 861 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines