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;
- }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |