Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A question about gethostbyname()

53 views
Skip to first unread message

Mitchell Schoenbrun

unread,
Aug 30, 2000, 3:00:00 AM8/30/00
to
Previously, zhoujun wrote in comp.os.qnx:

> On QNX 4.25, I failed to execute function gethostbyname().
> I am sure something is wrong with my system configuration,but, I can't find
> it out and correct it.

Well the most likely thing that comes to mind is that the IP's
in your /etc/resolv.conf point to name servers that are not
working. You might want to try pinging them for starters.

Mitchell Schoenbrun --------- masc...@pobox.com


zhoujun

unread,
Aug 31, 2000, 2:19:55 AM8/31/00
to
On QNX 4.25, I failed to execute function gethostbyname().
I am sure something is wrong with my system configuration,but, I can't find
it out and correct it.

Thank you for any info.

Zhoujun

zhoujun

unread,
Aug 31, 2000, 3:00:00 AM8/31/00
to
Thank you !
After restarting my computer, I tried to ping some involved IP addresses,I
found I can ping to any IP addresses in my subnet. And I can ping to my
nameserver and web servers in Internet,too.

My host: *.*.75.96
My nameserver: *.*.75.90
My gateway: *.*.75.8

But,I could not ping to *.*.120.20 although system knows the gateway
*.*.75.8.
After adding the subnet by command "route add -net *.*.120 *.*.75.8", I
can ping to *.*.120.20. I also want to know this cause.

The problem about gethostbyname() still exists.


Mitchell Schoenbrun <masc...@pobox.com> wrote in message
news:Voyager.00083...@schoenbrun.com...


> Previously, zhoujun wrote in comp.os.qnx:
>

> > On QNX 4.25, I failed to execute function gethostbyname().
> > I am sure something is wrong with my system configuration,but, I can't
find
> > it out and correct it.
>

Mario Charest

unread,
Aug 30, 2000, 8:16:19 PM8/30/00
to

What is your netmap, from what I understand it should be 255.255.255.0

"zhoujun" <jz...@mail.nairc.ac.cn> wrote in message
news:8ol2a1$t7r$1...@inn.qnx.com...


> Thank you !
> After restarting my computer, I tried to ping some involved IP addresses,I
> found I can ping to any IP addresses in my subnet. And I can ping to my
> nameserver and web servers in Internet,too.
>
> My host: *.*.75.96
> My nameserver: *.*.75.90
> My gateway: *.*.75.8
>
> But,I could not ping to *.*.120.20 although system knows the gateway
> *.*.75.8.
> After adding the subnet by command "route add -net *.*.120 *.*.75.8", I
> can ping to *.*.120.20. I also want to know this cause.
>
> The problem about gethostbyname() still exists.
>
>
> Mitchell Schoenbrun <masc...@pobox.com> wrote in message
> news:Voyager.00083...@schoenbrun.com...
> > Previously, zhoujun wrote in comp.os.qnx:
> >

> > > On QNX 4.25, I failed to execute function gethostbyname().
> > > I am sure something is wrong with my system configuration,but, I can't
> find
> > > it out and correct it.
> >

Heather Johnstone

unread,
Aug 31, 2000, 9:24:31 AM8/31/00
to
I think Mario means 'What is your netmask' :-)

I believe you want the netmask to be 255.255.0.0

Heather

Ivan Bannon

unread,
Aug 31, 2000, 5:54:45 PM8/31/00
to
Check out the file "/etc/resolv.conf" and be sure it defines your nameserver
correctly. That may be your problem

Ivan

zhoujun <jz...@mail.nairc.ac.cn> wrote in message

news:8okteh$pvd$1...@inn.qnx.com...

Ivan Bannon

unread,
Aug 31, 2000, 5:56:15 PM8/31/00
to
What???? A netmap of 255.255.255.0? L:ooks like a netmask to me? :}

Mario Charest <mcha...@zinformatic.com> wrote in message
news:8oli4j$7q7$1...@inn.qnx.com...

Ivan Bannon

unread,
Aug 31, 2000, 5:58:08 PM8/31/00
to
The TCP/IP release for 4.25 has a problem in that the ifconfigalways sets
the
netmask to 255.255.255.0 whanever you define the "en1" IP. I have tried to
get to to create a 255.255.0.0, but if you check it always shows ffffff00 as
the
netmask, which is 255.255.255.0

