Solved

How does Winipcfg get IP addresses

Posted on 1999-01-11
18
278 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSDN Subscription - Azure and NFP's 3 75
Windows Process running 3 58
SSRS troubles 4 68
PL SQL Developer 7 52
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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