From a9e967346002253e576285c9af83b0fc41fe47b4 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Thu, 17 Jan 2008 12:26:14 +0000 Subject: [PATCH] iphlpapi: Implement GetBestInterfaceEx. --- dlls/iphlpapi/iphlpapi.spec | 1 + dlls/iphlpapi/iphlpapi_main.c | 40 ++++++++++++++++++++++++++++++----- include/iphlpapi.h | 10 +++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/dlls/iphlpapi/iphlpapi.spec b/dlls/iphlpapi/iphlpapi.spec index a9797ac6689..5ea43c5636a 100644 --- a/dlls/iphlpapi/iphlpapi.spec +++ b/dlls/iphlpapi/iphlpapi.spec @@ -20,6 +20,7 @@ @ stub GetAdapterOrderMap @ stdcall GetAdaptersInfo( ptr ptr ) @ stdcall GetBestInterface( long ptr ) +@ stdcall GetBestInterfaceEx( ptr ptr ) @ stub GetBestInterfaceFromStack @ stdcall GetBestRoute( long long long ) @ stub GetBestRouteFromStack diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 43ea3235130..748a74ac8b3 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -39,9 +39,12 @@ #include "windef.h" #include "winbase.h" #include "winreg.h" +#define USE_WS_PREFIX +#include "winsock2.h" #include "iphlpapi.h" #include "ifenum.h" #include "ipstats.h" + #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); @@ -811,18 +814,45 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen) * Failure: error code from winerror.h */ DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex) +{ + struct WS_sockaddr_in sa_in; + memset(&sa_in, 0, sizeof(sa_in)); + sa_in.sin_family = AF_INET; + sa_in.sin_addr.S_un.S_addr = dwDestAddr; + return GetBestInterfaceEx((struct WS_sockaddr *)&sa_in, pdwBestIfIndex); +} + +/****************************************************************** + * GetBestInterfaceEx (IPHLPAPI.@) + * + * Get the interface, with the best route for the given IP address. + * + * PARAMS + * dwDestAddr [In] IP address to search the interface for + * pdwBestIfIndex [Out] found best interface + * + * RETURNS + * Success: NO_ERROR + * Failure: error code from winerror.h + */ +DWORD WINAPI GetBestInterfaceEx(struct WS_sockaddr *pDestAddr, PDWORD pdwBestIfIndex) { DWORD ret; - TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex); - if (!pdwBestIfIndex) + TRACE("pDestAddr %p, pdwBestIfIndex %p\n", pDestAddr, pdwBestIfIndex); + if (!pDestAddr || !pdwBestIfIndex) ret = ERROR_INVALID_PARAMETER; else { MIB_IPFORWARDROW ipRow; - ret = GetBestRoute(dwDestAddr, 0, &ipRow); - if (ret == ERROR_SUCCESS) - *pdwBestIfIndex = ipRow.dwForwardIfIndex; + if (pDestAddr->sa_family == AF_INET) { + ret = GetBestRoute(((struct WS_sockaddr_in *)pDestAddr)->sin_addr.S_un.S_addr, 0, &ipRow); + if (ret == ERROR_SUCCESS) + *pdwBestIfIndex = ipRow.dwForwardIfIndex; + } else { + FIXME("address family %d not supported\n", pDestAddr->sa_family); + ret = ERROR_NOT_SUPPORTED; + } } TRACE("returning %d\n", ret); return ret; diff --git a/include/iphlpapi.h b/include/iphlpapi.h index 8fa352ac472..1e64a185f62 100644 --- a/include/iphlpapi.h +++ b/include/iphlpapi.h @@ -94,6 +94,16 @@ DWORD WINAPI GetUniDirectionalAdapterInfo( DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex); +#ifdef __WINE_WINSOCKAPI_STDLIB_H +DWORD WINAPI GetBestInterfaceEx( +#ifdef USE_WS_PREFIX + struct WS_sockaddr *pDestAddr, +#else + struct sockaddr *pDestAddr, +#endif + PDWORD pdwBestIfIndex); +#endif + DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute);