enumerating network interfaces?

Discussion in 'OT Technology' started by crotchfruit, Jun 26, 2003.

  1. crotchfruit

    crotchfruit Guest

    does anyone know the win32 api calls to enumerate the network interfaces, and then get their info? tried searching google and msdn with no luck :squint:
     
  2. crotchfruit

    crotchfruit Guest

    to be a little more specific, here is my problem:

    i am trying to autodetect the ip of the computer running my program. right now i am doing something like:

    char ip[256];
    gethostname(ip,256);
    struct hostent *h;
    h = gethostbyname(ip);

    //my_ip gets the ip here (iterating through list w/ ip_pos)
    strcpy(my_ip, inet_ntoa(*((struct in_addr *)h->h_addr_list[ip_pos])));


    this works great on my win2k dev computer. the problem is, when i tried on a win98 machine, all i get is '127.0.0.1'.

    i debugged into this and found that gethostname was returning 'localhost.xxx.com' on the win98 machine. this was traced back to the DNS settings for the win98 machine. that is, if they changed the 'host' field to anything but 'localhost', i would get the correct ip instead of 127.0.0.1.

    (btw, iterating through the h_addr_list didn't help, since it only returned one element [127.0.0.1])

    basically, i need a way to get the non-localhost ip of a computer even if they set the DNS to think it's localhost.whatever. obviously this ip exists somewhere because the win98 computer can still see and be seen by the network.

    i guess i can always just add to a FAQ that you need to set this properly, but it would be nice if it didn't matter.

    thanks for any help :bowdown:
     
  3. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    i have some source code at home where I was doing something similar. I'll try and post it tonight when i get home from work :x:
     
  4. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    You might want to try getting the netbios name using GetComputerName() in place of gethostname().
     
  5. Mikel

    Mikel .

    Joined:
    May 17, 2000
    Messages:
    227,938
    Likes Received:
    347
    Location:
    38103
  6. crotchfruit

    crotchfruit Guest

    you are a genius. this solved my problem :bowdown: :bowdown: :bowdown: :bowdown:
     

Share This Page