Group: IP Helper - Library: iphlpapi
DWORD GetBestRoute(
DWORD dwDestAddr,
DWORD dwSourceAddr,
PMIB_IPFORWARDROW pBestRoute
);
DECLARE LONG GetBestRoute IN Iphlpapi;
LONG dwDestAddr,;
LONG dwSourceAddr,;
INTEGER pBestRoute
dwDestAddr [in] Destination IP address for which to obtain the best route.
dwSourceAddr [in] Source IP address. This IP address corresponds to an interface on the local computer.
pBestRoute [out] Pointer to a MIB_IPFORWARDROW structure containing the best route for the IP address specified by dwDestAddr.
If the function succeeds, the return value is NO_ERROR (0).
#DEFINE MIB_IPFORWARDROW_SIZE 56
nSrcIP = inet_addr("192.168.0.200")
nDstIP = inet_addr("66.94.234.13")
oBuffer = CREATEOBJECT("PChar",;
REPLICATE(CHR(0), MIB_IPFORWARDROW_SIZE))
IF GetBestRoute(nDstIP, nSrcIP, oBuffer.GetAddr()) <> 0
? "GetBestRoute failed with error code:",;
GetLastError()
RETURN
ENDIF
cBuffer = oBuffer.GetValue()
nHopIP = buf2dword(SUBSTR(cBuffer, 13, 4))
? inet_ntoa(nSrcIP)
See also: GetBestInterface.