我想通过WinAPI删除默认路由:
route delete 0.0.0.0
看起来路线正在通过未记录的Nsi *调用进行。有没有更简单的方法呢?
答案 0 :(得分:1)
DeleteIpForwardEntry可以解决问题:
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
// Execute as admin
int main()
{
ULONG size = 10000;
PMIB_IPFORWARDTABLE table = (PMIB_IPFORWARDTABLE)malloc(size);
memset(table, 0, size);
GetIpForwardTable(table,&size,true);
for (int i = 0; i < (int) table->dwNumEntries; i++) {
// Default route 0.0.0.0
if(table->table[i].dwForwardDest == 0)
{
DWORD ret = DeleteIpForwardEntry(&table->table[i]);
printf("Ret: %X\n", ret);
break;
}
}
return 0;
}