GetBestRoute2 - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// netioapi.h

NETIOAPI_API GetBestRoute2(
  _In_opt_       NET_LUID            *InterfaceLuid,
  _In_           NET_IFINDEX         InterfaceIndex,
  _In_opt_ const SOCKADDR_INET       *SourceAddress,
  _In_     const SOCKADDR_INET       *DestinationAddress,
  _In_           ULONG               AddressSortOptions,
  _Out_          PMIB_IPFORWARD_ROW2 BestRoute,
  _Out_          SOCKADDR_INET       *BestSourceAddress
);
View the official Windows hardware development documentation

NtDoc

No description available.

Windows hardware development documentation (getbestroute2)

GetBestRoute2 function

The GetBestRoute2 function retrieves the IP route entry on a local computer for the best route to the specified destination IP address.

Parameters

Return value

GetBestRoute2 returns STATUS_SUCCESS if the function succeeds.

If the function fails, GetBestRoute2 returns one of the following error codes:

Return code Description
STATUS_INVALID_PARAMETER An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress, BestSourceAddress, or BestRoute parameters. This error is also returned if both InterfaceLuid and InterfaceIndex parameters were unspecified. This error is also returned if the DestinationAddress parameter does not specify an IPv4 or IPv6 address and family
STATUS_NOT_FOUND The specified interface could not be found. This error is returned if the network interface that the InterfaceLuid or InterfaceIndex parameter specifies could not be found.
STATUS_NOT_SUPPORTED The request is not supported. This error is returned if no IPv4 stack is located on the local computer and an IPv4 address and family was specified in the DestinationAddress parameter, or if no IPv6 stack is located on the local computer and an IPv4 address and family was specified in the DestinationAddress parameter.
Other Use the FormatMessage function to obtain the message string for the returned error.

Remarks

The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP address to a destination IP address.

On input, your driver must initialize the following parameters.

In addition, on input, your driver can initialize the SourceAddress parameter to the preferred IPv4 or IPv6 address and family.

On output, when the call is successful, GetBestRoute2 retrieves an MIB_IPFORWARD_ROW2 structure for the best route from the source IP address the destination IP address.

Requirements

Target platform Universal
Version Available in Windows Vista and later versions of the Windows operating systems.
Header Netioapi.h (include Netioapi.h)
Library Netio.lib
IRQL < DISPATCH_LEVEL

See also

CreateIpForwardEntry2

DeleteIpForwardEntry2

GetIpForwardEntry2

GetIpForwardTable2

InitializeIpForwardEntry

MIB_IPFORWARD_ROW2

MIB_IPFORWARD_TABLE2

NotifyRouteChange2

SetIpForwardEntry2