Solved

How does Winipcfg get IP addresses

Posted on 1999-01-11
18
279 Views
Last Modified: 2013-12-04
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????????
0
Comment
Question by:haast
  • 8
  • 5
  • 3
  • +1
18 Comments
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418548
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.
0
 

Author Comment

by:haast
ID: 1418549
nickrepin

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

Can you help with that scenario ?????

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418550
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).
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:haast
ID: 1418551
No DHCP !!
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418552
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...
0
 

Expert Comment

by:CodeMonkey
ID: 1418553
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]));
    }
  }
}
0
 

Author Comment

by:haast
ID: 1418554
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

0
 

Author Comment

by:haast
ID: 1418555
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,


0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418556
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.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418557
I can give you some info about that entries in NT, but now I have no info about 95.
0
 

Author Comment

by:haast
ID: 1418558
NickRepin could you please contact me at: westwebs@ihug.co.nz
0
 

Author Comment

by:haast
ID: 1418559
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
0
 

Author Comment

by:haast
ID: 1418560
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
0
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 1418561
For a DIAL-UP connection, this code will get information about the currently established DUN connection.  YOUR IP address is returned in this line:

strcpy(hostip, prasip->szIpAddress);
       ^^^^^^



//
// Check the state of any RAS connection
//
char *CWindow::CheckRAS(DWORD *state, char *hostip)
{

RASCONN *ras_buf;
RASPPPIP *prasip;
DWORD sz_ras_buf, numconn, errcd, szrasip;
HRASCONN hrc;
static char rasname[256];

// Allocate space for RASCONN buffers
ras_buf = (RASCONN *)malloc(32 * sizeof(RASCONN));
sz_ras_buf = 32 * sizeof(RASCONN);

ras_buf->dwSize = sizeof(RASCONN);

if((errcd = RasEnumConnections(ras_buf, &sz_ras_buf, &numconn)) != 0){
    *state = RAS_ERROR;
    free(ras_buf);
return NULL;
}

if(numconn > 0){
hrc = ras_buf->hrasconn;

prasip = (RASPPPIP *)malloc(sizeof(RASPPPIP));
szrasip = sizeof(RASPPPIP);
prasip->dwSize = szrasip;

errcd = RasGetProjectionInfo(hrc, RASP_PppIp, prasip, &szrasip);
switch(errcd){

default:
    *state = RAS_ERROR;
    free(ras_buf);
    return NULL;
case 0:
*state = RAS_CONN;
strcpy(rasname, ras_buf->szEntryName);
strcpy(hostip, prasip->szIpAddress);
if(strlen(rasname) > 0){
    free(ras_buf);
     return(rasname);
     }
     else{
         *state = RAS_ERROR;
         free(ras_buf);
         return NULL;
     }

case 731:
    *state = RAS_DIAL;
    strcpy(rasname, ras_buf->szEntryName);
if(strlen(rasname) > 0){
    free(ras_buf);
     return(rasname);
     }
     else{
         *state = RAS_ERROR;
         free(ras_buf);
         return NULL;
     }
}
}
else{
    *state = RAS_NOCONN;
    free(ras_buf);
    return NULL;
}
}
0
 

Author Comment

by:haast
ID: 1418562
jhance, give me a bit of time and i will check it out, thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 1418563
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...
0
 

Expert Comment

by:CodeMonkey
ID: 1418564
Sorry, I didn't answer but I was away
0
 

Expert Comment

by:CodeMonkey
ID: 1418565
Sorry, I didn't answer but I was away. jhance's answer seems okay
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question