Heather Johnstone <hea...@qnx.com> wrote in message
news:8olmaf$4t4$1...@nntp.qnx.com...

zhoujun

unread,
Aug 31, 2000, 10:09:31 PM8/31/00
to
Thank you !
In my file "/etc/resolv.conf" :
domain nairc.ac.cn
nameserver *.*.75.90

And, the problem about gethostbyname() still exists either the netmask is
set to 255.255.0.0 or to 255.255.255.0.


Ivan Bannon <ivan....@rjginc.com> wrote in message
news:8omk1t$obg$1...@inn.qnx.com...

Xiaodan Tang

unread,
Sep 1, 2000, 12:47:09 AM9/1/00
to
zhoujun <jz...@mail.nairc.ac.cn> wrote:
> Thank you !
> In my file "/etc/resolv.conf" :
> domain nairc.ac.cn
> nameserver *.*.75.90

> And, the problem about gethostbyname() still exists either the netmask is
> set to 255.255.0.0 or to 255.255.255.0.

If you can, post "netstat -ni, netstat -nr", that will give a
clear picture of the connectivate.

1) is "ping *.*.75.90" works?

2) is "nslookup" contact the nameserver ? Is it showing you the right
server address (*.*.75.90)

3) What is "ping <somename>" returned ? Is it resolved the name?

4) The name you giveing "gethostbyname()", is it in /etc/hosts or
is it in nameserver? Can you "nslookup <thename>" to resolve it?

5) you may consider change your /etc/resolv.conf as:

domain nairc.ac.cn
lookup file bind
nameserver *.*.75.90

This will tell resolver check /etc/hosts first, if can't find,
check nameserver.

-xt...@qnx.com

zhoujun

unread,
Sep 1, 2000, 3:42:57 AM9/1/00
to
Thank you !
Because *.*.75.90 is my temp nameserver,so I change my nameserver to
*.*.120.20; then I try to do some test. The following is the result:

"netstat -ni" & "netstat -nr" can work well.

1) I can ping to *.*.120.20.

2) "nslookup" can contact the nameserver, and show the right IP address:
*.*.120.20.

3) For example,"ping www.qnx.com" returns the right IP address.

4)The name I give "gethostbyname()", for example, "node1", is in
"/etc/hosts",but not in my nameserver. I can't "nslookup node1" to resolve
it.

But I can get right response with "ping node1" or "telnet node1".
In the help documents on QNX, I find the following:
The nslookup utility won't look at /etc/hosts even if the lookup keyword
is used in /etc/resolv.conf.

5) I add "lookup file bind" to "/etc/resolv.conf" according to your
advice,but, "nslookup node1" still can't find "node1".

What's the matter?

Xiaodan Tang <xt...@qnx.com> wrote in message
news:8onccd$4da$1...@nntp.qnx.com...

Xiaodan Tang

unread,
Sep 1, 2000, 9:35:27 AM9/1/00
to
zhoujun <jz...@mail.nairc.ac.cn> wrote:
> Thank you !
> Because *.*.75.90 is my temp nameserver,so I change my nameserver to
> *.*.120.20; then I try to do some test. The following is the result:

> "netstat -ni" & "netstat -nr" can work well.

> 1) I can ping to *.*.120.20.

> 2) "nslookup" can contact the nameserver, and show the right IP address:
> *.*.120.20.

> 3) For example,"ping www.qnx.com" returns the right IP address.

> 4)The name I give "gethostbyname()", for example, "node1", is in
> "/etc/hosts",but not in my nameserver. I can't "nslookup node1" to resolve
> it.

> But I can get right response with "ping node1" or "telnet node1".
> In the help documents on QNX, I find the following:
> The nslookup utility won't look at /etc/hosts even if the lookup keyword
> is used in /etc/resolv.conf.

> 5) I add "lookup file bind" to "/etc/resolv.conf" according to your
> advice,but, "nslookup node1" still can't find "node1".

But your "gethostbyname("node1")" is succeesed, right? (Cause you could
ping/telnet to "node1").

nslookup using different resolver as others. It _ONLY_ talk to a nameserver,
resolving names. Others, ping/telnet, they using the resolver in libsocket,
which understand "lookup file bind", menas they will check /etc/hosts first,
then DNS.

