GetBestInterfaceEx function

The GetBestInterfaceEx function retrieves the index of the interface that has the best route to the specified IPv4 or IPv6 address.

Syntax

DWORD GetBestInterfaceEx(
  sockaddr *pDestAddr,
  PDWORD   pdwBestIfIndex
);

Parameters

pDestAddr

The destination IPv6 or IPv4 address for which to retrieve the interface with the best route, in the form of a sockaddr structure.

pdwBestIfIndex

A pointer to the index of the interface with the best route to the IPv6 or IPv4 address specified by pDestAddr.

Return Value

If the function succeeds, the return value is NO_ERROR.

If the function fails, the return value is one of the following error codes.

Return code Description
ERROR_CAN_NOT_COMPLETE
The operation could not be completed.
ERROR_INVALID_PARAMETER
An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the pdwBestIfIndex parameter or if the pDestAddr or pdwBestIfIndex parameters point to memory that cannot be accessed. This error can also be returned if the pdwBestIfIndex parameter points to memory that can't be written to.
ERROR_NOT_SUPPORTED
The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified in the pDestAddr parameter or no IPv6 stack is on the local computer and an IPv6 address was specified in the pDestAddr parameter.
Other
Use the FormatMessage function to obtain the message string for the returned error.

Remarks

The GetBestInterfaceEx function differs from the GetBestInterface function in that it can be used with either IPv4 or IPv6 addresses.

The Family member of the sockaddr structure pointed to by the pDestAddr parameter must be set to one of the following values: AF_INET or AF_INET6.

On Windows Vista and later, the pdwBestIfIndex parameter is treated internally by IP Helper as a pointer to a NET_IFINDEX datatype.

Requirements

   
Windows version Windows XP [desktop apps | UWP apps] Windows Server 2003 [desktop apps | UWP apps]
Target Platform Windows
Header iphlpapi.h
Library Iphlpapi.lib
DLL Iphlpapi.dll

See Also

GetBestInterface

IP Helper Function Reference

IP Helper Start Page

MIB_BEST_IF

sockaddr