Link to home
Start Free TrialLog in
Avatar of haast
haast

asked on

How does Winipcfg get IP addresses

I would like some detailed workable Win32 'C' code of how to get my IP address when connected to the Internet, and I want to take into account that my computer may or may not have a network card !!!!!!!!

Just like Windows winipcfg proggy does????????
Avatar of NickRepin
NickRepin

It's hard enough, and it's different for NT and 95.
Keep in mind that may be more than one adapter card, more than one RAS (dial-up) connections, DHCP...

It cannot be described with two or two hundred words.

I can write for you working code for 1000 pts at least.
Avatar of haast

ASKER

nickrepin

OK, how about setting limits on this 1 ras connection, 1 adapter card win95/98.

Can you help with that scenario ?????

The problem is not in how many cards we have.
To obtain this info we must:

1) enum all adapters
2) enum all RAS connections
3) obtain TCP/IP and DHCP settings for them
These all must be done through registry, here is no API at all!

I have not got any code you want.
I have got some info about registry keys for NT, and have not for 95.

I can find these all, but it's all absolute free for me. Moreover, I'll waste my time. It's indeed very hard job. For me, at least. I'll do it for 1000 pts, not less.

The Qs like yours were asked here with no success (if I'm not wrong).
Avatar of haast

ASKER

No DHCP !!
I'm sorry, but I really have no time.
The main problem is to enumerate adapters and RAS connections.
May be, other experts can help you...
This code sample will give you a list of valid network interfaces that are available to your computer. If you have Dial up networking then your as your new connection becomes established, extra interafaces will appear in the list. You can use the RAS functions to decide if they are Dial up related connections

char szHostname[100];
if( gethostname( szHostname, sizeof( szHostname ))==0)
{
  HOSTENT* pHostEnt=gethostbyname(szHostname);
  if (pHostEnt)
  {
    int nAdapter = 0;
    while ( pHostEnt->h_addr_list[nAdapter] )
    {
      print("%s\n",inet_ntoa( *(IN_ADDR*)(pHostEnt->h_addr_list[nAdapter]));
    }
  }
}
Avatar of haast

ASKER

Codemonkey, i follow your code OK, but can you elaborate on this .....
You can use the RAS functions to decide if they are Dial up related connections

Avatar of haast

ASKER

Codemonkey, I realise that the list of IP's in network byte order is here: pHostEnt->h_addr_list[nAdapter], but how do establish which IP is the actual current ISP dynamic IP.

(RAS connection) I have had a brief look at RASCON & RASPPPIP structs and HRASCON. As Nickrepin has suggested, I probably have to enumerate the connections with RasEnumConnections and then RasGetProjectionInfo and also he is right about NT being different to Win95/98.

So this is the partof the question that I need answered !!

thanks,


haast, as I know, it's need to enumerate registry entries that relates to RAS connections (their like 'fake' adapters). The addresses in these entries are changes dynamically when RAS connected/disconnected.
I can give you some info about that entries in NT, but now I have no info about 95.
Avatar of haast

ASKER

NickRepin could you please contact me at: westwebs@ihug.co.nz
Avatar of haast

ASKER

Codemonkey, i follow your code OK, but can you elaborate on this .....
You can use the RAS functions to decide if they are Dial up related connections
Avatar of haast

ASKER

Codemonkey, i follow your code OK, but can you elaborate on this .....
You can use the RAS functions to decide if they are Dial up related connections
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of haast

ASKER

jhance, give me a bit of time and i will check it out, thanks
BTW, Winipcfg does this via undocumented WINSOCK calls.  I've traced some out enough to verify that they are indeed undocumented calls.  

The only other reference I have on this subject which you might also find useful is:

http://www.caip.rutgers.edu/~arni/ws2/stas.htm

but it's techniques don't apply to DUN.

Enjoy...
Sorry, I didn't answer but I was away
Sorry, I didn't answer but I was away. jhance's answer seems okay