… | |
… | |
35 | |
35 | |
36 | use AnyEvent (); |
36 | use AnyEvent (); |
37 | use AnyEvent::Handle (); |
37 | use AnyEvent::Handle (); |
38 | use AnyEvent::Util qw(AF_INET6); |
38 | use AnyEvent::Util qw(AF_INET6); |
39 | |
39 | |
40 | our $VERSION = 4.1; |
40 | our $VERSION = 4.13; |
41 | |
41 | |
42 | our @DNS_FALLBACK = (v208.67.220.220, v208.67.222.222); |
42 | our @DNS_FALLBACK = (v208.67.220.220, v208.67.222.222); |
43 | |
43 | |
44 | =item AnyEvent::DNS::a $domain, $cb->(@addrs) |
44 | =item AnyEvent::DNS::a $domain, $cb->(@addrs) |
45 | |
45 | |
… | |
… | |
65 | =item AnyEvent::DNS::srv $service, $proto, $domain, $cb->(@srv_rr) |
65 | =item AnyEvent::DNS::srv $service, $proto, $domain, $cb->(@srv_rr) |
66 | |
66 | |
67 | Tries to resolve the given service, protocol and domain name into a list |
67 | Tries to resolve the given service, protocol and domain name into a list |
68 | of service records. |
68 | of service records. |
69 | |
69 | |
70 | Each srv_rr is an array reference with the following contents: |
70 | Each C<$srv_rr> is an array reference with the following contents: |
71 | C<[$priority, $weight, $transport, $target]>. |
71 | C<[$priority, $weight, $transport, $target]>. |
72 | |
72 | |
73 | They will be sorted with lowest priority first, then randomly |
73 | They will be sorted with lowest priority first, then randomly |
74 | distributed by weight as per RFC 2782. |
74 | distributed by weight as per RFC 2782. |
75 | |
75 | |
… | |
… | |
708 | =cut |
708 | =cut |
709 | |
709 | |
710 | sub new { |
710 | sub new { |
711 | my ($class, %arg) = @_; |
711 | my ($class, %arg) = @_; |
712 | |
712 | |
713 | # try to create a ipv4 and an ipv6 socket |
|
|
714 | # only fail when we cnanot create either |
|
|
715 | |
|
|
716 | socket my $fh4, AF_INET , &Socket::SOCK_DGRAM, 0; |
|
|
717 | socket my $fh6, AF_INET6, &Socket::SOCK_DGRAM, 0; |
|
|
718 | |
|
|
719 | $fh4 || $fh6 |
|
|
720 | or Carp::croak "unable to create either an IPv6 or an IPv4 socket"; |
|
|
721 | |
|
|
722 | my $self = bless { |
713 | my $self = bless { |
723 | server => [], |
714 | server => [], |
724 | timeout => [2, 5, 5], |
715 | timeout => [2, 5, 5], |
725 | search => [], |
716 | search => [], |
726 | ndots => 1, |
717 | ndots => 1, |
… | |
… | |
731 | }, $class; |
722 | }, $class; |
732 | |
723 | |
733 | # search should default to gethostname's domain |
724 | # search should default to gethostname's domain |
734 | # but perl lacks a good posix module |
725 | # but perl lacks a good posix module |
735 | |
726 | |
|
|
727 | # try to create an ipv4 and an ipv6 socket |
|
|
728 | # only fail when we cannot create either |
|
|
729 | my $got_socket; |
|
|
730 | |
736 | Scalar::Util::weaken (my $wself = $self); |
731 | Scalar::Util::weaken (my $wself = $self); |
737 | |
732 | |
738 | if ($fh4) { |
733 | if (socket my $fh4, AF_INET , &Socket::SOCK_DGRAM, 0) { |
|
|
734 | ++$got_socket; |
|
|
735 | |
739 | AnyEvent::Util::fh_nonblocking $fh4, 1; |
736 | AnyEvent::Util::fh_nonblocking $fh4, 1; |
740 | $self->{fh4} = $fh4; |
737 | $self->{fh4} = $fh4; |
741 | $self->{rw4} = AnyEvent->io (fh => $fh4, poll => "r", cb => sub { |
738 | $self->{rw4} = AnyEvent->io (fh => $fh4, poll => "r", cb => sub { |
742 | if (my $peer = recv $fh4, my $pkt, MAX_PKT, 0) { |
739 | if (my $peer = recv $fh4, my $pkt, MAX_PKT, 0) { |
743 | $wself->_recv ($pkt, $peer); |
740 | $wself->_recv ($pkt, $peer); |
744 | } |
741 | } |
745 | }); |
742 | }); |
746 | } |
743 | } |
747 | |
744 | |
748 | if ($fh6) { |
745 | if (AF_INET6 && socket my $fh6, AF_INET6, &Socket::SOCK_DGRAM, 0) { |
|
|
746 | ++$got_socket; |
|
|
747 | |
749 | $self->{fh6} = $fh6; |
748 | $self->{fh6} = $fh6; |
750 | AnyEvent::Util::fh_nonblocking $fh6, 1; |
749 | AnyEvent::Util::fh_nonblocking $fh6, 1; |
751 | $self->{rw6} = AnyEvent->io (fh => $fh6, poll => "r", cb => sub { |
750 | $self->{rw6} = AnyEvent->io (fh => $fh6, poll => "r", cb => sub { |
752 | if (my $peer = recv $fh6, my $pkt, MAX_PKT, 0) { |
751 | if (my $peer = recv $fh6, my $pkt, MAX_PKT, 0) { |
753 | $wself->_recv ($pkt, $peer); |
752 | $wself->_recv ($pkt, $peer); |
754 | } |
753 | } |
755 | }); |
754 | }); |
756 | } |
755 | } |
|
|
756 | |
|
|
757 | $got_socket |
|
|
758 | or Carp::croak "unable to create either an IPv4 or an IPv6 socket"; |
757 | |
759 | |
758 | $self->_compile; |
760 | $self->_compile; |
759 | |
761 | |
760 | $self |
762 | $self |
761 | } |
763 | } |
… | |
… | |
1126 | "any" record type. |
1128 | "any" record type. |
1127 | |
1129 | |
1128 | The callback will be invoked with a list of matching result records or |
1130 | The callback will be invoked with a list of matching result records or |
1129 | none on any error or if the name could not be found. |
1131 | none on any error or if the name could not be found. |
1130 | |
1132 | |
1131 | CNAME chains (although illegal) are followed up to a length of 8. |
1133 | CNAME chains (although illegal) are followed up to a length of 10. |
1132 | |
1134 | |
1133 | The callback will be invoked with an result code in string form (noerror, |
1135 | The callback will be invoked with an result code in string form (noerror, |
1134 | formerr, servfail, nxdomain, notimp, refused and so on), or numerical |
1136 | formerr, servfail, nxdomain, notimp, refused and so on), or numerical |
1135 | form if the result code is not supported. The remaining arguments are |
1137 | form if the result code is not supported. The remaining arguments are |
1136 | arraryefs of the form C<[$name, $type, $class, @data>], where C<$name> is |
1138 | arraryefs of the form C<[$name, $type, $class, @data>], where C<$name> is |
… | |
… | |
1243 | $do_search = sub { |
1245 | $do_search = sub { |
1244 | @search |
1246 | @search |
1245 | or (undef $do_search), (undef $do_req), return $cb->(); |
1247 | or (undef $do_search), (undef $do_req), return $cb->(); |
1246 | |
1248 | |
1247 | (my $name = lc "$qname." . shift @search) =~ s/\.$//; |
1249 | (my $name = lc "$qname." . shift @search) =~ s/\.$//; |
1248 | my $depth = 2; |
1250 | my $depth = 10; |
1249 | |
1251 | |
1250 | # advance in cname-chain |
1252 | # advance in cname-chain |
1251 | $do_req = sub { |
1253 | $do_req = sub { |
1252 | $self->request ({ |
1254 | $self->request ({ |
1253 | rd => 1, |
1255 | rd => 1, |
… | |
… | |
1330 | |
1332 | |
1331 | =back |
1333 | =back |
1332 | |
1334 | |
1333 | =head1 AUTHOR |
1335 | =head1 AUTHOR |
1334 | |
1336 | |
1335 | Marc Lehmann <schmorp@schmorp.de> |
1337 | Marc Lehmann <schmorp@schmorp.de> |
1336 | http://home.schmorp.de/ |
1338 | http://home.schmorp.de/ |
1337 | |
1339 | |
1338 | =cut |
1340 | =cut |
1339 | |
1341 | |