gethostbyaddr / nslookup failed on AIX 5.3
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > gethostbyaddr / nslookup failed on AIX 5.3




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    gethostbyaddr / nslookup failed on AIX 5.3  
kcw3388@hotmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-06 06:25 AM

Hi,

I have a AIX 5.3 machine; the
gethostbyaddr ( ) and nslookup failed.

I have the correct entry in /etc/hosts file.

But the "host" command worked fine.

Does anyone why?

Also, is there any C library call similar
to "host" command on AIX?

Any comments/suggestions are appreciated.

Thanks,

Kevin






[ Post a follow-up to this message ]



    Re: gethostbyaddr / nslookup failed on AIX 5.3  
Reiner Huober


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-06 06:25 AM


kcw3388@hotmail.com schrieb:

> Hi,
>
> I have a AIX 5.3 machine; the
> gethostbyaddr ( ) and nslookup failed.
>
> I have the correct entry in /etc/hosts file.
>
> But the "host" command worked fine.
>
> Does anyone why?
>
> Also, is there any C library call similar
> to "host" command on AIX?
>
> Any comments/suggestions are appreciated.
>

nslookup will never search in /etc/hosts, it is the nameserver lookup
and consults /etc/resolv.conf and *only* DNS servers.

gethostbyaddr consults many sources, e.g. /etc/hosts, NIS, DNS. On most
systems, /etc/nsswitch.conf must be set appropriately - I do not know
modern AIX. The address of a host in /etc/hosts should be recognizable.


However, if you use DNS, a special domain (hierarchy) *in-addr.arpa."
is consulted. The addresses are not type PTR So if you want to search
the address 1.2.3.4, you must use type=PTR and 4.3.2.1.in-addr.arpa.
Some modern versions of nslookup do this automatically if you enter an
IP address, but not all. Use "dig" instead. The address to host name
resolution in DNS works only if the administrator also makes correct
entriess in the in-addr.arpa.-domain.

> Also, is there any C library call similar
> to "host" command on AIX?
>
> Any comments/suggestions are appreciated.
>

I bet that the host command uses gethostbyaddr.  Are you sure that you
used the correct paramenters. Note that gethostbyaddr does not accept
an address as (char*), e.g. "1.2.3.4" as parameter. This is often not
detected since the first parameter is declared as (void*). You must use
the macro inet_addr and supply a 32 entity casted to void* or char* :-(

Do not use  gethostbyaddr("1.2.3.4",strlen("1.2.3.4"), AF_INET), but
instead

struct in_addr a;
a.s_addr=inet_addr("1.2.3.4");
gethostbyaddr((char*)&a,sizeof(a),AF_INET)

This works on my MacOS X box (shoud work for you too)

include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

main(argc,argv)
int argc; char ** argv;
{       struct hostent * h;
struct in_addr a;

a.s_addr=inet_addr(argc>1 ? argv[1] : "");
h=gethostbyaddr((char*)&a,sizeof(a),AF_INET);
printf("%s\n",h ? h->h_name : "not found");
}

HTH
Hubble.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:51 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register