找了半天,好像没有知道解决办法的
  要做基于snmp发现网络拓扑的东西,卡这儿了
  大哥大侠们谁能救救我啊?
  谢谢啦

解决方案 »

  1.   

    API做Get操作,但是总是没有消息返回,SnmpRecvMsg函数错误代码为SNMP_NOOP。就是说没有消息返回
      

  2.   

    ....这还不清楚阿,发Get请求失败了呗.snmp难在语法的解析上,请求就那么几个...
      

  3.   

    to shawnwan() 
    可是先发送查询了,应该接受到回复啊这是发送和接收的代码:bool CMySnmp::Send(CStringArray *pstrArr){
    HSNMP_VBL hVbl;
    HSNMP_PDU hPdu;
    HSNMP_ENTITY hSrcEntity,hDestEntity;
    smiOID oid; //创建变量绑定列表
    hVbl = SnmpCreateVbl(hSession,NULL,NULL);
    if(hVbl == SNMPAPI_FAILURE){
    AfxMessageBox("in send,create vbl failed");
    return FALSE;
    } //循环把请求列表中的项都绑定好
    int size = pstrArr->GetSize();
    for(int i=0;i<size;i++){
    SnmpStrToOid(pstrArr->GetAt(i),&oid); SnmpSetVb(hVbl,0,&oid,NULL);
    } //按照特定pdu格式发送,返回一个pdu句柄
    hPdu = SnmpCreatePdu(hSession,SNMP_PDU_GETNEXT,0,NULL,NULL,hVbl);
    if(hPdu == SNMPAPI_FAILURE){
    AfxMessageBox("SnmpCreatePdu failed");
    return FALSE;
    }
    hSrcEntity=SnmpStrToEntity(hSession,"127.0.0.1");  
    hDestEntity=SnmpStrToEntity(hSession,"127.0.0.1");
    if(hSrcEntity==SNMPAPI_FAILURE || hDestEntity==SNMPAPI_FAILURE){
    AfxMessageBox("SnmpStrToEntity failed");
    return FALSE;
    }
    //发送
    if(SnmpSendMsg(hSession,hSrcEntity,hDestEntity,hContext,hPdu)==SNMPAPI_FAILURE){
    AfxMessageBox("SnmpSendMsg failed");
    return FALSE;
    }
    //释放句柄
    SnmpFreeEntity(hSrcEntity);
    SnmpFreeEntity(hDestEntity);
    SnmpFreePdu(hPdu);
    SnmpFreeVbl(hVbl); return TRUE;
    }
    bool CMySnmp::Receive(HSNMP_VBL &hVbl){
    HSNMP_ENTITY hSrcEntity,hDestEntity;
    HSNMP_CONTEXT hContext;
    HSNMP_PDU hPdu; if(SnmpRecvMsg(hSession,&hSrcEntity,&hDestEntity,&hContext,&hPdu)==SNMPAPI_FAILURE){
    CString strError;
    switch (SnmpGetLastError(hSession))
                    {
                    case SNMPAPI_NOOP:
                            strError="Session当前没有消息在队列中!";
                            break;
                                       break;                          }
                    AfxMessageBox("消息接收失败!"+strError);
    return FALSE;
    } smiINT PDU_type;
    smiINT error_status;
    smiINT error_index; if(SnmpGetPduData(hPdu,&PDU_type,NULL,&error_status,&error_index,&hVbl)==SNMPAPI_FAILURE){
    AfxMessageBox("SnmpGetPduData failed");
    return FALSE;
    }

    return TRUE;
    }