Commit bdf180d2 authored by Alexandre Julliard's avatar Alexandre Julliard

iphlpapi: Fix the return value of GetPerAdapterInfo, with tests.

parent 89a3bd0c
...@@ -1513,28 +1513,19 @@ DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf) ...@@ -1513,28 +1513,19 @@ DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen) DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
{ {
ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO); ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
DWORD ret;
TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, pPerAdapterInfo, pOutBufLen);
pPerAdapterInfo, pOutBufLen);
if (!pOutBufLen) if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
ret = ERROR_INVALID_PARAMETER;
else if (!pPerAdapterInfo) if (!pPerAdapterInfo || *pOutBufLen < bytesNeeded)
{
*pOutBufLen = bytesNeeded;
ret = NO_ERROR;
}
else if (*pOutBufLen < bytesNeeded)
{ {
*pOutBufLen = bytesNeeded; *pOutBufLen = bytesNeeded;
ret = ERROR_BUFFER_OVERFLOW; return ERROR_BUFFER_OVERFLOW;
}
else
{
memset(pPerAdapterInfo, 0, bytesNeeded);
ret = NO_ERROR;
} }
return ret;
memset(pPerAdapterInfo, 0, bytesNeeded);
return NO_ERROR;
} }
......
...@@ -61,6 +61,7 @@ typedef DWORD (WINAPI *GetTcpStatisticsFunc)(PMIB_TCPSTATS); ...@@ -61,6 +61,7 @@ typedef DWORD (WINAPI *GetTcpStatisticsFunc)(PMIB_TCPSTATS);
typedef DWORD (WINAPI *GetUdpStatisticsFunc)(PMIB_UDPSTATS); typedef DWORD (WINAPI *GetUdpStatisticsFunc)(PMIB_UDPSTATS);
typedef DWORD (WINAPI *GetTcpTableFunc)(PMIB_TCPTABLE,PDWORD,BOOL); typedef DWORD (WINAPI *GetTcpTableFunc)(PMIB_TCPTABLE,PDWORD,BOOL);
typedef DWORD (WINAPI *GetUdpTableFunc)(PMIB_UDPTABLE,PDWORD,BOOL); typedef DWORD (WINAPI *GetUdpTableFunc)(PMIB_UDPTABLE,PDWORD,BOOL);
typedef DWORD (WINAPI *GetPerAdapterInfoFunc)(ULONG,PIP_PER_ADAPTER_INFO,PULONG);
static GetNumberOfInterfacesFunc gGetNumberOfInterfaces = NULL; static GetNumberOfInterfacesFunc gGetNumberOfInterfaces = NULL;
static GetIpAddrTableFunc gGetIpAddrTable = NULL; static GetIpAddrTableFunc gGetIpAddrTable = NULL;
...@@ -78,6 +79,7 @@ static GetTcpStatisticsFunc gGetTcpStatistics = NULL; ...@@ -78,6 +79,7 @@ static GetTcpStatisticsFunc gGetTcpStatistics = NULL;
static GetUdpStatisticsFunc gGetUdpStatistics = NULL; static GetUdpStatisticsFunc gGetUdpStatistics = NULL;
static GetTcpTableFunc gGetTcpTable = NULL; static GetTcpTableFunc gGetTcpTable = NULL;
static GetUdpTableFunc gGetUdpTable = NULL; static GetUdpTableFunc gGetUdpTable = NULL;
static GetPerAdapterInfoFunc gGetPerAdapterInfo = NULL;
static void loadIPHlpApi(void) static void loadIPHlpApi(void)
{ {
...@@ -115,6 +117,7 @@ static void loadIPHlpApi(void) ...@@ -115,6 +117,7 @@ static void loadIPHlpApi(void)
hLibrary, "GetTcpTable"); hLibrary, "GetTcpTable");
gGetUdpTable = (GetUdpTableFunc)GetProcAddress( gGetUdpTable = (GetUdpTableFunc)GetProcAddress(
hLibrary, "GetUdpTable"); hLibrary, "GetUdpTable");
gGetPerAdapterInfo = (GetPerAdapterInfoFunc)GetProcAddress(hLibrary, "GetPerAdapterInfo");
} }
} }
...@@ -584,6 +587,25 @@ static void testWin98Functions(void) ...@@ -584,6 +587,25 @@ static void testWin98Functions(void)
testGetNetworkParams(); testGetNetworkParams();
} }
static void testGetPerAdapterInfo(void)
{
DWORD ret, needed;
void *buffer;
if (!gGetPerAdapterInfo) return;
ret = gGetPerAdapterInfo(1, NULL, NULL);
ok( ret == ERROR_INVALID_PARAMETER, "got %u instead of ERROR_INVALID_PARAMETER\n", ret );
needed = 0xdeadbeef;
ret = gGetPerAdapterInfo(1, NULL, &needed);
if (ret == ERROR_NO_DATA) return; /* no such adapter */
ok( ret == ERROR_BUFFER_OVERFLOW, "got %u instead of ERROR_BUFFER_OVERFLOW\n", ret );
ok( needed != 0xdeadbeef, "needed not set\n" );
buffer = HeapAlloc( GetProcessHeap(), 0, needed );
ret = gGetPerAdapterInfo(1, buffer, &needed);
ok( ret == NO_ERROR, "got %u instead of NO_ERROR\n", ret );
HeapFree( GetProcessHeap(), 0, buffer );
}
/* /*
still-to-be-tested 2K-onward functions: still-to-be-tested 2K-onward functions:
AddIPAddress AddIPAddress
...@@ -593,7 +615,6 @@ DeleteProxyArpEntry ...@@ -593,7 +615,6 @@ DeleteProxyArpEntry
EnableRouter EnableRouter
FlushIpNetTable FlushIpNetTable
GetAdapterIndex GetAdapterIndex
GetPerAdapterInfo
NotifyAddrChange NotifyAddrChange
NotifyRouteChange NotifyRouteChange
SendARP SendARP
...@@ -601,6 +622,7 @@ UnenableRouter ...@@ -601,6 +622,7 @@ UnenableRouter
*/ */
static void testWin2KFunctions(void) static void testWin2KFunctions(void)
{ {
testGetPerAdapterInfo();
} }
START_TEST(iphlpapi) START_TEST(iphlpapi)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment