Mike> I am attempting to figure out a host name
Mike> (www.flash.net/mike.flash.net etc...) knowing the IP address
Mike> (111.111.111.111 etc...) however I've had little luck in doing
Mike> so. I've been trying to decipher the man pages on this but have
Mike> yet to get it to work.
Is this any help?
/* byaddr.c */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <stdio.h>
main(int argc, char **argv)
{
struct in_addr addr;
struct hostent *host;
char **argp = argv;
if (argc < 2)
{
fprintf(stderr,"Usage: %s addresses...\n",argv[0]);
return 1;
}
while (*++argp)
{
addr.s_addr = inet_addr(*argp);
host = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET);
if (!host)
printf("host %s not found\n",*argp);
else
printf("host %s found: name='%s'\n", *argp, host->h_name);
}
return 0;
Quote:}
--
Andrew.