Unix Technical Forum

gethostbyaddr problem

This is a discussion on gethostbyaddr problem within the AIX Operating System forums, part of the Unix Operating Systems category; --> Hi - I'm having difficulties with some old sockets software of mine. gethostbyaddr is returning null for some valid ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 08:13 AM
Clive George
 
Posts: n/a
Default gethostbyaddr problem

Hi -

I'm having difficulties with some old sockets software of mine.
gethostbyaddr is returning null for some valid IP addresses.

Here's my code:

hostAddress = inet_addr( argv[1] );
if( hostAddress == INADDR_NONE )
{
hostEntry = gethostbyname( argv[1] );
if( !hostEntry )
{
printf( "name not found\n" );
return 0;
}
}
else
{
hostEntry = gethostbyaddr( (char*) &hostAddress, sizeof( hostAddress ),
AF_INET );
if( !hostEntry )
{
printf( "gha failed %d\n", h_errno );
return 0;
}

}

which I thought was fairly non-controversial.

if argv[1] is 10.242.0.88, gethostbyaddr returns 0, and h_errno is 1
(HOST_NOT_FOUND).

I can get to 10.242.0.88 via telnet and other programs, and traceroute can
find it. (2 hops).

The aix 5.2 box I'm on is on a different subnet - for the sake of argument,
80.229.*, so it's ip would be 80.229.44.23.

The program can find other 80.229.* addresses, and if I put 10.242.0.88 in
/etc/hosts, it works.

So what am I doing wrong?

(Should I be doing gethostbyaddr at all? I thought it was the correct way to
get a hostent structure from an IP address.)

cheers,
clive



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 08:14 AM
Ken Bell
 
Posts: n/a
Default Re: gethostbyaddr problem

In article <4300f18d$0$1295$ed2619ec@ptn-nntp-reader02.plus.net>,
Clive George <clive@xxxx-x.fsnet.co.uk> wrote:
....
>if argv[1] is 10.242.0.88, gethostbyaddr returns 0, and h_errno is 1
>(HOST_NOT_FOUND).

....
>The program can find other 80.229.* addresses, and if I put 10.242.0.88 in
>/etc/hosts, it works.


What you write after the "and if I put" in your last sentence makes
me wonder: what result do you get (when your "gethostbyaddr" call
returns HOST_NOT_FOUND), from the command "nslookup 10.242.0.88"?

--
Ken Bell :: kenbell_AT_panix_DOT_com :: 212-475-4976 (voice)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 08:14 AM
Clive George
 
Posts: n/a
Default Re: gethostbyaddr problem

"Ken Bell" <kenbell@panix.com> wrote in message
news:ddrf98$qeh$1@reader2.panix.com...
> In article <4300f18d$0$1295$ed2619ec@ptn-nntp-reader02.plus.net>,
> Clive George <clive@xxxx-x.fsnet.co.uk> wrote:
> ...
>>if argv[1] is 10.242.0.88, gethostbyaddr returns 0, and h_errno is 1
>>(HOST_NOT_FOUND).

> ...
>>The program can find other 80.229.* addresses, and if I put 10.242.0.88 in
>>/etc/hosts, it works.

>
> What you write after the "and if I put" in your last sentence makes
> me wonder: what result do you get (when your "gethostbyaddr" call
> returns HOST_NOT_FOUND), from the command "nslookup 10.242.0.88"?


It fails :

Server: dns.mydomain.com
Address 80.229.123.1

*** dns.mydomain.com can't find 10.242.0.88:Non-existent host/domain

(it isn't actually mydomain...)

Does this mean I shouldn't be using gethostbyaddr in my code? How do other
sockets programs get the hostent structure from an IP address? (since they
do appear to work.)

cheers,
clive


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 08:14 AM
Tim Clarke
 
Posts: n/a
Default Re: gethostbyaddr problem

Hi Clive...

"Clive George" <clive@xxxx-x.fsnet.co.uk> wrote in message news:4301bd1b$0$17459$ed2e19e4@ptn-nntp-reader04.plus.net...
> > ...
> >>if argv[1] is 10.242.0.88, gethostbyaddr returns 0, and h_errno is 1
> >>(HOST_NOT_FOUND).

> > ...
> >>The program can find other 80.229.* addresses, and if I put 10.242.0.88 in
> >>/etc/hosts, it works.

> >
> > What you write after the "and if I put" in your last sentence makes
> > me wonder: what result do you get (when your "gethostbyaddr" call
> > returns HOST_NOT_FOUND), from the command "nslookup 10.242.0.88"?

>
> It fails :
>
> Server: dns.mydomain.com
> Address 80.229.123.1
>
> *** dns.mydomain.com can't find 10.242.0.88:Non-existent host/domain
>
> (it isn't actually mydomain...)
>
> Does this mean I shouldn't be using gethostbyaddr in my code? How do other
> sockets programs get the hostent structure from an IP address? (since they
> do appear to work.)


Sounds as though you need to *either* configure the 10.242.0.88 host's name, if this is something you control, in the name-server or
/etc/hosts, *or* not use the gethostby? functions which invoke the call to the name-server to translate between name and address.
I'm no expert in sockets programming but I have worked with TCP/IP for a number of years.

--
Regards,
Tim Clarke (a.k.a. WBST)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 08:14 AM
Clive George
 
Posts: n/a
Default Re: gethostbyaddr problem

"Tim Clarke" <SpamBlock.Monetaim.Com@cswebmail.com> wrote in message
news:WqjMe.10624$1F5.9394@newsfe4-win.ntli.net...

>> Does this mean I shouldn't be using gethostbyaddr in my code? How do
>> other
>> sockets programs get the hostent structure from an IP address? (since
>> they
>> do appear to work.)

>
> Sounds as though you need to *either* configure the 10.242.0.88 host's
> name,
> if this is something you control, in the name-server or /etc/hosts, *or*
> not
> use the gethostby? functions which invoke the call to the name-server to
> translate between name and address.
> I'm no expert in sockets programming but I have worked with TCP/IP for a
> number of years.


Darn, yes, have looked at my code a little more carefully, and no, I don't
need to use gethostbyaddr at all - I don't need the hostent. I suspect this
is a hangover from some of my early attempts at sockets programming.

cheers,
clive


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com