T
Hier mal zwei Mezhoden aus der MSDN:
für(Windows)
DeleteIPAddress(ULONG NTEContext)
AddIPAdress( IPAddr Address,
IPMask IpMask,
DWORD IfIndex,
PULONG NTEContext,
PULONG NTEInstance)
// Before calling AddIPAddress we use GetIpAddrTable to get
// an adapter to which we can add the IP.
PMIB_IPADDRTABLE pIPAddrTable;
DWORD dwSize = 0;
pIPAddrTable = (MIB_IPADDRTABLE*) malloc( sizeof( MIB_IPADDRTABLE) );
// Make an initial call to GetIpAddrTable to get the
// necessary size into the dwSize variable
if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
GlobalFree( pIPAddrTable );
pIPAddrTable = (MIB_IPADDRTABLE *) malloc ( dwSize );
}
// Make a second call to GetIpAddrTable to get the
// actual data we want
if ( (dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 )) == NO_ERROR ) {
printf("\tAddress: %ld\n", pIPAddrTable->table[0].dwAddr);
printf("\tMask: %ld\n", pIPAddrTable->table[0].dwMask);
printf("\tIndex: %ld\n", pIPAddrTable->table[0].dwIndex);
printf("\tBCast: %ld\n", pIPAddrTable->table[0].dwBCastAddr);
printf("\tReasm: %ld\n", pIPAddrTable->table[0].dwReasmSize);
}
else {
printf("Call to GetIpAddrTable failed.\n");
}
// IP and mask we will be adding
UINT iaIPAddress;
UINT imIPMask;
iaIPAddress = inet_addr("192.168.0.27");
imIPMask = inet_addr("255.255.255.0");
// Variables where handles to the added IP will be returned
ULONG NTEContext = 0;
ULONG NTEInstance = 0;
if ( (dwRetVal = AddIPAddress(iaIPAddress,
imIPMask,
pIPAddrTable->table[0].dwIndex,
&NTEContext,
&NTEInstance) ) == NO_ERROR) {
printf("\tIP address added.\n");
}
else {
printf("Error adding IP address.\n");
LPVOID lpMsgBuf;
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwRetVal,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL )) {
printf("\tError: %s", lpMsgBuf);
}
LocalFree( lpMsgBuf );
}
// Delete the IP we just added using the NTEContext
// variable where the handle was returned
if ((dwRetVal = DeleteIPAddress(NTEContext)) == NO_ERROR) {
printf("\tIP Address Deleted.\n");
}
else {
printf("\tCall to DeleteIPAddress failed.\n");
}