RocDove 2014-12-04 09:32 采纳率: 0%
浏览 1020

如何扩张windows自带的snmp

我在扩展snmp时,自己编写的SnmpExtensionInit函数能被调用,但是在用snmpget获取自己扩展的节点时,无法调用预期的SnmpExtensionQuery函数。猜测是在SnmpExtensionInit函数中对象没能注册成功。下面列出部分代码:

#include
#include
#include
#include "testmib.h"
#pragma comment(lib,"Snmpapi.lib")

//#define OID_SIZEOF( Oid ) ( sizeof Oid / sizeof(UINT) )

// template MIB entry
struct MIB_ENTRY
{
AsnObjectIdentifier asnOid;
void * pStorageValue;
CHAR * szStorageName;
BYTE chType;
UINT unAccess;
MIB_ENTRY* pMibNext;
};

UINT g_unMyOIDPrefix[] = {1, 3, 6, 1, 4, 1, 15};
UINT g_unAgeOid[] = {1,1,1};

AsnObjectIdentifier MIB_OidPrefix = { OID_SIZEOF(g_unMyOIDPrefix), g_unMyOIDPrefix};

DWORD g_dwStartTime = 0;

int g_age = 0;

struct MIB_ENTRY g_MyMibTable[] = {

{
    {OID_SIZEOF(g_unAgeOid),g_unAgeOid},
    &g_age,
    "Age",
    ASN_INTEGER,
    SNMP_ACCESS_READ_WRITE,
    NULL
}

};

UINT g_unMyMibCount = (sizeof(g_MyMibTable) / sizeof(MIB_ENTRY));

BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
// TerminateThread(g_hTrapGenThread,0);
// CloseHandle(g_hTrapGenThread);
// CloseHandle(g_hSimulateTrap);
break;
}
return TRUE;
}

// When exported funtion will be called during DLL loading and initialization
BOOL SNMP_FUNC_TYPE SnmpExtensionInit(DWORD dwUptimeReference,HANDLE *phSubagentTrapEvent, AsnObjectIdentifier *pFirstSupportedRegion)
{
*phSubagentTrapEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // creaet this event for the trap

SnmpUtilOidCpy(pFirstSupportedRegion, &MIB_OidPrefix);
//*pFirstSupportedRegion = MIB_OidPrefix;

// *phSubagentTrapEvent = g_hSimulateTrap; // by assigning it pass it to the SNMP service
// So when ever you set this event service will call
// SnmpExtensionTrap exported function

// hard coded initialization

g_age = 0;

g_dwStartTime = GetTickCount();

return SNMPAPI_NOERROR;

}

// this export is to query the MIB table and fields
BOOL SNMP_FUNC_TYPE SnmpExtensionQuery(BYTE bPduType, SnmpVarBindList *pVarBindList, AsnInteger32 *pErrorStatus, AsnInteger32 *pErrorIndex)
{
int nRet = 0;
UINT i = 0;
//AsnObjectName tt;

*pErrorStatus = SNMP_ERRORSTATUS_NOERROR;
*pErrorIndex = 0;

for 
    (
    ;
i < pVarBindList->len;
++i)
{
    *pErrorStatus = SNMP_ERRORSTATUS_NOERROR;

    // what type of request we are getting?
    switch(bPduType)
    {
    case SNMP_PDU_GET:// // gets the variable value passed variable in pVarBindList
        pVarBindList->list[i].value.asnType = ASN_INTEGER;
        pVarBindList->list[i].value.asnValue.number = g_age;
        if(*pErrorStatus != SNMP_ERRORSTATUS_NOERROR)
            *pErrorIndex++;
        break;
    case SNMP_PDU_GETNEXT: // gets the next variable related to the passed variable in pVarBindList

        *pErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
        *pErrorIndex++;
        break;
    case SNMP_PDU_SET: // sets a variable
        g_age = pVarBindList->list[i].value.asnValue.counter;
        *pErrorStatus = SNMP_ERRORSTATUS_NOERROR;
            //*pErrorIndex++;
        break;
    default:
        *pErrorStatus = SNMP_ERRORSTATUS_NOSUCHNAME;
        *pErrorIndex++;
    }
}   

return SNMPAPI_NOERROR;

}

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-10-25 18:43
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题