GetBestInterfaceEx function (iphlpapi.h)
The GetBestInterfaceEx function retrieves the index of the interface that has the best route to the specified IPv4 or IPv6 address.
Syntax
IPHLPAPI_DLL_LINKAGE DWORD GetBestInterfaceEx(
[in] sockaddr *pDestAddr,
[out] PDWORD pdwBestIfIndex
);
Parameters
[in] pDestAddr
The destination IPv6 or IPv4 address for which to retrieve the interface with the best route, in the form of a sockaddr structure.
[out] 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 |
---|---|
|
The operation could not be completed. |
|
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. |
|
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. |
|
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
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps | UWP apps] |
Minimum supported server | Windows Server 2003 [desktop apps | UWP apps] |
Target Platform | Windows |
Header | iphlpapi.h |
Library | Iphlpapi.lib |
DLL | Iphlpapi.dll |