Juan Lang : iphlpapi: Use route table to find an adapter' s default gateway in GetAdaptersInfo.
Alexandre Julliard
julliard at winehq.org
Mon Oct 15 11:28:09 CDT 2007
Module: wine
Branch: master
Commit: 519e8db1f38f877128b86af544f7d62efd0c01b5
URL: http://source.winehq.org/git/wine.git/?a=commit;h=519e8db1f38f877128b86af544f7d62efd0c01b5
Author: Juan Lang <juan.lang at gmail.com>
Date: Sat Oct 13 16:21:20 2007 -0700
iphlpapi: Use route table to find an adapter's default gateway in GetAdaptersInfo.
---
dlls/iphlpapi/iphlpapi_main.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index eaccf83..858437d 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -678,9 +678,12 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
else {
InterfaceIndexTable *table = NULL;
PMIB_IPADDRTABLE ipAddrTable = NULL;
+ PMIB_IPFORWARDTABLE routeTable = NULL;
ret = getIPAddrTable(&ipAddrTable, GetProcessHeap(), 0);
if (!ret)
+ ret = getRouteTable(&routeTable, GetProcessHeap(), 0);
+ if (!ret)
table = getNonLoopbackInterfaceIndexTable();
if (table) {
size = sizeof(IP_ADAPTER_INFO) * table->numIndexes;
@@ -753,6 +756,14 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
}
}
}
+ /* Find first router through this interface, which we'll assume
+ * is the default gateway for this adapter */
+ for (i = 0; i < routeTable->dwNumEntries; i++)
+ if (routeTable->table[i].dwForwardIfIndex == ptr->Index
+ && routeTable->table[i].dwForwardType ==
+ MIB_IPROUTE_TYPE_INDIRECT)
+ toIPAddressString(routeTable->table[i].dwForwardNextHop,
+ ptr->GatewayList.IpAddress.String);
if (winsEnabled) {
ptr->HaveWins = TRUE;
memcpy(ptr->PrimaryWinsServer.IpAddress.String,
@@ -771,6 +782,7 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
}
else
ret = ERROR_OUTOFMEMORY;
+ HeapFree(GetProcessHeap(), 0, routeTable);
HeapFree(GetProcessHeap(), 0, ipAddrTable);
}
}
More information about the wine-cvs
mailing list