Gethostbyname()

Ambitious contributor
7Mar2010,17:15   #1
en_7123's Avatar
Could some one tell me how to use gethostbyname() to convert the string entered by user into corresponding ip.If some one could show it by demonstrating a code that would be great.The user should get an option to enter the name of the site say google.com and the corresponding ip is shown and in case the user enters the ip it is converted in the site name.Thanks
Go4Expert Founder
7Mar2010,18:37   #2
shabbir's Avatar
See http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
Ambitious contributor
7Mar2010,18:42   #3
en_7123's Avatar
Quote:
Originally Posted by shabbir View Post
Ok My bad I'm using c on fedora.Could you please show by an example.Thanks
Contributor
8Mar2010,04:29   #4
Gene Poole's Avatar
Try this:

Code:
  struct hostent *hp;

  hp=gethostbyname(addr);
  if(hp){
    printf("%d.%d.%d.%d\n",hp->h_addr[0],hp->h_addr[1],hp->h_addr[2],hp->h_addr[3]);
  }