|
From: kcw3388 on 16 Jun 2006 22:25 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
From: Reiner Huober on 17 Jun 2006 01:47 kcw3388(a)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.
|
Pages: 1 Prev: FIFO synchronization problem Next: High-Speed TCP/IP Message Logging |