Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-22-2004, 05:32 AM   #1
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: gives me gives me
localhost gives me

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

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

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

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){
                return 1;

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

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

        return 0;


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 10:23 AM
screensaver doesnt work encore Slackware 10 09-21-2005 05:43 PM
Why doesnt my USB mouse doesnt work? barkha Linux - Hardware 2 08-16-2005 12:31 PM
mic doesnt work freeka Linux - Hardware 3 07-25-2005 04:19 PM
Alsa Doesnt work Creeps Linux - General 1 09-14-2004 01:50 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 AM.

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