GetBestRoute 函數獲取到目的IP的最佳匹配路由。
第一個參數為:destination(目的IP)
第二個參數為:source(源IP)
通常不需要指定第二個source,這個一般用來匹配具體某一個網卡接口路由的,即source等于本機某個網卡的接口IP或網關。
GetBestInterface 函數是獲取到目的IP的最佳網卡接口IFR_INDEX。
bool Router::GetBestRoute(uint32_t destination, uint32_t source, MIB_IPFORWARDROW& route) noexcept{int err = ::GetBestRoute(destination, source, &route);return err == NO_ERROR;}bool Router::GetBestRoute(uint32_t destination, MIB_IPFORWARDROW& route) noexcept{return GetBestRoute(destination, 0, route);}int Router::GetBestInterface(uint32_t ip) noexcept{DWORD dwBestIfIndex = 0;int err = ::GetBestInterface(ip, &dwBestIfIndex);if (err != NO_ERROR){return -1;}return dwBestIfIndex;}