//------C code in win2k-------//
#include <windows.h>
#include <stdio.h>
#include <iphlpapi.h>
void Usage(void) {
printf("Usage: Ipchange [ -l ] [ -a -n<index id> -i<ip address> -m<subnet mask> ] "
"[ -d -c<context id>]\n\n"
"\t -l List adapter index IDs and IP Address context ID information\n"
"\t -a Add IP Address option\n"
"\t -d Delete IP Address option\n"
"\t -i IP Address to specify with -a option\n"
"\t -m Subnet Mask to specify with -a option\n"
"\t -c IP context ID for an existing IP address\n"
"\t -n Index ID of an existing network adapter\n");
}
// Get sizing information about all adapters
AdapterInfoSize = 0;
if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
printf("GetAdaptersInfo sizing failed with error %d\n", Err);
return;
}
}
// Allocate memory from sizing information
if ((pAdapterInfo = (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) == NULL)
{
printf("Memory allocation error\n");
return;
}
// Get actual adapter information
if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
{
printf("GetAdaptersInfo failed with error %d\n", Err);
return;
}
if (OptList)
{
printf("MAC Address - Adapter\n"
"Index Context Ip Address Subnet Mask\n"
"--------------------------------------------------------------\n");
pAdapt = pAdapterInfo;
while (pAdapt)
{
for (UINT i=0; i<pAdapt->AddressLength; i++)
{
if (i == (pAdapt->AddressLength - 1))
printf("%.2X - ",(int)pAdapt->Address[i]);
else
printf("%.2X-",(int)pAdapt->Address[i]);
}
printf("%s\n", pAdapt->Description);