Click to See Complete Forum and Search --> : CreateIpForwardEntry problems


rootroot
August 14th, 2001, 10:36 AM
I've got a problem with the post SP4 NT4+ API "CreateIpForwardEntry". I'm trying to add a routing rule in the piece of code hereunder. It works just fine. However, if i use the IP address assigned to my ethernetcard as het "next hop" (thereby making it the default gateway for the particular network segment) it fails me. Can anyone help me out?


private Type MIB_IPFORWARDROW
dwForwardDest as Long ' IP addr of destination
dwForwardMask as Long ' subnetwork mask of destination
dwForwardPolicy as Long ' conditions for multi-path route
dwForwardNextHop as Long ' IP address of next hop
dwForwardIfIndex as Long ' index of interface
dwForwardType as Long ' route type
dwForwardProto as Long ' protocol that generated route
dwForwardAge as Long ' age of route
dwForwardNextHopAS as Long ' autonomous system number
dwForwardMetric1 as Long ' protocol-specific metric
dwForwardMetric2 as Long ' protocol-specific metric
dwForwardMetric3 as Long ' protocol-specific metric
dwForwardMetric4 as Long ' protocol-specific metric
dwForwardMetric5 as Long ' protocol-specific metric
End Type

private Declare Function CreateIpForwardEntry Lib "IPHLPAPI.DLL" _
(byref pRoute as Any) as Long

Function RouteAdd(byval sInterfaceIndex as Long, _
byval sForwardDestination as string, _
byval sForwardMask as string, _
byval sForwardNextHop as string) as Boolean

Dim IPForwardTable as MIB_IPFORWARDROW

With IPForwardTable

sForwardNextHop = "172.31.64.9"
.dwForwardDest = inet_addr(sForwardDestination)
.dwForwardIfIndex = sInterfaceIndex
.dwForwardMask = inet_addr(sForwardMask)
.dwForwardNextHop = inet_addr(sForwardNextHop)
.dwForwardAge = 0
.dwForwardMetric1 = 50

If MsgBox("Would you like the routing information to be permanent (otherwise the routing information is volatile and needs to be re-created every time you boot)?", vbYesNo, "Question") = vbYes then
.dwForwardProto = PROTO_IP_NT_STATIC
else
.dwForwardProto = PROTO_IP_NETMGMT
End If
.dwForwardPolicy = 0 ' iphlpapi.h states unused (platform sdk july 2000)

If CreateIpForwardEntry(IPForwardTable) = ERROR_SUCCESS then
MsgBox "Created route to host."
else
MsgBox "Failed to create route!"

End If
End Function