gethostbyname problems

I have a program with the following code:

if ( (hp = gethostbyname (hostname) == 0)
{
fprintf (stderr, “Unknown hostname %s\n”, hostname);
return FALSE
}

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 above
code can’t. Any help would be appreciated.

Jeff.

Jeffrey Adler <jeffadler.at.bigfoot.dot.com@nowhere.com> wrote:

I have a program with the following code:

if ( (hp = gethostbyname (hostname) == 0)
{
fprintf (stderr, “Unknown hostname %s\n”, hostname);
return FALSE
}

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 above
code can’t. Any help would be appreciated.

Jeff.

As discussed here:
http://www.openqnx.com/PNphpBB2-viewtopic-t4848-.html
you will need add “lookup file bind”.

How does “ping” do it??


“Frank Liu” <fliu@usdjmp1.eng.vodafone-us.com> wrote in message
news:crhgvq$llb$1@inn.qnx.com

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:
I have a program with the following code:

if ( (hp = gethostbyname (hostname) == 0)
{
fprintf (stderr, “Unknown hostname %s\n”, hostname);
return FALSE
}

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
above
code can’t. Any help would be appreciated.

Jeff.



As discussed here:
http://www.openqnx.com/PNphpBB2-viewtopic-t4848-.html
you will need add “lookup file bind”.

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” <fliu@usdjmp1.eng.vodafone-us.com> wrote in message
news:crhgvq$llb$1@inn.qnx.com

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:
I have a program with the following code:

if ( (hp = gethostbyname (hostname) == 0)
{
fprintf (stderr, “Unknown hostname %s\n”, hostname);
return FALSE
}

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
above
code can’t. Any help would be appreciated.

Jeff.



As discussed here:
http://www.openqnx.com/PNphpBB2-viewtopic-t4848-.html
you will need add “lookup file bind”.

you are probably hitting a bug where there are two socket libraries
on your system. make sure you link the right one.

If I remember correctly, one is in /usr/lib, the other is in
/usr/watcom/10.6/usr/lib. Just remove/rename the later one so that
the good one in /usr/lib gets picked up.

Frank

That did the trick. Thanks.

“Frank Liu” <fliu@usdjmp1.eng.vodafone-us.com> wrote in message
news:crht5d$1bp$1@inn.qnx.com

you are probably hitting a bug where there are two socket libraries
on your system. make sure you link the right one.

If I remember correctly, one is in /usr/lib, the other is in
/usr/watcom/10.6/usr/lib. Just remove/rename the later one so that
the good one in /usr/lib gets picked up.

Frank