Thread: IP/HOST Conflict when gettin' the Users IP (Sockets)

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    45

    IP/HOST Conflict when gettin' the Users IP (Sockets)

    Hello!

    I just found a nasty bug, I use the following code to determine the users IP:

    Code:
        if (gethostname(hostname, sizeof(hostname)) == SOCKET_ERROR) {
            printf("nothing found");
        }
    
        struct hostent *phe = gethostbyname(hostname);
        memcpy(&addr, phe->h_addr_list[0], sizeof(struct in_addr));
        sprintf(hostip,"%s",inet_ntoa(addr));
    
        //Convert IP to Decimal notation
        sprintf(decResult,"%u", addr);
        sprintf(decResult,"%u", htonl(atoi(decResult)));

    The problem is the following:

    Code:
    phe->h_addr_list[0]
    ==> Works only when connected via wireless
    Code:
    phe->h_addr_list[1]
    ==> Works only when connected via LAN

    And I don't know what happends when I would connect to both?

    So how do I determine what interfaces are active?

    Kind regards

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    45
    Solved: VirtualBox Host-Only Network was the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  2. gettin a movie screencap
    By geek@02 in forum Windows Programming
    Replies: 3
    Last Post: 11-20-2006, 10:25 AM
  3. sorting list gettin seg fault
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 05-20-2006, 11:52 PM
  4. IRQ conflict
    By alpha in forum Tech Board
    Replies: 2
    Last Post: 09-09-2003, 03:11 PM
  5. still gettin errors
    By dP munky in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2003, 04:25 PM