| | |
C++ WinSNMP API:
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2004
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Aug 2004
Posts: 5
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Aug 2004
Posts: 5
Reputation:
Solved Threads: 0
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;
}
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;
}
•
•
Join Date: Aug 2004
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Sep 2005
Posts: 2
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- News Story: MySpace Dev Policy Tweak, New Messaging API Leak (Software Development Job Offers)
- WinSNMP get (C++)
- News Story: Google Base Data API good news for Blogger bloggers (XML, XSLT and XPATH)
Other Threads in the C++ Forum
- Previous Thread: Problem with chars!
- Next Thread: WinSNMP Help
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





