本文整理汇总了C++中Pdu::set_context_name方法的典型用法代码示例。如果您正苦于以下问题:C++ Pdu::set_context_name方法的具体用法?C++ Pdu::set_context_name怎么用?C++ Pdu::set_context_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pdu
的用法示例。
在下文中一共展示了Pdu::set_context_name方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetRequest
/////////////////////////////////////////////////////////////////////////////
// 函数:SetRequest //
// 说明:设置简单变量的结果 //
// 参数:无 //
// 返回值: //
// 成功返回0,否则返回一个非0 值 //
/////////////////////////////////////////////////////////////////////////////
int BasicSNMP::SetRequest()
{
int nResult = 0;
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid(oid); // set the Oid portion of the Vb
vb.set_value(m_nOIDValue); // set the Oid portion of the Vb
pdu += vb;
SnmpTarget *target;// = &ctarget;
if(version ==version3)
{//If SNMP Version Is 3
nResult = InitUTarget();//Init UTarget
pdu.set_security_level( m_nSecurityLevel);//Set the Security Level portion of Pdu
pdu.set_context_name (contextName);//Set the Context Name portion of Pdu
pdu.set_context_engine_id(contextEngineID);//Set the Context Engine ID portion of Pdu
target = &utarget; //Set SNMP Target
}
else
{
target = &ctarget; //Set SNMP Target
}
nResult = pSnmp->set(pdu,*target);//Get Reques
return nResult;
}
示例2: push_button_get_next_clicked
// issue a GET-NEXT request
void MainWindow::push_button_get_next_clicked()
{
int status;
if (!snmp)
return;
push_button_get_next->setEnabled(false);
// Create a Oid and a address object from the entered values
Oid oid(line_edit_obj_id->text());
UdpAddress address(line_edit_target->text());
// check if the address is valid
// One problem here: if a hostname is entered, a blocking DNS lookup
// is done by the address object.
if (!address.valid())
{
QString err = QString("\nInvalid Address or DNS Name: %1\n")
.arg(line_edit_target->text());
text_edit_output->append(err);
push_button_get_next->setEnabled(true);
return;
}
Pdu pdu; // empty Pdu
Vb vb; // empty Vb
SnmpTarget *target; // will point to a CTarget(v1/v2c) or UTarget (v3)
// Set the Oid part of the Vb
vb.set_oid(oid);
// Add the Vb to the Pdu
pdu += vb;
// Get retries and timeout values
int retries = spin_box_retries->value();
int timeout = 100 * spin_box_timeout->value();
if (radio_button_v3->isChecked())
{
// For SNMPv3 we need a UTarget object
UTarget *utarget = new UTarget(address);
utarget->set_version(version3);
utarget->set_security_model(SNMP_SECURITY_MODEL_USM);
utarget->set_security_name(combo_box_sec_name->currentText());
target = utarget;
// set the security level to use
if (combo_box_sec_level->currentText() == "noAuthNoPriv")
pdu.set_security_level(SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV);
else if (combo_box_sec_level->currentText() == "authNoPriv")
pdu.set_security_level(SNMP_SECURITY_LEVEL_AUTH_NOPRIV);
else
pdu.set_security_level(SNMP_SECURITY_LEVEL_AUTH_PRIV);
// Not needed, as snmp++ will set it, if the user does not set it
pdu.set_context_name(line_edit_context_name->text());
pdu.set_context_engine_id(line_edit_context_engine_id->text());
}
else
{
// For SNMPv1/v2c we need a CTarget
CTarget *ctarget = new CTarget(address);
if (radio_button_v2->isChecked())
ctarget->set_version(version2c);
else
ctarget->set_version(version1);
// set the community
ctarget->set_readcommunity( line_edit_community->text());
target = ctarget;
}
target->set_retry(retries); // set the number of auto retries
target->set_timeout(timeout); // set timeout
// Now do an async get_next
status = snmp->get_next(pdu, *target, callback, this);
// Could we send it?
if (status == SNMP_CLASS_SUCCESS)
{
timer.start(100);
}
else
{
QString err = QString("\nCould not send async GETNEXT request: %1\n")
.arg(Snmp::error_msg(status));
text_edit_output->append(err);
push_button_get_next->setEnabled(true);
}
// the target is no longer needed
//.........这里部分代码省略.........
示例3: main
//.........这里部分代码省略.........
int construct_status;
v3_MP = new v3MP(engineId, snmpEngineBoots, construct_status);
USM *usm = v3_MP->get_usm();
usm->add_usm_user(securityName,
authProtocol, privProtocol,
authPassword, privPassword);
}
else
{
// MUST create a dummy v3MP object if _SNMPv3 is enabled!
int construct_status;
v3_MP = new v3MP("dummy", 0, construct_status);
}
#endif
//--------[ build up SNMP++ object needed ]-------------------------------
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( oid); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
address.set_port(port);
CTarget ctarget( address); // make a target using the address
#ifdef _SNMPv3
UTarget utarget( address);
if (version == version3) {
utarget.set_version( version); // set the SNMP version SNMPV1 or V2 or V3
utarget.set_retry( retries); // set the number of auto retries
utarget.set_timeout( timeout); // set timeout
utarget.set_security_model( securityModel);
utarget.set_security_name( securityName);
pdu.set_security_level( securityLevel);
pdu.set_context_name (contextName);
pdu.set_context_engine_id(contextEngineID);
}
else {
#endif
ctarget.set_version( version); // set the SNMP version SNMPV1 or V2
ctarget.set_retry( retries); // set the number of auto retries
ctarget.set_timeout( timeout); // set timeout
ctarget.set_readcommunity( community); // set the read community name
#ifdef _SNMPv3
}
#endif
//-------[ issue the request, blocked mode ]-----------------------------
cout << "SNMP++ GetNext to " << argv[1] << " SNMPV"
#ifdef _SNMPv3
<< ((version==version3) ? (version) : (version+1))
#else
<< (version+1)
#endif
<< " Retries=" << retries
<< " Timeout=" << timeout * 10 <<"ms";
#ifdef _SNMPv3
if (version == version3)
cout << endl
<< "securityName= " << securityName.get_printable()
<< ", securityLevel= " << securityLevel
<< ", securityModel= " << securityModel << endl
<< "contextName= " << contextName.get_printable()
<< ", contextEngineID= " << contextEngineID.get_printable()
<< endl;
else
#endif
cout << " Community=" << community.get_printable() << endl << flush;
SnmpTarget *target;
#ifdef _SNMPv3
if (version == version3)
target = &utarget;
else
#endif
target = &ctarget;
status = snmp.get_next( pdu, *target, callback,NULL);
if (status == SNMP_CLASS_SUCCESS)
{
cout << "Async GetNext Request sent." << endl;
}
else
cout << "SNMP++ GetNext Error, " << snmp.error_msg( status)
<< " (" << status <<")" << endl ;
for (int t=1; t<=10; t++)
{
snmp.eventListHolder->SNMPProcessPendingEvents();
#ifdef WIN32
Sleep(1000);
#else
sleep(1);
#endif
}
Snmp::socket_cleanup(); // Shut down socket subsystem
}
示例4: GetBulkRequest
int CSVBaseSNMP::GetBulkRequest(MonitorResult &ResultList)
{
WriteLog("\n\n*****************************");
WriteLog("GetBulkRequest!");
static const int BULK_BUFF = 10;
int nResult = 0;
char chPrvOID[MAX_BUFF_LEN] = {0};
bool bEnd = false;
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( oid); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
SnmpTarget *target;
if(version ==version3)
{//If SNMP Version Is 3
nResult = InitUTarget(); //Init UTarget
pdu.set_security_level( m_lSecurityLevel); //Set the Security Level portion of Pdu
pdu.set_context_name (m_szContextName); //Set the Context Name portion of Pdu
pdu.set_context_engine_id(m_szContextEngineID); //Set the Context Engine ID portion of Pdu
target = &m_Utarget; //Set SNMP Target
}
else
{
target = &m_Ctarget; //Set SNMP Target
}
try
{
if(m_pSnmp)
{
int nIndex = 0, i = 0;
while (( nResult = m_pSnmp->get_bulk(pdu, *target, 0, BULK_BUFF)) == SNMP_CLASS_SUCCESS)
{
if(bEnd)
break;
for (i = 0; i < pdu.get_vb_count(); i ++)
{
pdu.get_vb( vb, i);
if (pdu.get_type() == REPORT_MSG)
{
Oid tmp;
vb.get_oid(tmp);
return -5;
}
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW)
{
string szOID = vb.get_printable_oid();
WriteLog(szOID.c_str());
int nPosition = static_cast<int>(szOID.find(m_szStartID));
if(nPosition < 0)
{
bEnd = true;
break;
}
if(static_cast<int>(strlen(chPrvOID)) > 0)
{//如果上次OID不为空
if(strcmp(vb.get_printable_oid(), chPrvOID) == 0)
{//比较OID名称是否相同,相同则退出循环
bEnd = true;
break;
}
}
//结果赋值
if(static_cast<int>(strlen(vb.get_printable_oid())) < MAX_BUFF_LEN)
strcpy(chPrvOID, vb.get_printable_oid());
SNMP_Monitor_Result result;
result.m_szOID = vb.get_printable_oid();
if(strcmp(result.m_szOID.substr(0,19).c_str(),"1.3.6.1.2.1.2.2.1.2")==0)
{
char str[100];
vb.get_value(str);
result.m_szValue=str;
WriteLog(str);
}
else
result.m_szValue = vb.get_printable_value();
//nPosition = static_cast<int>(result.m_szOID.find(m_szStartID.c_str()) + m_szStartID.length());
//if(nPosition > 0)
//{
result.m_szIndex = result.m_szOID.substr(m_szStartID.length() + 1);
result.m_szOID = result.m_szOID.substr(0, m_szStartID.length());
//PrintDebugString("index is " + result.m_szIndex);
//}
WriteLog(result.m_szIndex.c_str());
WriteLog(result.m_szValue.c_str());
ResultList[nIndex] = result;
nIndex ++;
}
else
{
m_szErrorMsg = "End of MIB Reached";
return -4;
//.........这里部分代码省略.........
示例5: GetRequest
int CSVBaseSNMP::GetRequest(MonitorResult &ResultList)
{
WriteLog("\n\n*****************************");
WriteLog("GetRequest!");
int nResult = 0;
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( oid); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
SnmpTarget *target;
if(version == version3)
{//If SNMP Version Is 3
nResult = InitUTarget(); //Init UTarget
pdu.set_security_level( m_lSecurityLevel); //Set the Security Level portion of Pdu
pdu.set_context_name(m_szContextName); //Set the Context Name portion of Pdu
pdu.set_context_engine_id(m_szContextEngineID); //Set the Context Engine ID portion of Pdu
target = &m_Utarget; //Set SNMP Target
}
else
{
target = &m_Ctarget; //Set SNMP Target
}
try
{
//cout << address << endl;
//cout << oid.get_printable() << endl;
if(m_pSnmp)
{
nResult = m_pSnmp->get( pdu,*target); //Get Reques
if(nResult != 0)
{//当有错误发生时候
m_szErrorMsg = m_pSnmp->error_msg(nResult);
return nResult;
}
for ( int i = 0; i < pdu.get_vb_count(); i ++)
{
pdu.get_vb(vb, i);
if (pdu.get_type() == REPORT_MSG)
{
Oid tmp;
vb.get_oid(tmp);
return -5;
}
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW)
{
SNMP_Monitor_Result result;
result.m_szOID = vb.get_printable_oid();
result.m_szValue = vb.get_printable_value();
size_t nPosition = result.m_szOID.rfind(".");
if(nPosition > 0)
{
result.m_szIndex = result.m_szOID.substr(nPosition);
result.m_szOID = result.m_szOID.substr(0, nPosition - 1);
}
WriteLog(result.m_szIndex.c_str());
WriteLog(result.m_szValue.c_str());
ResultList[i] = result;
}
else
{
m_szErrorMsg = "End of MIB Reached";
return -4;
}
}
}
}
catch(...)
{
DWORD dwError = GetLastError();
char szMsg[512] = {0};
int nlen = sprintf(szMsg, "Error Number is %08X --*GetRequest*---", dwError);
DumpLog("snmpmonitor-request", szMsg, nlen);
}
return nResult;
}
示例6: main
//.........这里部分代码省略.........
const char *filename = "snmpv3_boot_counter";
unsigned int snmpEngineBoots = 0;
int status;
status = getBootCounter(filename, engineId, snmpEngineBoots);
if ((status != SNMPv3_OK) && (status < SNMPv3_FILEOPEN_ERROR))
{
cout << "Error loading snmpEngineBoots counter: " << status << endl;
return 1;
}
snmpEngineBoots++;
status = saveBootCounter(filename, engineId, snmpEngineBoots);
if (status != SNMPv3_OK)
{
cout << "Error saving snmpEngineBoots counter: " << status << endl;
return 1;
}
int construct_status;
v3_MP = new v3MP(engineId, snmpEngineBoots, construct_status);
if (construct_status != SNMPv3_MP_OK)
{
cout << "Error initializing v3MP: " << construct_status << endl;
return 1;
}
usm = v3_MP->get_usm();
usm->add_usm_user(securityName,
authProtocol, privProtocol,
authPassword, privPassword);
}
else
{
// MUST create a dummy v3MP object if _SNMPv3 is enabled!
int construct_status;
v3_MP = new v3MP("dummy", 0, construct_status);
}
//--------[ build up SNMP++ object needed ]-------------------------------
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid(Oid("1.3.6.1.2.1.1.1.0")); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
address.set_port(port);
CTarget ctarget( address); // make a target using the address
UTarget utarget( address);
if (version == version3) {
utarget.set_version( version); // set the SNMP version SNMPV1 or V2 or V3
utarget.set_retry( retries); // set the number of auto retries
utarget.set_timeout( timeout); // set timeout
utarget.set_security_model( securityModel);
utarget.set_security_name( securityName);
pdu.set_security_level( securityLevel);
pdu.set_context_name (contextName);
pdu.set_context_engine_id(contextEngineID);
}
else {
ctarget.set_version( version); // set the SNMP version SNMPV1 or V2
ctarget.set_retry( retries); // set the number of auto retries
ctarget.set_timeout( timeout); // set timeout
ctarget.set_readcommunity( community); // set the read community name
}
//-------[ issue the request, blocked mode ]-----------------------------
cout << "SNMP++ Get to " << argv[1] << " SNMPV"
<< ((version==version3) ? (version) : (version+1))
<< " Retries=" << retries
<< " Timeout=" << timeout * 10 <<"ms";
if (version == version3)
cout << endl
<< "securityName= " << securityName.get_printable()
<< ", securityLevel= " << securityLevel
<< ", securityModel= " << securityModel << endl
<< "contextName= " << contextName.get_printable()
<< ", contextEngineID= " << contextEngineID.get_printable()
<< endl;
else
cout << " Community=" << community.get_printable() << endl << flush;
SnmpTarget *target;
if (version == version3)
target = &utarget;
else
target = &ctarget;
Pdu pduKeyChange;
if (version == version3) {
pduKeyChange.set_security_level( securityLevel);
pduKeyChange.set_context_name (contextName);
pduKeyChange.set_context_engine_id(contextEngineID);
}
snmp.get( pdu, *target);
KeyChange(&snmp, pduKeyChange, newUser, newPassword, *target, AUTHKEY);
Snmp::socket_cleanup(); // Shut down socket subsystem
}
示例7: GetBulkRequest
/////////////////////////////////////////////////////////////////////////////
// 函数:GetBulkRequest //
// 说明:得到表格变量的结果 //
// 参数:无 //
// 返回值: //
// 成功返回0,否则返回一个非0 值 //
/////////////////////////////////////////////////////////////////////////////
int BasicSNMP::GetBulkRequest()
{
//puts("BasicSNMP::GetBulkRequest");
int nResult = 0;
char chPrvOID[MAX_BUFF_LEN] = {0};
bool bEnd = false;
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( oid); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
DestroyResultList();
SnmpTarget *target;// = &ctarget;
if(version ==version3)
{//If SNMP Version Is 3
nResult = InitUTarget();//Init UTarget
pdu.set_security_level( m_nSecurityLevel);//Set the Security Level portion of Pdu
pdu.set_context_name (contextName);//Set the Context Name portion of Pdu
pdu.set_context_engine_id(contextEngineID);//Set the Context Engine ID portion of Pdu
target = &utarget; //Set SNMP Target
}
else
{
target = &ctarget; //Set SNMP Target
}
OIDResult *pTemp = new OIDResult();
OIDResult *pPrevResult = pTemp;
//pTemp->pNext = NULL;
pResult = pTemp;
try
{
//SnmpTarget *target = &ctarget;
while (( nResult = pSnmp->get_next(pdu, *target))== SNMP_CLASS_SUCCESS)
{
if(bEnd)
{
break;
}
for ( int z=0;z<pdu.get_vb_count(); z++)
{
pdu.get_vb( vb,z);
if (pdu.get_type() == REPORT_MSG)
{
Oid tmp;
vb.get_oid(tmp);
return -5;
}
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW)
{
char chOID[MAX_BUFF_LEN] = {0};
sprintf(chOID, "%s", vb.get_printable_oid());
char *pDest = strstr(chOID, chOIDStart);
if(pDest == NULL)
{//OID名称是否包含开始OID
bEnd = true;
break;
}
if(strlen(chPrvOID)>0)
{//如果上次OID不为空
if(strcmp(vb.get_printable_oid(), chPrvOID) == 0)
{//比较OID名称是否相同,相同则退出循环
bEnd = true;
break;
}
}
//结果赋值
strcpy(chPrvOID, vb.get_printable_oid());
strcpy(pTemp->chOID, vb.get_printable_oid());
strcpy(pTemp->chValue,vb.get_printable_value());
char *pIndex;
pIndex=pTemp->chOID+strlen(oid.get_printable())+1;
//pTemp->nLen = static_cast<int>(strlen(pTemp->chValue));
//char *pdest = strrchr(pTemp->chOID, '.');
//int nLast = (int)(pdest - pTemp->chOID + 1);
//memcpy(pTemp->chIndex, (pTemp->chOID)+nLast, strlen(pTemp->chOID) - nLast);
strcpy(pTemp->chIndex,pIndex);
//pTemp->chIndex[strlen(pTemp->chOID) - nLast] = '\0';
}
else
{
memset(chErrMsg, 0 , MAX_BUFF_LEN);
strcpy(chErrMsg, "End of MIB Reached");
return -4;
}
if(pTemp->pNext == NULL)
{
//.........这里部分代码省略.........
示例8: GetRequest
/////////////////////////////////////////////////////////////////////////////
// 函数:GetRequest //
// 说明:得到简单变量的结果 //
// 参数:无 //
// 返回值: //
// 成功返回0,否则返回一个非0 值 //
/////////////////////////////////////////////////////////////////////////////
int BasicSNMP::GetRequest()
{
static const char chFile[] = "smmpmonitor.log";
int nResult = 0;
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( oid); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
DestroyResultList();
SnmpTarget *target;// = &ctarget;
if(version ==version3)
{//If SNMP Version Is 3
nResult = InitUTarget();//Init UTarget
pdu.set_security_level( m_nSecurityLevel);//Set the Security Level portion of Pdu
pdu.set_context_name (contextName);//Set the Context Name portion of Pdu
pdu.set_context_engine_id(contextEngineID);//Set the Context Engine ID portion of Pdu
target = &utarget; //Set SNMP Target
}
else
{
target = &ctarget; //Set SNMP Target
}
OIDResult *pTemp = new OIDResult();//construct OIDResult Struct
pTemp->pNext = NULL;
pResult = pTemp;
try
{
nResult = pSnmp->get( pdu,*target);//Get Reques
if(nResult != 0)
{//当有错误发生时候
strcpy(chErrMsg, pSnmp->error_msg(nResult));
return nResult;
}
for ( int z = 0; z < pdu.get_vb_count(); z++)
{
pdu.get_vb( vb,z);
if (pdu.get_type() == REPORT_MSG)
{
Oid tmp;
vb.get_oid(tmp);
return -5;
}
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW)
{
//Set OIDResult Value
if(static_cast<int>(strlen(vb.get_printable_oid())) < MAX_BUFF_LEN)
strcpy(pTemp->chOID, vb.get_printable_oid());
if(static_cast<int>(strlen(vb.get_printable_value())) < MAX_BUFF_LEN)
{
strcpy(pTemp->chValue, vb.get_printable_value());
//pTemp->nLen = static_cast<int>(strlen(pTemp->chValue));
}
char *pdest = strrchr(pTemp->chOID, '.');
if(pdest)
{
(*pdest) = '\0';
pdest ++;
strcpy(pTemp->chIndex, pdest);
}
//if(pdest)
//{
// int nLast = (int)(pdest - pTemp->chOID + 1);
// memcpy(pTemp->chIndex, (pTemp->chOID)+nLast, strlen(pTemp->chOID) - nLast);
// pTemp->chIndex[strlen(pTemp->chOID) - nLast] = '\0';
//}
}
else
{
memset(chErrMsg, 0 , MAX_BUFF_LEN);
strcpy(chErrMsg, "End of MIB Reached");
return -4;
}
}
}
catch(...)
{
DWORD dwError = GetLastError();
char szMsg[512] = {0};
int nlen = sprintf(szMsg, "Error Number is %08X --*GetRequest*---", dwError);
DumpLog(chFile, szMsg, nlen);
//cout << "Error Number is " << dwError << "---*GetRequest*---" << endl;
}
return nResult;
}
示例9: GetNextRequest
/////////////////////////////////////////////////////////////////////////////
// 函数:GetNextRequest //
// 说明:以当前OID变量为开始,得到下一个简单变量的结果 //
// 参数:无 //
// 返回值: //
// 成功返回0,否则返回一个非0 值 //
/////////////////////////////////////////////////////////////////////////////
int BasicSNMP::GetNextRequest()
{
int nResult = 0;
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( oid); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
DestroyResultList();
SnmpTarget *target;// = &ctarget;
if(version ==version3)
{//If SNMP Version Is 3
nResult = InitUTarget();//Init UTarget
pdu.set_security_level( m_nSecurityLevel);//Set the Security Level portion of Pdu
pdu.set_context_name (contextName);//Set the Context Name portion of Pdu
pdu.set_context_engine_id(contextEngineID);//Set the Context Engine ID portion of Pdu
target = &utarget; //Set SNMP Target
}
else
{
target = &ctarget; //Set SNMP Target
}
OIDResult *pTemp = new OIDResult();
pTemp->pNext = NULL;
pResult = pTemp;
//SnmpTarget *target = &ctarget;
nResult = pSnmp->get_next( pdu,*target);
if(nResult != 0)
{//当有错误发生时候
strcpy(chErrMsg, pSnmp->error_msg(nResult));
}
for ( int z=0;z<pdu.get_vb_count(); z++)
{
pdu.get_vb( vb,z);
if (pdu.get_type() == REPORT_MSG)
{
Oid tmp;
vb.get_oid(tmp);
return -5;
}
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW)
{
strcpy(pTemp->chOID, vb.get_printable_oid());
strcpy(pTemp->chValue,vb.get_printable_value());
//pTemp->nLen = static_cast<int>(strlen(pTemp->chValue));
char *pdest = strrchr(pTemp->chOID, '.');
int nLast = (int)(pdest - pTemp->chOID + 1);
memcpy(pTemp->chIndex, (pTemp->chOID)+nLast, strlen(pTemp->chOID) - nLast);
pTemp->chIndex[strlen(pTemp->chOID) - nLast] = '\0';
oid = pTemp->chOID;
}
else
{
// memset(chErrMsg, 0 , MAX_BUFF_LEN);
// strcpy(chErrMsg, "End of MIB Reached");
return -4;
}
}
return nResult;
}
示例10: main_bulk_jun
//.........这里部分代码省略.........
cout << "Error saving snmpEngineBoots counter: " << status << endl;
return 1;
}
int construct_status;
v3_MP = new v3MP(engineId, snmpEngineBoots, construct_status);
USM *usm = v3_MP->get_usm();
usm->add_usm_user(securityName,
authProtocol, privProtocol,
authPassword, privPassword);
}
else
{
// MUST create a dummy v3MP object if _SNMPv3 is enabled!
int construct_status;
v3_MP = new v3MP("dummy", 0, construct_status);
}
#endif
//--------[ build up SNMP++ object needed ]-------------------------------
address.set_port(port);
CTarget ctarget( address); // make a target using the address
#ifdef _SNMPv3
UTarget utarget( address);
if (version == version3) {
utarget.set_version( version); // set the SNMP version SNMPV1 or V2 or V3
utarget.set_retry( retries); // set the number of auto retries
utarget.set_timeout( timeout); // set timeout
utarget.set_security_model( securityModel);
utarget.set_security_name( securityName);
pdu.set_security_level( securityLevel);
pdu.set_context_name (contextName);
pdu.set_context_engine_id(contextEngineID);
}
else {
#endif
ctarget.set_version( version); // set the SNMP version SNMPV1 or V2
ctarget.set_retry( retries); // set the number of auto retries
ctarget.set_timeout( timeout); // set timeout
ctarget.set_readcommunity( community); // set the read community name
#ifdef _SNMPv3
}
#endif
//-------[ issue the request, blocked mode ]-----------------------------
cout << "SNMP++ GetBulk to " << argv[1] << " SNMPV"
#ifdef _SNMPv3
<< ((version==version3) ? (version) : (version+1))
#else
<< (version+1)
#endif
<< " Retries=" << retries
<< " Timeout=" << timeout << "ms"
<< " Non Reptrs=" << non_reps
<< " Max Reps=" << max_reps << endl;
#ifdef _SNMPv3
if (version == version3)
cout << endl
<< "securityName= " << securityName.get_printable()
<< ", securityLevel= " << securityLevel
<< ", securityModel= " << securityModel << endl
<< "contextName= " << contextName.get_printable()
<< ", contextEngineID= " << contextEngineID.get_printable()
<< endl;
示例11: unload
// unload the data into SNMP++ objects
int SnmpMessage::unload(Pdu &pdu, // Pdu object
OctetStr &community, // community object
snmp_version &version, // SNMP version #
OctetStr *engine_id, // optional v3
OctetStr *security_name, // optional v3
long int *security_model,
UdpAddress *from_addr,
Snmp *snmp_session)
{
pdu.clear();
if (!valid_flag)
return SNMP_CLASS_INVALID;
snmp_pdu *raw_pdu;
raw_pdu = snmp_pdu_create(0); // do a "snmp_free_pdu( raw_pdu)" before return
int status;
#ifdef _SNMPv3
OctetStr context_engine_id;
OctetStr context_name;
long int security_level = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
if ((security_model) && (security_name) && (engine_id) && (snmp_session)) {
status = v3MP::I->snmp_parse(snmp_session, raw_pdu,
databuff, (int)bufflen, *engine_id,
*security_name, context_engine_id, context_name,
security_level, *security_model, version, *from_addr);
if (status != SNMPv3_MP_OK) {
pdu.set_request_id( raw_pdu->reqid);
pdu.set_type( raw_pdu->command);
snmp_free_pdu( raw_pdu);
return status;
}
pdu.set_context_engine_id(context_engine_id);
pdu.set_context_name(context_name);
pdu.set_security_level(security_level);
pdu.set_message_id(raw_pdu->msgid);
pdu.set_maxsize_scopedpdu(raw_pdu->maxsize_scopedpdu);
}
else {
#endif
unsigned char community_name[MAX_LEN_COMMUNITY + 1];
int community_len = MAX_LEN_COMMUNITY + 1;
status = snmp_parse(raw_pdu, databuff, (int) bufflen,
community_name, community_len, version);
if (status != SNMP_CLASS_SUCCESS) {
snmp_free_pdu(raw_pdu);
return status;
}
community.set_data( community_name, community_len);
#ifdef _SNMPv3
}
#endif
// load up the SNMP++ variables
pdu.set_request_id(raw_pdu->reqid);
pdu.set_error_status((int) raw_pdu->errstat);
pdu.set_error_index((int) raw_pdu->errindex);
pdu.set_type( raw_pdu->command);
// deal with traps a little different
if ( raw_pdu->command == sNMP_PDU_V1TRAP) {
// timestamp
TimeTicks timestamp;
timestamp = raw_pdu->time;
pdu.set_notify_timestamp( timestamp);
// set the agent address
IpAddress agent_addr(inet_ntoa(raw_pdu->agent_addr.sin_addr));
if (agent_addr != "0.0.0.0")
{
pdu.set_v1_trap_address(agent_addr);
LOG_BEGIN(DEBUG_LOG | 4);
LOG("SNMPMessage: Trap address of received v1 trap");
LOG(agent_addr.get_printable());
LOG_END;
}
// set enterprise, notifyid
Oid enterprise;
if (raw_pdu->enterprise_length >0) {
for (int i=0; i< raw_pdu->enterprise_length; i++) {
enterprise += (int) (raw_pdu->enterprise[i]);
}
pdu.set_notify_enterprise(enterprise);
}
switch (raw_pdu->trap_type) {
case 0:
pdu.set_notify_id(coldStart);
break;
case 1:
pdu.set_notify_id(warmStart);
break;
//.........这里部分代码省略.........
示例12: runable
void* runable(void *data) {
//--------[ build up SNMP++ object needed ]-------------------------------
ssync.lock();
printf("HELLO:%s\n", community.get_printable());
int t = *((int*)data);
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid("1"); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
CTarget ctarget(address[t]); // make a target using the address
#ifdef _SNMPv3
UTarget utarget(address[t]);
if (version == version3) {
utarget.set_version( version); // set the SNMP version SNMPV1 or V2 or V3
utarget.set_retry( retries); // set the number of auto retries
utarget.set_timeout( timeout); // set timeout
utarget.set_security_model( securityModel);
utarget.set_security_name( securityName);
pdu.set_security_level( securityLevel);
pdu.set_context_name (contextName);
pdu.set_context_engine_id(contextEngineID);
}
else {
#endif
ctarget.set_version( version); // set the SNMP version SNMPV1 or V2 or V3
ctarget.set_retry( retries); // set the number of auto retries
ctarget.set_timeout( timeout); // set timeout
ctarget.set_readcommunity( community); // set the read community to use
ctarget.set_writecommunity( community);
#ifdef _SNMPv3
}
#endif
//-------[ issue the request, blocked mode ]-----------------------------
cout << "(" << t << "): "
<< "SNMP++ snmpWalk to " << address[t].get_printable() << " SNMPV"
#ifdef _SNMPv3
<< ((version==version3) ? (version) : (version+1))
#else
<< (version+1)
#endif
<< " Retries=" << retries
<< " Timeout=" << timeout <<"ms";
#ifdef _SNMPv3
if (version == version3)
cout << endl
<< "securityName= " << securityName.get_printable()
<< ", securityLevel= " << securityLevel
<< ", securityModel= " << securityModel << endl
<< "contextName= " << contextName.get_printable()
<< ", contextEngineID= " << contextEngineID.get_printable()
<< endl;
else
#endif
cout << " Community=" << community.get_printable() << endl << flush;
SnmpTarget *target;
#ifdef _SNMPv3
if (version == version3)
target = &utarget;
else
#endif
target = &ctarget;
int status = 0;
int requests = 0;
int objects = 0;
ssync.unlock();
while (( status = snmp->get_bulk( pdu,*target,0,BULK_MAX))
== SNMP_CLASS_SUCCESS)
{
requests++;
ssync.lock();
for ( int z=0;z<pdu.get_vb_count(); z++) {
pdu.get_vb( vb,z);
#ifdef _SNMPv3
if (pdu.get_type() == REPORT_MSG) {
Oid tmp;
vb.get_oid(tmp);
cout << "(" << t << "): " << "Received a reportPdu: "
<< snmp->error_msg( tmp)
<< endl
<< vb.get_printable_oid() << " = "
<< vb.get_printable_value() << endl;
ssync.unlock();
return 0;
}
#endif
objects++;
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW) {
cout << "(" << t << "): "
<< vb.get_printable_oid() << " = ";
cout << vb.get_printable_value() << "\n";
}
else {
cout << "(" << t << "): "
<< "End of MIB Reached\n";
cout << "(" << t << "): "
//.........这里部分代码省略.........