The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-23-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
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;
}