MibGet Sample

[This is preliminary documentation and subject to change.]

DWORD
APIENTRY
MibGet(
    IN     DWORD  dwInputSize,
    IN     PVOID  pInputData,
    IN OUT PDWORD pdwOutputSize,
       OUT PVOID  pOutputData
    )
/*++
  Routine Description
      Called by an admin (SNMP) utility.  It actually passes through the
      IP Router Manager, but all that does is demux the call to the
      desired routing protocol. We verify the parameters and return the
      information if we can
      
  Arguments


  Return Value
      ERROR_INSUFFICIENT_BUFFER
      ERROR_INVALID_PARAMETER
      ERROR_NO_DATA
      ERROR_NO_MORE_ITEMS
      ERROR_INVALID_INDEX
      NO_ERROR

--*/
{
    PPROTO_MIB_QUERY    pQuery;
    PPROTO_MIB_RESPONSE pResponse;
    PPROTO_MIB_INTF     pMibIf;
    PPROTO_MIB_GLOBAL   pMibGlobal;
    ULONG               ulNumIndices;
    DWORD               dwResult;
    
    
    EnterProtocolApi();

    TraceEnter("MibGet");

    if(dwInputSize < sizeof(DWORD))
    {
        //
        // Need atleas the OID to do the get
        //

        TraceLeave("MibGet");

        ExitProtocolApi();
        
        return ERROR_INVALID_PARAMETER;
    }

    //
    // The input to the function is the query
    //
    
    pQuery      = (PPROTO_MIB_QUERY)pInputData;
    pResponse   = (PPROTO_MIB_RESPONSE)pOutputData;
    
    //
    // It would be really bad if someone messed the sizes up
    //
    
    ASSERT(dwInputSize%sizeof(DWORD) == 0);
    
    ulNumIndices = NUM_INDICES(dwInputSize);

    dwResult = NO_ERROR;
    
    switch(pQuery->dwOid)
    {
        case PROTO_MIB_GLOBAL_ID:
        {
            //
            // The output size needed is the PROTO_MIB_RESPONSE + just
            // enough for the structure we need. We dont need space for
            // the whole union
            //
            
            if(*pdwOutputSize < FIELD_OFFSET(PROTO_MIB_RESPONSE, mgGlobal) + sizeof(PROTO_MIB_GLOBAL))
            {
                *pdwOutputSize = FIELD_OFFSET(PROTO_MIB_RESPONSE, mgGlobal) + sizeof(PROTO_MIB_GLOBAL);
                
                dwResult = ERROR_INSUFFICIENT_BUFFER;

                break;
            }

            *pdwOutputSize = FIELD_OFFSET(PROTO_MIB_RESPONSE, mgGlobal) + sizeof(PROTO_MIB_GLOBAL);
            
            pResponse->dwOid = PROTO_MIB_GLOBAL_ID;

            EnterCriticalSection(&g_csGlobalInfoLock);
            
            pResponse->mgGlobal.dwLogLevel = g_dwLogLevel;

            LeaveCriticalSection(&g_csGlobalInfoLock);
            
            break;
        }
        case PROTO_MIB_INTF_ID:
        {
            EnterCriticalSection(&g_csIfListLock);

            dwResult = LocateInterface(QUERY_TYPE_GET,
                                       pQuery,
                                       ulNumIndices,
                                       pResponse,
                                       pdwOutputSize);
            

            LeaveCriticalSection(&g_csIfListLock);
            
            break;
        }
        default:
        {
            dwResult = ERROR_INVALID_PARAMETER;

            break;
        }
    }

    TraceLeave("MibGet");

    ExitProtocolApi();
        
    return dwResult;
}