AnyEvent resolves hostnames always via DNS

Piotr Roszatycki piotr.roszatycki at gmail.com
Thu Mar 8 23:18:32 CET 2012


2012/3/7 Marc Lehmann <schmorp at schmorp.de>:
> Hi, thanks for your interest!
>
> On Tue, Mar 06, 2012 at 08:04:03PM +0100, Piotr Roszatycki <piotr.roszatycki at gmail.com> wrote:
>> Yesterday I noticed, that AnyEvent::Socket::resolve_sockaddr works
>> different than on every Linux box
>
> That's not a true statement (as you should be well aware of :).

I wrote this because it is true:

#!/usr/bin/env perl

use 5.12.0;

# Try with "1.1.1.1 example.com" in /etc/hosts file
# and "nameserver 2.2.2.2" as only nameserver in /etc/resolv.conf

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

use AnyEvent::Socket;
AnyEvent::Socket::inet_aton "example.com", my $cv = AE::cv;
say "AnyEvent:", join ".", unpack "C*", $cv->recv;

AnyEvent hangs up because it always uses DNS even if there is an entry
in /etc/hosts or /etc/resolv.conf is empty.

>> The most default configuration of Name Service Switch:
> AnyEvent doesn't implement nss indeed, AnyEvent implements DNS lookups.

On my intranet server there is no DNS available. Every application
works correctly, but there is only one exception: AnyEvent based
application.

>> The order of resolving a socket address is important because
>> /etc/hosts works even if i.e. nameserver is unavailable (problem with
> That is what indeed should happen - does it not?

Well, it doesn't, unfortunately.

>> possible local overring (spoofing) some addresses outside our network.
> No, that's not the purpose of /etc/hosts - the purpose of /etc/hosts is to
> bootstrap the box until DNS is available, then DNS takes over.

This is common usage of/etc/hosts. The whole world use it for this
pupose and there is many tools exploiting this behaviour (adblocks,
jailbreakers and other hacks).

> DNS isn't mandatory, AnyEvent supports /etc/hosts, or at least, I have
> no evidence that it doesn't do so. Maybe you used the wrong syntax for
> /etc/hosts or AnyEvent couldn't parse your entry for other reasons? OR
> maybe you had a matching entry in DNS?

AnyEvent try DNS even if /etc/resolv.conf is empty. Then AnyEvent uses
Google's DNS. They might be unavailable
i.e. on intranet server.

> So, if /etc/hosts don't work as a fallback, then could you send me
> your /etc/hosts and a small snippet that fails to resolve the hostname
> properly?

The simplest example:

/etc/hosts:
1.1.1.1 example.conf
/etc/resolv.conf
<empty>

and try my script.

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



More information about the anyevent mailing list