Obtaining the MIB II Interfaces Table
The following code uses MprAdminMIBEntryGet to obtain the MIB II interfaces table from the local machine.
#include <windows.h>
#include <mprapi.h>
#include <iprtrmib.h>
#pragma comment(lib, "mprapi.lib")
void main()
{
HANDLE _hMibSrv = INVALID_HANDLE_VALUE;
MIB_OPAQUE_QUERY MibOpaqueQuery;
PMIB_OPAQUE_INFO pMibOpaqueInfo = NULL;
DWORD dwInSize, dwOutSize, dwResult;
PMIB_IFTABLE pIntfTable;
MibOpaqueQuery.dwVarId = IF_TABLE;
dwInSize = sizeof( MIB_OPAQUE_QUERY );
dwOutSize = 0;
dwResult = MprAdminMIBEntryGet ( _hMibSrv,
PID_IP,
IPRTRMGR_PID,
(PVOID)&MibOpaqueQuery,
dwInSize,
(PVOID *)&pMibOpaqueInfo,
&dwOutSize );
if ( dwResult != NO_ERROR )
return;
if ( pMibOpaqueInfo == NULL )
return;
pIntfTable = ( PMIB_IFTABLE ) pMibOpaqueInfo -> rgbyData;
}
#include <windows.h>
#include <stdio.h>
#include "Iphlpapi.h"
int __cdecl main(){
MIB_SERVER_HANDLE hMibSrv = NULL;
MIB_OPAQUE_QUERY MibOpaqueQuery;
PMIB_OPAQUE_INFO pMibOpaqueInfo = NULL;
DWORD dwInSize, dwOutSize, dwRes;
PMIB_IFTABLE pIntfTable;
MibOpaqueQuery.dwVarId = IF_TABLE;
dwInSize = sizeof(MIB_OPAQUE_QUERY);
dwOutSize = 0;
// Connect to the MIB server to obtain the hMibSrv handle
dwRes = MprAdminMIBServerConnect(NULL, &hMibSrv);
if (dwRes != NO_ERROR){
wprintf(L"ERROR: Unable to connect to the MIB server specified.\n");
return ERROR_SUCCESS;
}
// Retrieve the MIB interfaces table. The local RRAS service MUST be running or this call will fail.
dwRes = MprAdminMIBEntryGet(hMibSrv, PID_IP, IPRTRMGR_PID, (PVOID)&MibOpaqueQuery, dwInSize, (PVOID*)&pMibOpaqueInfo, &dwOutSize);
if (dwRes != NO_ERROR){
wprintf(L"ERROR: Unable to retrieve the MIB interface table.\n");
return ERROR_SUCCESS;
}
// Disconnect from the MIB server to release the hMibSrv handle
MprAdminMIBServerDisconnect(hMibSrv);
if (dwRes != NO_ERROR)
return ERROR_SUCCESS;
if (pMibOpaqueInfo == NULL)
return ERROR_SUCCESS;
pIntfTable = (PMIB_IFTABLE)pMibOpaqueInfo->rgbyData;
// Print out the name and description of each MIB interface in the table
wprintf(L"There were %d MIB table records found:\n", pIntfTable->dwNumEntries);
for(UINT i=0; i < pIntfTable->dwNumEntries; i++){
wprintf(L"%d\t%s\t", i, pIntfTable->table[i].wszName, pIntfTable->table[i].bDescr);
printf("%s\n", pIntfTable->table[i].bDescr);
}
return ERROR_SUCCESS;
}
Related topics