[erlang-questions] how to debug inet_res?

Raimo Niskanen <>
Tue Feb 12 17:17:46 CET 2013


On Tue, Feb 12, 2013 at 04:28:17PM +0100, Benoit Chesneau wrote:
> Hi all,
> 
> I am using a custom version of Erlang on iOS and for some reasons I
> ignore yet the DNS resolution is failing in some networks. Since you
> can't launch ports on iOS due to the sandboxing, Erlang is using the
> module inet_res to do the resolution. Which works well on some network
> but return {error, nxdomain} in an office at Singapore.
> 
> Testing the same domain name on desktop with native or inet_res return
> the IP address correctly. For now I have written a small nif to do the
> gethostbyname call but I'm still curious to know why it fails on IOS.
> not sure which kind of test I should do. Any idea?

inet_res is the DNS resolver client written in Erlang. It does not call
gethostbyname. The module inet_gethost_native uses an external port
program to call gethostbyname.

For inet_res, first try this:
    rr(inet_res).
    inet_res:resolve("google.com", in, a).

If that does not work; I first suggest you call inet_db:get_rc() to get a
summary of what settings are used (on both machines) and compare.

Then you can look at the internal ETS table ets:i(inet_db) and compare them
on both machines.

To use a specific nameserver:
    inet_res:resolve("google.com", in, a, [{nameservers,[{{8,8,8,8},53}]}]).

That looks up Googles address at Googles public nameserver 8.8.8.8.
It does not work for me since I am behind a company firewall that does not
allow outgoing DNS queries. I have to use a local nameserver. That local
nameserver should be found in the ets table inet_db which should show in
the inet_db:get_rc() output. If so e.g inet_res:gethostbyname("google.com")
will produce a hostent record.

Note. There is some magic in play indicated by an automatic default entry
{resolv_conf,"/etc/resolv.conf"} in the inet_db:get_rc() output. That causes
inet_res to update inet_db with content from /etc/resolv.conf before doing
a DNS query.

So do an inet_res call first; then if it does not work check the internal
tables. Compare the tables before and after the first call.

You can also add an argument 'verbose' to the argument 4 option list of
inet_res:resolve/4 that will show which servers are tried and what they
reply / timeout.

> 
> - benoit
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list