LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   gethostbyname() doesnt always work (https://www.linuxquestions.org/questions/programming-9/gethostbyname-doesnt-always-work-137395/)

nodger 01-22-2004 04:32 AM

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?

infamous41md 01-22-2004 10:56 AM

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;
}



All times are GMT -5. The time now is 02:26 PM.