本文整理汇总了C++中Pdu::set_notify_enterprise方法的典型用法代码示例。如果您正苦于以下问题:C++ Pdu::set_notify_enterprise方法的具体用法?C++ Pdu::set_notify_enterprise怎么用?C++ Pdu::set_notify_enterprise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pdu
的用法示例。
在下文中一共展示了Pdu::set_notify_enterprise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
//.........这里部分代码省略.........
示例2: main
//.........这里部分代码省略.........
ptr+=3;
authPassword = ptr;
continue;
}
if ( strstr( argv[x],"-up")!=0) {
ptr = argv[x];
ptr+=3;
privPassword = ptr;
continue;
}
#endif
}
//----------[ create a SNMP++ session ]-----------------------------------
int status;
Snmp *snmp;
if (address.get_ip_version() == Address::version_ipv4)
snmp = new Snmp(status, "0.0.0.0");
else
snmp = new Snmp(status, "::");
if ( status != SNMP_CLASS_SUCCESS) {
cout << "SNMP++ Session Create Fail, " << snmp->error_msg(status) << "\n";
return 1;
}
//---------[ init SnmpV3 ]--------------------------------------------
#ifdef _SNMPv3
if (version == version3) {
char *engineId = "TrapSender";
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);
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; // variable binding object to use
vb.set_oid(PAYLOADID); // example oid for trap payload
vb.set_value(PAYLOAD); // example string for payload
pdu += vb; // append the vb to the pdu
pdu.set_notify_id( oid); // set the id of the trap
pdu.set_notify_enterprise( ent); // set up the enterprise of the trap
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_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_readcommunity( community); // set the read community name
#ifdef _SNMPv3
}
#endif
//-------[ Send the trap ]------------------------------------------------
cout << "SNMP++ Trap to " << argv[1] << " SNMPV"
#ifdef _SNMPv3
<< ((version==version3) ? (version) : (version+1));
#else
<< (version+1);