AnyEvent resolves hostnames always via DNS
Marc Lehmann
schmorp at schmorp.de
Fri Mar 9 08:42:28 CET 2012
On Thu, Mar 08, 2012 at 11:18:32PM +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:
No, you didn't - you probably wrote it because you think it is true, but
since it is not (I can trivially come up with counter examples, just use
default settings for nss for example), it means you are too fast at making
this kind of claim, without knowledge to back it up.
> my $ip = Socket::inet_aton "example.com";
inet_aton is only defined for numeric ip addresses. AnyEvent::Socket
extends that with dns.
you need to use resolve_sockaddr, which is the equivalent of nss for
anyevent.
> AnyEvent hangs up because it always uses DNS even if there is an entry
It doesn't "hang up" here, although it's not clear to me what it means. Do
you mena it times out? That would be proper behaviour if 2.2.2.2 is not
working as a nameserver.
> On my intranet server there is no DNS available.
That's your problem to fix, not AnyEvent's. AnyEvent supports /etc/hosts
for name resolution, it does not implement some magic DNS system around
/etc/hosts, and neither does your system software.
> works correctly, but there is only one exception: AnyEvent based
> application.
AnyEvent of course also works correctly - if you specify a nonresponding
dns server than you will get timeouts, nothing else can ever happen.
> >> 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.
It seems it does - you seem to shift the target around though. AnyEvent does
support /etc/hosts as fallback when resolving socket addresses, it does not
fake DNS service for you.
If you want DNS, implement DNS.
> >> 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.
Exactly.
> The whole world use it for this pupose and there is many tools
> exploiting this behaviour (adblocks, jailbreakers and other hacks).
Exactly, so why do you want to use it for something else?
> AnyEvent try DNS even if /etc/resolv.conf is empty. Then AnyEvent uses
> Google's DNS.
Not quite true, but reasonably close.
> They might be unavailable i.e. on intranet server.
You can provide your own dns servers if you wish, or tell AnyEvent not to
use any servers. You have to explicitly tell anyevent about this, though.
> /etc/hosts:
> 1.1.1.1 example.conf
> /etc/resolv.conf
> <empty>
>
> and try my script.
Works as designed, supporting /etc/hosts as it should. Use
resolve_sockaddr or tcp_connect.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list