LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-22-2004, 04:32 AM   #1
nodger
Member
 
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192

Rep: Reputation: 30
gethostbyname() doesnt always work


I dont know if this is a programming question or a network question, but theres no `network programming' forum, so I guess I'll ask it here.

Im having some problems with the gethostbyname() function. It works on most names, for example:

www.hotmail.com gives me 207.68.173.245
www.linuxquestions.org gives me 64.179.4.146
localhost gives me 127.0.0.1

however these addresses dont resolve for me, although if I open a browser window
I can easily access them:

www.al4a.com

any ideas?
 
Old 01-22-2004, 10:56 AM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
using this prog i resolved all of those addy's fine:
Code:
[n00b@localho.outernet] cat ghbyname.c 
#include "my_sock.h"

int
main(int argc, char **argv)
{
        struct hostent  *hp;
        struct in_addr  **pptr;

        if(argc != 2){
                printf("Usage: %s <hostname>\n", argv[0]);
                return 1;
        }

        if( (hp = gethostbyname(argv[1])) == NULL){
                perror("gethostbyname");
                return 1;
        }

        pptr = (struct in_addr **)hp->h_addr_list;

        while( *pptr != NULL ){
                printf("ip address: %s\n", inet_ntoa(**(pptr++)));
        }

        return 0;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tor doesnt work Smokey Ubuntu 0 10-16-2005 09:23 AM
screensaver doesnt work encore Slackware 10 09-21-2005 04:43 PM
Why doesnt my USB mouse doesnt work? barkha Linux - Hardware 2 08-16-2005 11:31 AM
mic doesnt work freeka Linux - Hardware 3 07-25-2005 03:19 PM
Alsa Doesnt work Creeps Linux - General 1 09-14-2004 12:50 AM


All times are GMT -5. The time now is 03:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration