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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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) |
| |||
| "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 |
| |||
| 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) |
| ||||
| "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 |