-xt...@qnx.com

zhoujun

unread,
Sep 1, 2000, 9:24:05 PM9/1/00
to
It is just the question. My "gethostbyname("node1")" is _not_ succeeded On
QNX 4.25, and it returns NULL. It can be rightly executed on my Redhat 6.0.
I am really muddled.

Xiaodan Tang <xt...@qnx.com> wrote in message

news:8oobav$lul$1...@nntp.qnx.com...

Xiaodan Tang

unread,
Sep 2, 2000, 3:24:22 PM9/2/00
to
zhoujun <jz...@mail.nairc.ac.cn> wrote:
> It is just the question. My "gethostbyname("node1")" is _not_ succeeded On
> QNX 4.25, and it returns NULL. It can be rightly executed on my Redhat 6.0.
> I am really muddled.

I was confused.

Are you saying your "gethostbyname("node1")" is not succeeded even if
you could "ping node1" from the same QNX 4.25 machine? (ping _IS_
using gethostbyname() if you give it a name).

xt...@qnx.com

zhoujun

unread,
Sep 2, 2000, 9:39:01 PM9/2/00
to
Yes, my question is just that. I have tested the function for many times on
QNX 4.25, but I have never gotten the right result. It always returns
"NULL";but on the same QNX 4.25 machine, "ping node1" or "telnet node1" can
execute successfully.

Xiaodan Tang <xt...@qnx.com> wrote in message

news:8ork56$jjc$1...@nntp.qnx.com...

Xiaodan Tang

unread,
Sep 3, 2000, 12:06:03 AM9/3/00
to
zhoujun <jz...@mail.nairc.ac.cn> wrote:
> Yes, my question is just that. I have tested the function for many times on
> QNX 4.25, but I have never gotten the right result. It always returns
> "NULL";but on the same QNX 4.25 machine, "ping node1" or "telnet node1" can
> execute successfully.

That's strange. As I said, "ping" _IS_ using a gethostbyname() on
the node name you give it.

Can you do this:

# env

# ping -c1 node1

# cat <your test program>.c

# cc -o mytest <your test program>.c -lsocket

# ./mytest

Post the output of each command. The "your test program".c is
the program showing how your "gethostbyname()" failed.

-xiaodan

zhoujun

unread,
Sep 3, 2000, 2:28:18 AM9/3/00
to
Thank you !
The following is the output of those commands according to your post.

# env
_=/usr/bin/env
ABLPATH=/qnx4/photon/translations
PHOTON=//1/dev/photon
KBD=en_US_101.kbd
PATH=/bin:/etc:/usr/bin:/etc:/usr/ucb:/usr/local/bin:/qnx4/photon/bin:
/qnx4/photon/usr/bin:/qnx4/phtk/appbuilder:/usr/bin//photon
SHELL=/bin/sh
PHFONT=/dev/phfont
PHIG=1
PHTK_PATH=/qnx4/phtk
TMPDIR=/tmp
HOME=///
PHWM=pwm
CON_KBD=USA
USER_NAME=/dev/photon
TERM=qansi-m
TZ=wast-08
HZ=1000
ABLANG=en
PHOTON_PATH=/qnx4/photon
PHSTART=1
LOGNAME=root
SYSNAME=qnx4

# ping -c1 node1
PING node1.nairc.ac.cn (159.226.75.96): 56 data bytes
64 bytes from 159.226.75.96: icmp_seq=0 ttl=255 time=0 ms

--- node1.nairc.ac.cn ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0/0/0 ms

# cat test.c
#include <stdio.h>
#include <netdb.h>
main()
{
if(gethostbyname("node1")==NULL) printf("error\n");

}

# cc -o mytest test.c -lsocket
/usr/watcom/10.6/bin/wcc386 -zq -ms -4r -i=/usr/watcom/10.6/usr/include -i=/
usr/include t
est.c
/usr/watcom/10.6/bin/wlink op quiet form qnx flat na mytest op priv=3 op c
libp /usr/watc
om/10.6/usr/lib:/usr/lib:. f /home/empress/test.o l
/usr/watcom/10.6/usr/lib/socket3r.lib
op offset=40k op st=32k

# ./mytest
error
#

0 new messages