Platform SDK: Internet Protocol Helper

GetBestInterface

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

DWORD GetBestInterface(
  IPAddr dwDestAddr,     // destination IP address
  PDWORD pdwBestIfIndex  // index of interface with the best route
);

Parameters

dwDestAddr
Specifies the destination IP address for which to retrieve the interface that has the best route.
pdwBestIfIndex
Pointer to a DWORD variable. On successful return, this variable contains the index of the interface that has the best route to the address specified by the dwDestAddr parameter.

Return Values

If the function succeeds, the return value is NO_ERROR.

If the function fails, use FormatMessage to obtain the message string for the returned error.

Remarks

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

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 98.
  Header: Declared in Iphlpapi.h.
  Library: Use Iphlpapi.lib.

See Also

GetBestRoute, MIB_BEST_IF