Obtain hostnames from IP addresses
Hello!
Does anyone know how to obtain hostnames (e.g., skywalker.termol.uv.es)
from IP addresses (e.g., 147.156.6.236). I've written this program:
#include <netdb.h>
#include <sys/socket.h>
#include <stdio.h>
#include <string.h>
int main() {
int l;
char addr[]="147.156.6.236";
struct hostent *ph;
l=strlen(addr);ph=gethostbyaddr(addr,l,AF_INET);
if (ph!=NULL) fprintf(stderr,"%d:\t%s\n",i,ph->h_name);
else perror("gethostbyaddr()");
return 0;
}
following the recommendations of a informatic friend of mine about using
function gethostbyaddr, but I obtain:
147.156.6.236: gethostbyaddr(): Address family not supported by protocol
With "man 3 gethostbyaddr" I read "The only valid address type is
currently AF_INET", and when reading /usr/include/sys/socket.h and
/usr/include/socketbits.h I see that AF_INET is 2 for the "IP protocol
family".
Thus, what is wrong?
Is there any program (like a filter: input address in stdin, output name
in stdout) that could do it? I've tried with nslookup but doesn't work
(and it worked last month).
--
Conrado Badenas (Assistant Lecturer)
Department of Thermodynamics. University of Valencia
c/. Doctor Moliner, 50 | e-m: Conrado.Badenas@uv.es
46100 Burjassot (Valencia) | Phn: +34-63864350
SPAIN | Fax: +34-63983385
Reply to: