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;}