Dear all,

I'm developing an SNMP manager using WinSNMP API. While starting up the SNMP by calling the function SnmpStartup, it returns SNMPAPI_SUCCESS, but strangely the 5 output parameters are not defined after the function is executed. Is this normal? Why is this happenning? What should I do?

Regards,
Alan Lewis William Walter

P/S: Pls let me know if there's any url or source code on this particular topic.

It should be either SNMPAPI_OFF or SNMPAPI_ON, right?
Have you checked the return value for these constants?

I'd figured out that it's the way I put the arguments which is wrong. I'd missed out the "&" where there're supposed to be ones.
Anyway, thanks.

Now, my SNMP agent is partially complete. A SNMP manager is created to test the agent's viability.

Dear all,

I have a doubt about this: On creating a single document application, I assigned values to an pre-declared array in OnInitDialog. Somehow after the program had passed the OnInitDialog and the dialog is created, the values in the array were all nullified.
I don't know why is this so. Would anyone out there help clarify me with this?

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;
}

The previous problem has been resolved. It's the problem with the syntax. The syntax need to be set appropriately before the message is sent. Otherwise, the management entity won't be able to read the value you pass to it.

Now, another doubt has emerges. I've declared two smiOIDs in my SNMP agent, and when it's time for me to call the SnmpFreeDescriptor in order to free the resources allocated to them, the first one of them is freed successfully but there's access violation for the second one.

Must I use only one smiOID in my application? Hope somebody out there might help.

Hello Alan,

I am trying to write an SNMP agent with WinSNMP API. From what you have posted, it seems that you got it to work.

I call the startup function, create a session (with a callback function), and call SnmpListen. All of these functions return successfully. But my callback function never gets called, regardless of the messages that I sent to the agent's port.

The SNMP.exe service is running.

I am really stuck here.

Thanks for you help,
Ilya

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.