pointers, hostent and gethostbyname

This is a discussion on pointers, hostent and gethostbyname within the Networking/Device Communication forums, part of the General Programming Boards category; ok, having (more and more and more) pointer troubler this time its trying to get my IP but i can't ...

  1. #1
    Registered User whackaxe's Avatar
    Join Date
    Mar 2004
    Posts
    332

    pointers, hostent and gethostbyname

    ok, having (more and more and more) pointer troubler this time its trying to get my IP but i can't seem to get even 1 out of the hostent.

    i know that this returns one of multiple network adresses, but looping throught htem wron't be to hard once i manage to get 1 I suppose)


    Code:
       char localName[256];
       LPHOSTENT localMachine;
    
       //geting host name for local 'puter
       gethostname(localName, sizeof(localName));
    
       //making a hostent with above name
       localMachine = gethostbyname(localName);
    
       //getting first adress 
       //HELP NEEDED HERE PLEASE =)
       char * addrList = *(localMachine->h_addr_list[0]);
    
       //print IP (hopefuly)
       MessageBox(NULL,addrList,"your adress is...",MB_OK);
    i get a message box with garbage in it

    TIA peeps

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Fron the FAQ
    printf("%s\n", inet_ntoa(*(struct in_addr *) h->h_addr_list[0]));

    http://faq.cprogramming.com/cgi-bin/...=1045780608#01
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Casting and Pointers
    By kpreston in forum C Programming
    Replies: 10
    Last Post: 08-28-2008, 09:23 PM
  2. gethostbyname allways NULL
    By BianConiglio in forum Windows Programming
    Replies: 6
    Last Post: 08-18-2005, 02:27 AM
  3. problem in gethostbyname
    By swaugh in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-02-2004, 01:45 PM
  4. gethostbyname
    By Micko in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-11-2004, 01:21 PM
  5. WinSock and gethostbyname() won't return correctly...
    By SyntaxBubble in forum C++ Programming
    Replies: 2
    Last Post: 07-05-2002, 01:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21