Share via


GetBestInterface (Compact 2013)

3/26/2014

This function retrieves the index of the interface that has the best route to the specified IP address.

Syntax

DWORD GetBestInterface(
  IPAddr dwDestAddr, 
  PDWORD pdwBestIfIndex 
);

Parameters

  • dwDestAddr
    [in] The destination IP address 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

Return code

Description

NO_ERROR

The function succeeds.

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 pdwBestIfIndex points to memory that cannot be written.

ERROR_NOT_SUPPORTED

The request is not supported. This error is returned if no IPv4 stack is located on the local device.

Other

Use the FormatMessage function to obtain the message string for the returned error.

Remarks

The GetBestInterface function only works with IPv4 addresses. For use with IPv6 addresses, the GetBestInterfaceEx must be used.

For information about the IPAddr data type, see Window Data Types. To convert an IP address between dotted decimal notation and IPAddr format, use the inet_addr and inet_ntoa functions.

Requirements

Header

iphlpapi.h

Library

Iphlpapi.lib

See Also

Reference

IP Helper Functions
IPAddr
GetBestRoute
GetBestInterfaceEx
MIB_BEST_IF

Other Resources

IP Helper
Window Data Types