try this,
Code:
# include<netdb.h>
# include<stdio.h>
# include<netinet/in.h>
# include<arpa/inet.h>
# include<sys/socket.h>
int main(int argc, char *argv[])
{
long conv;
struct hostent *h;
if(argc != 2)
{
fprintf(stderr, "USAGE: <binary> <IP_ADDRESS>\n");
exit(1);
}
if( (int) (conv=inet_addr(argv[1])) == -1 )
{
fprintf(stderr, "IP Notation Wrong\n");
exit(1);
}
h=gethostbyaddr((char*)&conv, sizeof(conv), AF_INET);
if(h == (struct hostent *) NULL)
{
fprintf(stderr, "Resolve failed for %s\n", argv[1]);
exit(1);
}
fprintf(stderr, "Name: %s\n", h->h_name);
return 0;
}