Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to detect multiple ip addresses

Status
Not open for further replies.

sv

Programmer
Feb 19, 2001
5
US
is it possible to detect multiple IP addresses or Adapters in a computer? I want to list all the possible choices of the IPs available in a program. Anyone have examples or code or an overview of how its done?
 
I haven't done it myself, but you should be able to do something like (sorry, it's in C, but you ought to be able to see what's happening)

[tt]
DWORD cb = 0;
PROTOCOL_INFO *pPI;
BOOL pfLanas[100];
int nLanas = sizeof(pfLanas)/sizeof(BOOL);
int iRC;

// Determine output buffer size
iRC = EnumProtocols(NULL, NULL, &cb);

if (!cb)
return; // No adapters in system, or error

// Allocate a buffer
pPI = (PROTOCOL_INFO*) calloc(1, cb);

// Enumerate all protocols.
iRes = EnumProtocols( NULL, pPI, &cb );

// EnumProtocols() lists each lana number twice, once for
// SOCK_DGRAM and once for SOCK_SEQPACKET. Set a flag in
// pfLanas so unique lanas can be identified.

memset(pfLanas, 0, sizeof(pfLanas));

while (iRC > 0) {
// Scan protocols looking for AF_INET (TCP, IP).
if (pPI[--iRC].iAddressFamily == AF_INET)
// found one
pfLanas[abs(pPI[iRC].iProtocol)] = TRUE;
}
}

free(pPI);
[/tt]

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top