AnyEvent resolves hostnames always via DNS

Piotr Roszatycki piotr.roszatycki at gmail.com
Fri Mar 9 15:41:46 CET 2012


2012/3/9 Marc Lehmann <schmorp at schmorp.de>:
>> my $ip = Socket::inet_aton "example.com";
> inet_aton is only defined for numeric ip addresses. AnyEvent::Socket
> extends that with dns.

Example in AnyEvent/Socket.pm is measliding:

   inet_aton "www.google.com", my $cv = AE::cv;
   say unpack "H*", $_
      for $cv->recv;
   # => d155e363
   # => d155e367 etc.

libc6 inet_aton resolves also hostnames but it could be just an extra
feature missing in AnyEvent. I can live without it.

>
> you need to use resolve_sockaddr, which is the equivalent of nss for
> anyevent.

use Socket;
my $ip = gethostbyname "example.com";
say "Socket:", join ".", unpack "C*", $ip;

use AnyEvent::Socket;
my $cv = AE::cv;
my $ip;
AnyEvent::Socket::resolve_sockaddr "example.com", 80, 0, 0, undef, sub {
    my $target = shift;
    my ($domain, $type, $proto, $sockaddr) = @$target;
    my ($port, $host) = AnyEvent::Socket::unpack_sockaddr $sockaddr;
    $ip = $host;
    $cv->send;
};
$cv->recv;
say "AnyEvent:", join ".", unpack "C*", $ip;

Still the same:

Socket:1.1.1.1
AnyEvent:192.0.43.10

> If you want DNS, implement DNS.

I don't want to save the world, which uses /etc/hosts for wrong
things. I want just make some AnyEvent-based applications working
without DNS.

Sub::Override will save my day. Seems like I just need to override
AnyEvent::DNS::a. It's very fortunate that Perl allows to fix some
broken libraries easly.

Thanks.
-- 
 .''`.    Piotr Roszatycki
: :' :    mailto:Piotr.Roszatycki at gmail.com
`. `'     mailto:dexter at cpan.org
  `-



More information about the anyevent mailing list