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];
    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 ''.

    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

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

    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 custom title

    Sep 20, 2001
    Likes Received:
    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

    Jan 6, 2001
    Likes Received:
    You might want to try getting the netbios name using GetComputerName() in place of gethostname().
  5. Mikel

    Mikel .

    May 17, 2000
    Likes Received:
  6. crotchfruit

    crotchfruit Guest

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

Share This Page