Author: cgutman
Date: Thu Aug 19 06:05:35 2010
New Revision: 48563
URL:
http://svn.reactos.org/svn/reactos?rev=48563&view=rev
Log:
[IPHLPAPI]
- Copy our TCP table into the caller's buffer if we actually get one (not yet!)
- Return ERROR_NO_DATA if we fail to get anything from TCP/IP
- Fixes bug #4185
Modified:
trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] Thu Aug 19 06:05:35
2010
@@ -1747,7 +1747,7 @@
*/
DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder)
{
- DWORD ret = NO_ERROR;
+ DWORD ret = ERROR_NO_DATA;
TRACE("pTcpTable %p, pdwSize %p, bOrder %d\n", pTcpTable, pdwSize,
(DWORD)bOrder);
@@ -1764,18 +1764,31 @@
ret = ERROR_INSUFFICIENT_BUFFER;
}
else {
- PMIB_TCPTABLE pTcpTable = getTcpTable();
- if (pTcpTable)
+ PMIB_TCPTABLE pOurTcpTable = getTcpTable();
+ if (pOurTcpTable)
{
size = sizeof(MIB_TCPTABLE);
- if (pTcpTable->dwNumEntries > 1)
- size += (pTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW);
- *pdwSize = size;
-
- if (bOrder)
- qsort(pTcpTable->table, pTcpTable->dwNumEntries,
- sizeof(MIB_TCPROW), TcpTableSorter);
- ret = NO_ERROR;
+ if (pOurTcpTable->dwNumEntries > 1)
+ size += (pOurTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW);
+
+ if (*pdwSize < size)
+ {
+ *pdwSize = size;
+
+ ret = ERROR_INSUFFICIENT_BUFFER;
+ }
+ else
+ {
+ memcpy(pTcpTable, pOurTcpTable, size);
+
+ if (bOrder)
+ qsort(pTcpTable->table, pTcpTable->dwNumEntries,
+ sizeof(MIB_TCPROW), TcpTableSorter);
+
+ ret = NO_ERROR;
+ }
+
+ free(pOurTcpTable);
}
}
}