本文整理汇总了C++中Pdu::get_type方法的典型用法代码示例。如果您正苦于以下问题:C++ Pdu::get_type方法的具体用法?C++ Pdu::get_type怎么用?C++ Pdu::get_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pdu
的用法示例。
在下文中一共展示了Pdu::get_type方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: callback
void callback( int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *cd)
{
Vb nextVb;
int pdu_error;
cout << "reason: " << reason << endl
<< "msg: " << snmp->error_msg(reason) << endl;
pdu_error = pdu.get_error_status();
if (pdu_error) {
cout << "Response contains error: "
<< snmp->error_msg(pdu_error)<< endl;
}
for (int i=0; i<pdu.get_vb_count(); i++)
{
pdu.get_vb(nextVb, i);
cout << "Oid: " << nextVb.get_printable_oid() << endl
<< "Val: " << nextVb.get_printable_value() << endl;
}
if (pdu.get_type() == sNMP_PDU_INFORM) {
cout << "pdu type: " << pdu.get_type() << endl;
cout << "sending response to inform: " << endl;
nextVb.set_value("This is the response.");
pdu.set_vb(nextVb, 0);
snmp->response(pdu, target);
}
cout << endl;
}
示例2: KeyChange
void KeyChange(Snmp* snmp, Pdu& myPdu,
const OctetStr& user, const OctetStr& newpass,
SnmpTarget& target, int type)
{
struct UsmKeyUpdate *uku = NULL;
int stat;
int status;
uku = usm->key_update_prepare(user, target, newpass,
myPdu, type, stat);
if (uku == NULL)
cout << "Key update preparation failed *************" << endl
<< "with " << snmp->error_msg(stat) << endl <<endl;
if (( status = snmp->set( myPdu,target)) == SNMP_CLASS_SUCCESS) {
Vb vb3;
Oid oid3;
myPdu.get_vb( vb3,0);
vb3.get_oid(oid3);
Vb vb4;
Oid oid4;
myPdu.get_vb( vb4,1);
vb4.get_oid(oid4);
if (myPdu.get_type() == REPORT_MSG) {
cout << "Received a reportPDU! with Oid "
<< oid3.get_printable() << endl
<< snmp->error_msg(oid3) << endl;
usm->key_update_abort(uku);
}
else {
cout << flush << endl
<< "Oid = " << vb3.get_printable_oid() << endl
<< "Value = " << vb3.get_printable_value() << endl;
cout << flush << endl
<< "Oid = " << vb4.get_printable_oid() << endl
<< "Value = " << vb4.get_printable_value() << endl;
int resul = usm->key_update_commit(uku, USM_PasswordAllKeyUpdate);
cout << endl << "result of local key update: "
<< resul << endl;
}
}
else {
cout << "SNMP++ KeyChange Error, " << snmp->error_msg( status)
<< " (" << status <<")"<< endl;
usm->key_update_abort(uku);
}
cout << "******************************** END"
<< endl << endl << flush;
}
示例3: async_callback
void MainWindow::async_callback(int reason, Snmp * /*snmp*/, Pdu &pdu,
SnmpTarget &target)
{
Vb nextVb;
int pdu_error;
QString prefix_text;
QString notify_text;
push_button_get_next->setEnabled(true);
// What is the reason for this callback?
if (reason == SNMP_CLASS_NOTIFICATION)
{
prefix_text = "Trap: ";
// get the notify id for traps
Oid id;
pdu.get_notify_id(id);
notify_text = QString(" ID: %1 Type %2 -- ").arg(id.get_printable())
.arg(pdu.get_type());
}
else if (reason == SNMP_CLASS_ASYNC_RESPONSE)
{
prefix_text = "Response ";
}
else if (reason == SNMP_CLASS_TIMEOUT)
{
prefix_text = "Timeout ";
}
else
{
QString err = QString("\nDid not receive async response/trap: (%1) %2\n")
.arg(reason).arg(Snmp::error_msg(reason));
text_edit_output->append(err);
}
// Look at the error status of the Pdu
pdu_error = pdu.get_error_status();
if (pdu_error)
{
QString err = "\nResponse contains error:\n";
err += Snmp::error_msg(pdu_error);
text_edit_output->append(err);
return;
}
// The Pdu must contain at least one Vb
if (pdu.get_vb_count() == 0)
{
QString err = "\nPdu is empty\n";
text_edit_output->append(err);
return;
}
for (int i=0; i<pdu.get_vb_count(); i++)
{
// Get the Vb of the Pdu
pdu.get_vb(nextVb, i);
// Get Oid and value from the Vb and display it
line_edit_obj_id->setText(nextVb.get_printable_oid());
line_edit_value->setText(nextVb.get_printable_value());
text_edit_output->append(prefix_text +
target.get_address().get_printable() +
" -- " +
notify_text +
line_edit_obj_id->text() + " = " +
line_edit_value->text() + "\n");
}
// If we received a inform pdu, we have to send a response
if (pdu.get_type() == sNMP_PDU_INFORM)
{
text_edit_output->append("Sending response to inform.\n");
// just change the value of the first vb
pdu.get_vb(nextVb, 0);
nextVb.set_value("This is the response.");
pdu.set_vb(nextVb, 0);
snmp->response(pdu, target);
}
}
示例4: switch
wpdu::wpdu(const Pdu& pdu, const UdpTarget& target):
valid_flag_(SNMP_CLASS_INVALID ), comm_len(MAX_COMM_STR_LEN)
{
reset_iov(iovec_);
version_ = target.get_version();
int status;
OctetStr comm_str;
community_name[0] = 0;
snmp_pdu *raw_pdu; // create a raw pdu
raw_pdu = cmu_snmp::pdu_create( (int) pdu.get_type());
if (!raw_pdu) {
valid_flag_ = SNMP_CLASS_RESOURCE_UNAVAIL;
return;
}
raw_pdu->reqid = pdu.get_request_id();
raw_pdu->errstat= (unsigned long) pdu.get_error_status();
raw_pdu->errindex= (unsigned long) pdu.get_error_index();
switch (raw_pdu->command) {
case sNMP_PDU_GET:
case sNMP_PDU_GETNEXT:
target.get_read_community(comm_str);
break;
case sNMP_PDU_SET:
target.get_write_community(comm_str);
break;
case sNMP_PDU_V1TRAP:
target.get_read_community(comm_str);
if (set_trap_info(raw_pdu, pdu)) // will free raw_pdu
return;
break;
case sNMP_PDU_RESPONSE:
break;
default:
ACE_ASSERT(0);
return;
}
if (load_vbs(raw_pdu, pdu)) {
cmu_snmp::free_pdu( raw_pdu);
valid_flag_ = SNMP_CLASS_RESOURCE_UNAVAIL;
return;
}
// TODO: determine how big raw_pdu serializes out to
iovec_.iov_len = target.get_max_pdu_size();
ACE_NEW(iovec_.iov_base, char [iovec_.iov_len]);
// create raw byte stream
// The intermediate integer is to avoid type-punned pointer
// dereferencing.
int out_length = iovec_.iov_len;
status = cmu_snmp::build( raw_pdu,
(unsigned char *)iovec_.iov_base,
&out_length,
target.get_version(),
comm_str.data(),
comm_str.length());
iovec_.iov_len = out_length;
if ( status != 0) {
valid_flag_ = SNMP_ERROR_WRONG_ENCODING;
cmu_snmp::free_pdu( raw_pdu);
return;
}
cmu_snmp::free_pdu( raw_pdu);
valid_flag_ = SNMP_CLASS_SUCCESS;
}
示例5: SetPdu
int CSNMPMessage::SetPdu(const int reason, const Pdu &pdu,
const UdpAddress &fromaddress)
{
if (Pdu::match_type(m_pdu.get_type(), pdu.get_type()) == false)
{
LOG_BEGIN(INFO_LOG | 1);
LOG("MsgQueue: Response pdu type does not match, pdu is ignored: (id) (type1) (type2)");
LOG(m_uniqueId);
LOG(m_pdu.get_type());
LOG(pdu.get_type());
LOG_END;
return -1;
}
unsigned short orig_type = m_pdu.get_type();
if (m_received)
{
LOG_BEGIN(WARNING_LOG | 1);
LOG("MsgQueue: Message is already marked as received (id) (reason) (new reason)");
LOG(m_uniqueId);
LOG(reason);
LOG(m_reason);
LOG_END;
// TODO: better check based on error codes
if (reason || !m_reason)
{
LOG_BEGIN(WARNING_LOG | 1);
LOG("MsgQueue: ignoring the second pdu");
LOG_END;
return 0;
}
}
m_received = 1;
m_pdu = pdu;
m_reason = reason;
if ((orig_type == sNMP_PDU_INFORM) &&
(m_pdu.get_type() == sNMP_PDU_RESPONSE))
{
// remove the first two vbs of the pdu if sysUpTime and notify_id
if (m_pdu.get_vb_count() < 2)
return 0;
const Vb &vb1 = m_pdu.get_vb(0);
if (vb1.get_syntax() != sNMP_SYNTAX_TIMETICKS) return 0;
if (vb1.get_oid() != SNMP_MSG_OID_SYSUPTIME) return 0;
const Vb &vb2 = m_pdu.get_vb(1);
if (vb2.get_syntax() != sNMP_SYNTAX_OID) return 0;
if (vb2.get_oid() != SNMP_MSG_OID_TRAPID) return 0;
TimeTicks timeticks;
Oid oid;
vb1.get_value(timeticks);
m_pdu.set_notify_timestamp(timeticks);
vb2.get_value(oid);
m_pdu.set_notify_id(oid);
m_pdu.delete_vb(1);
m_pdu.delete_vb(0);
}
return 0;
}
示例6: 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;
//.........这里部分代码省略.........
示例7: 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;
}
示例8: 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)
{
//.........这里部分代码省略.........
示例9: 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;
}
示例10: 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;
}
示例11: main
//.........这里部分代码省略.........
cout << "Error initializing v3MP: " << construct_status << endl;
return 1;
}
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);
if (status == SNMP_CLASS_SUCCESS)
{
pdu.get_vb( vb,0);
#ifdef _SNMPv3
if (pdu.get_type() == REPORT_MSG) {
cout << "Received a report pdu: "
<< snmp.error_msg(vb.get_printable_oid()) << endl;
}
#endif
cout << "Oid = " << vb.get_printable_oid() << endl
<< "Value = " << vb.get_printable_value() << endl;
}
else
{
cout << "SNMP++ GetNext Error, " << snmp.error_msg( status)
<< " (" << status <<")" << endl;
}
Snmp::socket_cleanup(); // Shut down socket subsystem
}
示例12: main_bulk_jun
//.........这里部分代码省略.........
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;
else
#endif
cout << " Community=" << community.get_printable() << endl << flush;
SnmpTarget *target;
#ifdef _SNMPv3
if (version == version3)
target = &utarget;
else
#endif
target = &ctarget;
Pdu pdu2 = pdu;
if (( status = snmp.get_bulk( pdu,*target,non_reps,max_reps))== SNMP_CLASS_SUCCESS) {
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 << "Received a reportPdu: "
<< snmp.error_msg( tmp)
<< endl
<< vb.get_printable_oid() << " = "
<< vb.get_printable_value() << endl;
}
#endif
cout << "Oid = " << vb.get_printable_oid() << "\n";
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW) {
cout << "Value = " << vb.get_printable_value() << "\n\n";
}
else {
cout << "End of MIB view.\n\n";
}
}
}
else
cout << "SNMP++ GetBulk Error, " << snmp.error_msg( status) << "\n";
pdu = pdu2;
//--------------------
if (( status = snmp.get_bulk( pdu,*target,non_reps,max_reps))== SNMP_CLASS_SUCCESS) {
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 << "Received a reportPdu: "
<< snmp.error_msg( tmp)
<< endl
<< vb.get_printable_oid() << " = "
<< vb.get_printable_value() << endl;
}
#endif
cout << "Oid = " << vb.get_printable_oid() << "\n";
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW) {
cout << "Value = " << vb.get_printable_value() << "\n\n";
}
else {
cout << "End of MIB view.\n\n";
}
}
}
else
cout << "SNMP++ GetBulk Error, " << snmp.error_msg( status) << "\n";
//-------------
Snmp::socket_cleanup(); // Shut down socket subsystem
}
示例13: 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 << "): "
//.........这里部分代码省略.........