次の方法で共有


GetBestInterfaceEx (Compact 2013)

3/26/2014

This function retrieves the index of the interface that has the best route to the specified IP address. This function differs from the GetBestInterface function in that this function also supports the Internet Protocol version 6 (IPv6) protocol family.

Syntax

DWORD GetBestInterfaceEX(
  struct sockaddr* pDestAddr, 
  PDWORD pdwBestIfIndex 
);

Parameters

  • pDestAddr
    [in] The destination IP address from a sockaddr structure for which to retrieve the interface that has the best route.
  • pdwBestIfIndex
    [out] Pointer to the index of the interface that has the best route to the address specified by the dwDestAddr parameter.

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 cannot be written to.

ERROR_NOT_SUPPORTED

The request is not supported. This error is returned if no IPv4 stack is on the local device and an IPv4 address was specified in the pDestAddr parameter or no IPv6 stack is on the local device 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 because 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.

Requirements

Header

iphlpapi.h

Library

Iphlpapi.lib

See Also

Reference

IP Helper Functions
MIB_BEST_IF
sockaddr
GetBestInterface

Other Resources

IP Helper