… | |
… | |
27 | use strict; |
27 | use strict; |
28 | |
28 | |
29 | use AnyEvent::Handle (); |
29 | use AnyEvent::Handle (); |
30 | |
30 | |
31 | =item AnyEvent::DNS::addr $node, $service, $proto, $family, $type, $cb->([$family, $type, $proto, $sockaddr], ...) |
31 | =item AnyEvent::DNS::addr $node, $service, $proto, $family, $type, $cb->([$family, $type, $proto, $sockaddr], ...) |
32 | |
|
|
33 | NOT YET IMPLEMENTED |
|
|
34 | |
32 | |
35 | Tries to resolve the given nodename and service name into protocol families |
33 | Tries to resolve the given nodename and service name into protocol families |
36 | and sockaddr structures usable to connect to this node and service in a |
34 | and sockaddr structures usable to connect to this node and service in a |
37 | protocol-independent way. It works remotely similar to the getaddrinfo |
35 | protocol-independent way. It works remotely similar to the getaddrinfo |
38 | posix function. |
36 | posix function. |
… | |
… | |
47 | |
45 | |
48 | C<$proto> must be a protocol name, currently C<tcp>, C<udp> or |
46 | C<$proto> must be a protocol name, currently C<tcp>, C<udp> or |
49 | C<sctp>. The default is C<tcp>. |
47 | C<sctp>. The default is C<tcp>. |
50 | |
48 | |
51 | C<$family> must be either C<0> (meaning any protocol is ok), C<4> (use |
49 | C<$family> must be either C<0> (meaning any protocol is ok), C<4> (use |
52 | only IPv4) or C<6> (use only IPv6). |
50 | only IPv4) or C<6> (use only IPv6). This setting might be influenced by |
|
|
51 | C<$ENV{PERL_ANYEVENT_PROTOCOLS}>. |
53 | |
52 | |
54 | C<$type> must be C<SOCK_STREAM>, C<SOCK_DGRAM> or C<SOCK_SEQPACKET> (or |
53 | C<$type> must be C<SOCK_STREAM>, C<SOCK_DGRAM> or C<SOCK_SEQPACKET> (or |
55 | C<undef> in which case it gets automatically chosen). |
54 | C<undef> in which case it gets automatically chosen). |
56 | |
55 | |
57 | The callback will receive zero or more array references that contain |
56 | The callback will receive zero or more array references that contain |
… | |
… | |
191 | |
190 | |
192 | resolver->resolve ($domain => "*", $cb); |
191 | resolver->resolve ($domain => "*", $cb); |
193 | } |
192 | } |
194 | |
193 | |
195 | ############################################################################# |
194 | ############################################################################# |
196 | |
|
|
197 | #AnyEvent::DNS::addr $node, $service, $family, $type, $proto, $cb->([$family, $type, $protocol, $sockaddr], ...) |
|
|
198 | |
195 | |
199 | # $port, $host |
196 | # $port, $host |
200 | sub pack_sockaddr_in6($$) { |
197 | sub pack_sockaddr_in6($$) { |
201 | pack "nnN a16 N", |
198 | pack "nnN a16 N", |
202 | Socket::AF_INET6, |
199 | Socket::AF_INET6, |
… | |
… | |
213 | $family != 6 |
210 | $family != 6 |
214 | or return $cb->(); |
211 | or return $cb->(); |
215 | |
212 | |
216 | $family ||= 4; |
213 | $family ||= 4; |
217 | } |
214 | } |
|
|
215 | |
|
|
216 | $cb->() if $family == 4 && !$AnyEvent::PROTOCOL{ipv4}; |
|
|
217 | $cb->() if $family == 6 && !$AnyEvent::PROTOCOL{ipv6}; |
|
|
218 | |
|
|
219 | $family ||=4 unless $AnyEvent::PROTOCOL{ipv6}; |
|
|
220 | $family ||=6 unless $AnyEvent::PROTOCOL{ipv4}; |
218 | |
221 | |
219 | $proto ||= "tcp"; |
222 | $proto ||= "tcp"; |
220 | $type ||= $proto eq "udp" ? Socket::SOCK_DGRAM : Socket::SOCK_STREAM; |
223 | $type ||= $proto eq "udp" ? Socket::SOCK_DGRAM : Socket::SOCK_STREAM; |
221 | |
224 | |
222 | my $proton = (getprotobyname $proto)[2] |
225 | my $proton = (getprotobyname $proto)[2] |