943,906 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 7911
  • C++ RSS
Aug 3rd, 2004
0

C++ WinSNMP API:

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alan Lewis is offline Offline
5 posts
since Aug 2004
Aug 9th, 2004
0

Re: C++ WinSNMP API:

It should be either SNMPAPI_OFF or SNMPAPI_ON, right?
Have you checked the return value for these constants?
Reputation Points: 13
Solved Threads: 0
Newbie Poster
hivework is offline Offline
18 posts
since Mar 2004
Aug 15th, 2004
0

Re: C++ WinSNMP API:

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alan Lewis is offline Offline
5 posts
since Aug 2004
Aug 18th, 2004
0

Re: C++ WinSNMP API:

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alan Lewis is offline Offline
5 posts
since Aug 2004
Aug 23rd, 2004
0

Re: C++ WinSNMP API:

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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alan Lewis is offline Offline
5 posts
since Aug 2004
Aug 25th, 2004
0

Re: C++ WinSNMP API:

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Alan Lewis is offline Offline
5 posts
since Aug 2004
Sep 23rd, 2005
0

Re: C++ WinSNMP API:

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
CrazyScntst is offline Offline
2 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problem with chars!
Next Thread in C++ Forum Timeline: WinSNMP Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC