MSDN Documentation

CreateIpForwardEntry

The CreateIpForwardEntry function adds a new entry to the IP routing table.

Syntax


DWORD CreateIpForwardEntry(
  [in] PMIB_IPFORWARDROW pRoute
);
            

Parameters

Parameter Description
pRoute A pointer to a MIB_IPFORWARDROW structure that contains information for the new IP route entry.

The structure must specify at least the following members:
  • dwForwardDest: Destination IP address of the route.
  • dwForwardMask: Subnet mask of the destination IP address.
  • dwForwardNextHop: IP address of the next hop router.
  • dwForwardInterface: Index of the interface through which the destination is reachable.
  • dwForwardProto: Protocol that is managing this route (e.g., PROTO_IP_STATIC for a static route).
  • dwForwardType: Type of route (e.g., ROUTE_TYPE_DIRECT for a directly connected route).

Return Value

Return Value Description
NO_ERROR The route was successfully added to the IP routing table.
A non-NO_ERROR value An error occurred. The value indicates the type of error. Common error codes include:
  • ERROR_INVALID_PARAMETER: One or more parameters are invalid.
  • ERROR_NOT_FOUND: The specified interface or next hop is not found.
  • ERROR_ALREADY_EXISTS: An entry with the same destination and mask already exists.
  • ERROR_CANNOT_INSERT: The route could not be inserted (e.g., due to insufficient resources).

Remarks

To create a static route, set the dwForwardProto member of the MIB_IPFORWARDROW structure to PROTO_IP_STATIC.

The CreateIpForwardEntry function is typically used to programmatically configure routing on a Windows system.

Before calling this function, ensure that the interface specified by dwForwardInterface is valid and that the next hop address specified by dwForwardNextHop is reachable.

MIB_IPFORWARDROW Structure

The MIB_IPFORWARDROW structure represents an entry in the IP routing table. It has the following members:


typedef struct _MIB_IPFORWARDROW {
  DWORD           dwForwardDest;
  DWORD           dwForwardMask;
  DWORD           dwForwardNextHop;
  DWORD           dwForwardIfIndex;
  union {
    TYPE_OF_NEXT_HOP dwForwardType;
    DWORD           dwForwardPolicy;
  };
  union {
    DWORD           dwForwardAge;
    DWORD           dwForwardNextHopAS;
  };
  union {
    DWORD           dwForwardMetric1;
    DWORD           dwForwardMetric2;
    DWORD           dwForwardMetric3;
    DWORD           dwForwardMetric4;
    DWORD           dwForwardMetric5;
  };
  DWORD           dwForwardProto;
  DWORD           dwForwardAge;
  union {
    DWORD           dwForwardNextHopAS;
    DWORD           dwForwardRule.dwRoutingProtocols;
  };
  union {
    DWORD           dwForwardRule.dwNextHopSubnetMask;
    DWORD           dwForwardRule.dwRoutingCost;
  };
  DWORD           dwForwardRule.dwBroadcastFlag;
  DWORD           dwForwardRule.dwForwardFlags;
  DWORD           dwForwardRule.dwForwardMetric;
} MIB_IPFORWARDROW, *PMIB_IPFORWARDROW;
        

Refer to the full MSDN documentation for detailed descriptions of each member of the MIB_IPFORWARDROW structure.

See Also