16,472
社区成员
发帖
与我相关
我的任务
分享
// GetIfTable.cpp
// A sample try to get the speed of a modem by using GetIfTable() func
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment ( lib, "iphlpapi.lib" )
int main( void )
{
MIB_IFTABLE *pIfTable = NULL;
ULONG dwSize = 0;
DWORD dwRet;
printf( "This program try to get the speed of a modem by using GetIfTable()\n" );
dwRet = GetIfTable( pIfTable, &dwSize, TRUE );
if ( dwRet == ERROR_INSUFFICIENT_BUFFER )
{
pIfTable = ( MIB_IFTABLE * ) new char[dwSize];
if ( pIfTable != NULL )
{
dwRet = GetIfTable( pIfTable, &dwSize, TRUE );
if ( dwRet == NO_ERROR )
{
printf( "dwNumEntries = %u\n", pIfTable->dwNumEntries );
for ( int i=0; i<pIfTable->dwNumEntries; i++ )
{
printf( "table[%1d].dwIndex = %u\n",
i,
(pIfTable->table[i]).dwIndex );
printf( " dwType = %u\n",
(pIfTable->table[i]).dwType );
printf( " dwSpeed = %u\n",
(pIfTable->table[i]).dwSpeed );
}
}
else
{
printf( "Some error occured!\n" );
}
}
else
{
printf( "Memory allocate failue\n" );
}
}
else
{
printf( "Some error occured!\n" );
}
getchar();
return 0;
}