Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > C-C++

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 03-07-2010, 04:15 PM   #1
Ambitious contributor
 
en_7123's Avatar
 
Join Date: Feb 2010
Posts: 105
Thanks: 0
Thanked 4 Times in 4 Posts
Rep Power: 1
en_7123 is on a distinguished road
Post

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
en_7123 is offline   Reply With Quote
Old 03-07-2010, 05:37 PM   #2
Go4Expert Founder
 
shabbir's Avatar
 
Join Date: Jul 2004
Location: On Earth
Posts: 12,750
Thanks: 131
Thanked 294 Times in 228 Posts
Rep Power: 10
shabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud of
Send a message via Yahoo to shabbir

Re: Gethostbyname()


shabbir is offline   Reply With Quote
Old 03-07-2010, 05:42 PM   #3
Ambitious contributor
 
en_7123's Avatar
 
Join Date: Feb 2010
Posts: 105
Thanks: 0
Thanked 4 Times in 4 Posts
Rep Power: 1
en_7123 is on a distinguished road
Post

Re: Gethostbyname()


Quote:
Originally Posted by shabbir View Post
Ok My bad I'm using c on fedora.Could you please show by an example.Thanks
en_7123 is offline   Reply With Quote
Old 03-08-2010, 03:29 AM   #4
Contributor
 
Join Date: Nov 2009
Posts: 93
Thanks: 0
Thanked 4 Times in 4 Posts
Rep Power: 1
Gene Poole will become famous soon enough

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]);
  }
Gene Poole is offline   Reply With Quote
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

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