Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Gethostbyname() (http://www.go4expert.com/forums/gethostbyname-t21240/)

en_7123 7Mar2010 17:15

Gethostbyname()
 
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

shabbir 7Mar2010 18:37

Re: Gethostbyname()
 
See http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

en_7123 7Mar2010 18:42

Re: Gethostbyname()
 
Quote:

Originally Posted by shabbir (Post 65265)

Ok My bad I'm using c on fedora.Could you please show by an example.Thanks

Gene Poole 8Mar2010 04:29

Re: Gethostbyname()
 
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]);
  }



All times are GMT +5.5. The time now is 11:24.