DeleteIpForwardEntry function
Namespace: IP Helper API (iphlpapi)
Header: IpHlpApi.h
Library: Iphlpapi.lib
Syntax
DWORD DeleteIpForwardEntry(
PMIB_IPFORWARDROW pRouteInfo
);
Parameters
| Parameter | Type | Description |
|---|---|---|
pRouteInfo |
PMIB_IPFORWARDROW | Pointer to a MIB_IPFORWARDROW structure that specifies the route to delete. |
Return Value
If the function succeeds, the return value is NO_ERROR. If it fails, the return value is a Windows error code. Common errors include:
ERROR_NOT_FOUND– The specified route does not exist.ERROR_ACCESS_DENIED– Insufficient privileges.ERROR_INVALID_PARAMETER– Invalid structure members.
Remarks
- The caller must have the
SE_TCB_NAMEprivilege to delete routes. - Only routes created by the current user can be deleted without elevated rights.
- After deletion, the routing table is updated immediately.
Example (C++)
#include <windows.h>
#include <iphlpapi.h>
#include <iostream>
#pragma comment(lib, "iphlpapi.lib")
int main() {
MIB_IPFORWARDROW row = {0};
row.dwForwardDest = inet_addr("192.168.1.0");
row.dwForwardMask = inet_addr("255.255.255.0");
row.dwForwardNextHop = inet_addr("192.168.1.1");
row.dwForwardIfIndex = 2; // interface index
row.dwForwardType = MIB_IPROUTE_TYPE_INDIRECT;
row.dwForwardProto = MIB_IPPROTO_NETMGMT;
DWORD result = DeleteIpForwardEntry(&row);
if (result == NO_ERROR) {
std::cout << "Route deleted successfully." << std::endl;
} else {
std::cerr << "Failed to delete route. Error: " << result << std::endl;
}
return 0;
}