zqq_tt
驱动牛犊
驱动牛犊
  • 注册日期2003-05-07
  • 最后登录2007-12-25
  • 粉丝0
  • 关注0
  • 积分114分
  • 威望13点
  • 贡献值0点
  • 好评度9点
  • 原创分0分
  • 专家分0分
阅读:3925回复:2

SnmpMgrRequest出错,哪位大虾帮忙看一下,我急啊

楼主#
更多 发布于:2003-05-07 22:26
我主要想实现获取指定机器的网络流量,这段代码我是想获取该机器所收到的所有数据包的数量,但SnmpMgrRequest返回是0,用getlasterror测试,错误码是8,不知道怎么回事?
#include \"winsnmp.h\"
#include \"mgmtapi.h\"
...................
void go(void)
{
unsigned long nMajorVersion;
unsigned long nMinorVersion;
unsigned long nLevel;
unsigned long nTranslateMode;
unsigned long nRetransmitMode;
    //1.3.6.1.2.1.4.3
unsigned char   OID_ipAdEntMask[] =\"agent\";//{ 1, 3, 6, 1, 2, 1, 4 , 20, 1 ,3 };
smiOCTETS temptext={sizeof(OID_ipAdEntMask)/sizeof(unsigned char),OID_ipAdEntMask };
smiLPCOCTETS otstr=&temptext;

CString OID_ipMask=\"1.3.6.1.2.1.4.20.1.3\";
smiOID destOID;

    CHAR ServerAddress[]=\"11.36.225.190\";
CHAR ClientAddress[]=\"11.36.229.181\";

    HSNMP_SESSION nSession;
HSNMP_CONTEXT nHandle,ngetHandle;
HSNMP_ENTITY  nEntityClient,ngetEntityClient;
HSNMP_ENTITY  nEntityServer,ngetEntityServer;
HSNMP_VBL nVBL;
HSNMP_PDU nPud,ngetPud;
//return to the application the version of the Windows SNMP Application Programming Interface(WINSNMP API)
   /* SnmpStartup(&nMajorVersion,&nMinorVersion,&nLevel,&nTranslateMode,&nRetransmitMode);
//debug begin---------------------------------
TRACE(\"nMajorVersion=%d\\n\",nMajorVersion);
TRACE(\"nMinorVersion=%d\\n\",nMinorVersion);
TRACE(\"nLevel=%d\\n\",nLevel);
TRACE(\"nTranslateMode=%d\\n\",nTranslateMode);
TRACE(\"nRetransmitMode=%d\\n\",nRetransmitMode);
//debug end-----------------------------------*/
    LPSNMP_MGR_SESSION pp;
  

//*-----------------------------------------------------------------------------
UINT OID_ipInReceives[] = {1, 3, 6, 1, 2, 1, 4, 3};
AsnObjectIdentifier MIB_ipInReceives = {sizeof(OID_ipInReceives) / sizeof(UINT), OID_ipInReceives};

RFC1157VarBindList varBindList;
    //SnmpVarBind     varBind[2];
AsnInteger errorStatus;
AsnInteger errorIndex;
AsnObjectIdentifier MIB_NULL = {0, 0};
int ret;
UINT NICCount = 0, ifIndex = 0, i,successflag;
    
varBindList.list = NULL;
varBindList.len = 1;

if( ( varBindList.list = (RFC1157VarBind *) SNMP_realloc
    (varBindList.list,sizeof(RFC1157VarBind))) == NULL)
    {  
         successflag = 0;
         return;
    }

varBindList.list[varBindList.len - 1].name = MIB_ipInReceives;
varBindList.list[varBindList.len - 1].value.asnType =ASN_NULL;

//SnmpUtilOidCpy(&varBind[0].name, &MIB_ipInReceives);

if(pp=SnmpMgrOpen(\"11.36.225.190\",\"4006\",200,3))
TRACE(\"SnmpMgrOpen execute succeed\\n\");

if(ret=SnmpMgrRequest(pp,SNMP_PDU_GETNEXT,&varBindList, &errorStatus, &errorIndex))
TRACE(\"SnmpMgrRequest execute succeed\\n\");
}
}
zqq_tt
驱动牛犊
驱动牛犊
  • 注册日期2003-05-07
  • 最后登录2007-12-25
  • 粉丝0
  • 关注0
  • 积分114分
  • 威望13点
  • 贡献值0点
  • 好评度9点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-05-07 22:31
上一段代码比较乱,改正如下,请指教
#include \"winsnmp.h\"
#include \"mgmtapi.h\"
...................
void go(void)
{ #include \"winsnmp.h\"
#include \"mgmtapi.h\"

unsigned long nMajorVersion;
unsigned long nMinorVersion;
unsigned long nLevel;
unsigned long nTranslateMode;
unsigned long nRetransmitMode;

        HSNMP_SESSION nSession;
HSNMP_CONTEXT nHandle;
HSNMP_ENTITY  nEntityClient;
HSNMP_ENTITY  nEntityServer;
HSNMP_VBL nVBL;
HSNMP_PDU nPud;

    SnmpStartup(&nMajorVersion,&nMinorVersion,&nLevel,&nTranslateMode,&nRetransmitMode);
//debug begin---------------------------------
TRACE(\"nMajorVersion=%d\\n\",nMajorVersion);
TRACE(\"nMinorVersion=%d\\n\",nMinorVersion);
TRACE(\"nLevel=%d\\n\",nLevel);
TRACE(\"nTranslateMode=%d\\n\",nTranslateMode);
TRACE(\"nRetransmitMode=%d\\n\",nRetransmitMode);
//debug end-----------------------------------
    LPSNMP_MGR_SESSION pp;
  

//*-----------------------------------------------------------------------------
UINT OID_ipInReceives[] = {1, 3, 6, 1, 2, 1, 4, 3};
AsnObjectIdentifier MIB_ipInReceives = {sizeof(OID_ipInReceives) / sizeof(UINT), OID_ipInReceives};

RFC1157VarBindList varBindList;
    //SnmpVarBind     varBind[2];
AsnInteger errorStatus;
AsnInteger errorIndex;
AsnObjectIdentifier MIB_NULL = {0, 0};
int ret;
UINT NICCount = 0, ifIndex = 0, i,successflag;
    
varBindList.list = NULL;
varBindList.len = 1;

if( ( varBindList.list = (RFC1157VarBind *) SNMP_realloc
    (varBindList.list,sizeof(RFC1157VarBind))) == NULL)
    {  
         successflag = 0;
         return;
    }

varBindList.list[varBindList.len - 1].name = MIB_ipInReceives;
    varBindList.list[varBindList.len - 1].value.asnType =ASN_NULL;

if(pp=SnmpMgrOpen(\"11.36.225.190\",\"4006\",200,3))
TRACE(\"SnmpMgrOpen execute succeed\\n\");

if(ret=SnmpMgrRequest(pp,SNMP_PDU_GETNEXT,&varBindList, &errorStatus, &errorIndex))
TRACE(\"SnmpMgrRequest execute succeed\\n\");
}
kingcraft
驱动牛犊
驱动牛犊
  • 注册日期2003-06-18
  • 最后登录2003-07-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-07-09 17:12
为何没有人关注?
8的意思是不是密码不对?
游客

返回顶部