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

This commit is contained in:
Alexandre Julliard 2008-07-02 17:27:37 +02:00
parent 89a3bd0c15
commit bdf180d2a2
2 changed files with 32 additions and 19 deletions

View File

@ -1513,28 +1513,19 @@ DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf)
DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen)
{
ULONG bytesNeeded = sizeof(IP_PER_ADAPTER_INFO);
DWORD ret;
TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex,
pPerAdapterInfo, pOutBufLen);
if (!pOutBufLen)
ret = ERROR_INVALID_PARAMETER;
else if (!pPerAdapterInfo)
TRACE("(IfIndex %d, pPerAdapterInfo %p, pOutBufLen %p)\n", IfIndex, pPerAdapterInfo, pOutBufLen);
if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
if (!pPerAdapterInfo || *pOutBufLen < bytesNeeded)
{
*pOutBufLen = bytesNeeded;
ret = NO_ERROR;
return ERROR_BUFFER_OVERFLOW;
}
else if (*pOutBufLen < bytesNeeded)
{
*pOutBufLen = bytesNeeded;
ret = ERROR_BUFFER_OVERFLOW;
}
else
{
memset(pPerAdapterInfo, 0, bytesNeeded);
ret = NO_ERROR;
}
return ret;
memset(pPerAdapterInfo, 0, bytesNeeded);
return NO_ERROR;
}

View File

@ -61,6 +61,7 @@ typedef DWORD (WINAPI *GetTcpStatisticsFunc)(PMIB_TCPSTATS);
typedef DWORD (WINAPI *GetUdpStatisticsFunc)(PMIB_UDPSTATS);
typedef DWORD (WINAPI *GetTcpTableFunc)(PMIB_TCPTABLE,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 GetIpAddrTableFunc gGetIpAddrTable = NULL;
@ -78,6 +79,7 @@ static GetTcpStatisticsFunc gGetTcpStatistics = NULL;
static GetUdpStatisticsFunc gGetUdpStatistics = NULL;
static GetTcpTableFunc gGetTcpTable = NULL;
static GetUdpTableFunc gGetUdpTable = NULL;
static GetPerAdapterInfoFunc gGetPerAdapterInfo = NULL;
static void loadIPHlpApi(void)
{
@ -115,6 +117,7 @@ static void loadIPHlpApi(void)
hLibrary, "GetTcpTable");
gGetUdpTable = (GetUdpTableFunc)GetProcAddress(
hLibrary, "GetUdpTable");
gGetPerAdapterInfo = (GetPerAdapterInfoFunc)GetProcAddress(hLibrary, "GetPerAdapterInfo");
}
}
@ -584,6 +587,25 @@ static void testWin98Functions(void)
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:
AddIPAddress
@ -593,7 +615,6 @@ DeleteProxyArpEntry
EnableRouter
FlushIpNetTable
GetAdapterIndex
GetPerAdapterInfo
NotifyAddrChange
NotifyRouteChange
SendARP
@ -601,6 +622,7 @@ UnenableRouter
*/
static void testWin2KFunctions(void)
{
testGetPerAdapterInfo();
}
START_TEST(iphlpapi)