Module: wine Branch: master Commit: a9e967346002253e576285c9af83b0fc41fe47b4 URL: http://source.winehq.org/git/wine.git/?a=commit;h=a9e967346002253e576285c9af...
Author: Rob Shearman rob@codeweavers.com Date: Thu Jan 17 12:26:14 2008 +0000
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 a9797ac..5ea43c5 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 43ea323..748a74a 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); @@ -812,17 +815,44 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen) */ 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 8fa352a..1e64a18 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);