I have just encountered the same problem, and I do have “lookup file bind”
set in /etc/resolv.conf.
I am attached to two networks under QNX 4.25, one of which has a DNS server,
and I am using dhcp.client for that network. The host that I want to lookup
is in the /etc/hosts file, but not on the DNS server, although it resides on
the same network as the DNS server.
The mysterious thing is that ping is able to resolve the name, but a simple
program that does nothing but gethostbyname() fails. If I remove
/etc/resolv.conf, then both ping and my program resolve the name just fine.
So, it appears that for some reason my program never accesses /etc/hosts
when /etc/resolv.conf is present, but ping does.
So, is ping doing something magical that I need to know about, or am I
missing something about how gethostbyname() works?
“Frank Liu” <email@example.com> wrote in message
Jeffrey Adler <> firstname.lastname@example.org> > wrote:
I have a program with the following code:
if ( (hp = gethostbyname (hostname) == 0)
fprintf (stderr, “Unknown hostname %s\n”, hostname);
I call this with hostname = “scada_N”, which only exists in the in the
/etc/hosts file. If I define a nameserver in /etc/resolv.conf, then the
above code fails (the nameserver doesn’t know about scada_N).
I can, however, ping scada_N. Why can ping resolve the name but the
code can’t. Any help would be appreciated.
As discussed here:
you will need add “lookup file bind”.