Why GetBestInterfaceEx doesn't consider routes added via command line?

Deepan Negi 0 Reputation points
2024-06-19T09:27:31.26+00:00

Consider the case where there are two network interfaces connected to the system (Ethernet and WiFi). Both will add 0.0.0.0/0 route in the routing table but, one of the interface will have a lower metric (say Ethernet gets the lower metric). GetBestInterfaceEx gives correct results for any given IP i.e. Ethernet.

But, consider the case where we add a specific route for 1.1.1.1/32 to go via WiFi instead of Ethernet using "route add" command. In this case, GetBestInterfaceEx doesn't consider the newly added route and still returns WiFi as the best interface for 1.1.1.1 destination.

In case a VPN adds the same route for 1.1.1.1/32 to go via VPN adapter instead of Ethernet, even in this case, the API correctly gives the VPN adapter as the best interface.

Why does the MSDN API consider the route added by VPN different than the one added using route add command?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,045 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,492 questions
Windows Network
Windows Network
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Network: A group of devices that communicate either wirelessly or via a physical connection.
696 questions
{count} votes