need help with v3 traps
Frank.Fock____t-online.de
Frank.Fock____t-online.de
Thu Dec 13 10:21:46 CET 2001
Hi Laura,
utarget below is freed before you use it! See below:
Best regards,
Frank
Laura Quiroga schrieb:
> I am trying to send v3 traps by following the example in
> snmpTraps.cpp.
> Unfortunately, this does not seem to work for me. I am
> getting an
> exception when it tries to resolve the address.
>
> Here is my code:
> SnmpTarget *target = NULL;
> if (m_nVersion == version3)
> {
> int port = atoi(m_sTargetPort.c_str());
> address.set_port(port);
> UTarget utarget(address);
> utarget.set_version((snmp_version)m_nVersion); // set
> the SNMP
> version SNMPV1 or V2
> utarget.set_security_model(SecurityModel_USM);
> utarget.set_security_name(securityName);
> m_pPdu->set_security_level(SecurityLevel_authNoPriv);
> m_pPdu->set_context_name("receive_trap");
> m_pPdu->set_context_engine_id("receive_trap");
> target = &utarget;
Here the scope of utarget ends and the pointer to
it (&utarget) will be invalid. Thus, you cannot use
target after the closing }.
> }
> else
> {
> CTarget ctarget(address);
> ctarget.set_version((snmp_version)m_nVersion); // set
> the SNMP
> version SNMPV1 or V2
> ctarget.set_readcommunity(community); // set the
> community name to
> use
> target = &ctarget;
This will not work either!
> }
>
> status = snmp.trap(*m_pPdu,*target);
>
> Here is the callstack:
> GenAddress::operator=(const GenAddress & {...}) line 1876
> UTarget::resolve_to_U(OctetStr & {...}, int & 3,
> GenAddress & {...},
> unsigned long & 3435973836, int & -858993460, unsigned
> char & 204) line
> 625
> Snmp::trap(Pdu & {...}, SnmpTarget & {...}) line 1013 +
> 53 bytes
>
> It fails at address = (Address *)(addr.address)->clone();
>
> Any suggestions?
>
> -lxq
>
>
More information about the AGENTPP
mailing list