Dear all,
Thanks to one of the web member, The previous problem I faced has now been resolved.
Now, I'm facing another problem while trying to generate and send response to the management entity. I've checked using OutputDebugString that the PDU I'm to send contains the values I intended to send. However, the management entity receives the response as containing Null values. Following is the function I use to generate and send the response. Is there anything wrong with my codes?
bool CMibImpl::RespGenerator()
{
m_pRP->m_tRespPDU.m_hVbl = SnmpCreateVbl(m_pRP->m_tSnmpInfo.m_hSession, NULL, NULL);
if(m_pRP->m_tRespPDU.m_hVbl == SNMPAPI_FAILURE)
{
lMsg("SnmpCreateVbl Error");
m_pSnmpError->GetSnmpErrorDescribe(m_pRP->m_tSnmpInfo.m_hSession);
return SNMPAPI_FAILURE;
}
else
{
m_pRP->m_tRespPDU.m_lVblCount = m_pRP->m_tReqPDU.m_lVblCount;
for (int y=1; y<=m_pRP->m_tRespPDU.m_lVblCount; y++)
{
m_pRP->m_tRespPDU.m_tOID[y-1] = m_pRP->m_tReqPDU.m_tOID[y-1];
m_pRP->m_tRespPDU.m_tVALUE[y-1] = m_pRP->m_tReqPDU.m_tVALUE[y-1];
m_nStatus = SnmpSetVb (m_pRP->m_tRespPDU.m_hVbl,
0,
&m_pRP->m_tRespPDU.m_tOID[y-1],
&m_pRP->m_tRespPDU.m_tVALUE[y-1]);
if(m_nStatus == SNMPAPI_FAILURE)
{
lMsg(_T("SnmpSetVb Error"));
m_pSnmpError->GetSnmpErrorDescribe(m_pRP->m_tSnmpInfo.m_hSession);
return SNMPAPI_FAILURE;
}
}
m_pRP->m_tRespPDU.m_lPduType = SNMP_PDU_RESPONSE;
m_pRP->m_tRespPDU.m_hPDU = SnmpCreatePdu (m_pRP->m_tSnmpInfo.m_hSession,
m_pRP->m_tRespPDU.m_lPduType,
m_pRP->m_tRespPDU.m_lReqID,
m_pRP->m_tRespPDU.m_lErrStatus,
m_pRP->m_tRespPDU.m_lErrIndex,
m_pRP->m_tRespPDU.m_hVbl);
if(m_pRP->m_tRespPDU.m_hVbl == SNMPAPI_FAILURE)
{
lMsg("SnmpCreateVbl Error");
m_pSnmpError->GetSnmpErrorDescribe(m_pRP->m_tSnmpInfo.m_hSession);
return SNMPAPI_FAILURE;
}
else
{
m_pRP->m_tRespPDU.m_lpReqId = m_pRP->m_tReqPDU.m_lpReqId;
m_pRP->m_tRespPDU.m_lReqID = m_pRP->m_tReqPDU.m_lReqID;
m_pRP->m_tRespPDU.m_lErrStatus = m_pRP->m_tReqPDU.m_lErrStatus;
m_pRP->m_tRespPDU.m_lErrIndex = m_pRP->m_tReqPDU.m_lErrIndex;
m_nStatus = SnmpSetPduData (m_pRP->m_tRespPDU.m_hPDU,
&m_pRP->m_tRespPDU.m_lPduType,
&m_pRP->m_tReqPDU.m_lReqID,
&m_pRP->m_tReqPDU.m_lErrStatus,
&m_pRP->m_tReqPDU.m_lErrIndex,
&m_pRP->m_tRespPDU.m_hVbl);
if(m_nStatus == SNMPAPI_FAILURE)
{
lMsg(_T("SnmpSetPduData Error"));
m_pSnmpError->GetSnmpErrorDescribe(m_pRP->m_tSnmpInfo.m_hSession);
return SNMPAPI_FAILURE;
}
else
{
CString szDebug;
szDebug.Format (_T("\nDebug String: The value is %u, %u and %u.\n\n"),
m_pRP->m_tRespPDU.m_tVALUE[0].value.uNumber,
m_pRP->m_tRespPDU.m_tVALUE[1].value.uNumber,
m_pRP->m_tRespPDU.m_tVALUE[2].value.uNumber);
OutputDebugString(szDebug);
//m_hDstEntityReq = SnmpStrToEntity(m_hSession, _T("127.0.0.1"));
m_nStatus = SnmpSendMsg (m_pRP->m_tSnmpInfo.m_hSession,
m_pRP->m_tSnmpInfo.m_hAgentEntity,
m_pRP->m_tSnmpInfo.m_hMgrEntity,
m_pRP->m_tSnmpInfo.m_hContextReq,
m_pRP->m_tRespPDU.m_hPDU);
if(m_nStatus == SNMPAPI_FAILURE)
{
lMsg(_T("SnmpSendMsg Error"));
m_pSnmpError->GetSnmpErrorDescribe(m_pRP->m_tSnmpInfo.m_hSession);
return SNMPAPI_FAILURE;
}
}
}
}
return SNMPAPI_SUCCESS;
}