public Pdu processIncomingTrap(byte[] message) throws DecodingException, IOException { int l = message.length; byte[] copyOfMessage = new byte[l]; System.arraycopy(message, 0, copyOfMessage, 0, l); AsnDecoder rpdu = new AsnDecoder(); ByteArrayInputStream in = new ByteArrayInputStream(message); AsnSequence asnTopSeq = rpdu.DecodeSNMPv3(in); AsnPduSequence pduSeq = rpdu.processSNMPv3(this, asnTopSeq, copyOfMessage); TrapPduv2 trapPdu = new uk.co.westhawk.snmp.pdu.OneTrapPduv2(this); trapPdu.fillin(pduSeq); return trapPdu; }
/** Processes an incoming SNMP v3 message. */ protected void ProcessIncomingMessage(AsnDecoder rpdu, ByteArrayInputStream in) throws DecodingException, IOException { byte[] bu = null; // need to duplicate the message for V3 to rewrite int nb = in.available(); bu = new byte[nb]; in.read(bu); in = new ByteArrayInputStream(bu); AsnSequence asnTopSeq = rpdu.DecodeSNMPv3(in); int msgId = rpdu.getMsgId(asnTopSeq); Integer rid = (Integer) msgIdHash.get(new Integer(msgId)); if (rid != null) { if (AsnObject.debug > 6) { System.out.println( "SnmpContextv3.ProcessIncomingMessage(): msgId=" + msgId + ", Pdu reqId=" + rid); } Pdu pdu = getPdu(rid); try { AsnPduSequence pduSeq = rpdu.processSNMPv3(this, asnTopSeq, bu); if (pduSeq != null) { // got a message Integer rid2 = new Integer(pduSeq.getReqId()); if (AsnObject.debug > 6) { System.out.println("SnmpContextv3.ProcessIncomingMessage():" + " rid2=" + rid2); } Pdu newPdu = null; if (rid2.intValue() != rid.intValue()) { newPdu = getPdu(rid2); if (AsnObject.debug > 3) { System.out.println( "ProcessIncomingMessage(): " + "pduReqId of msgId (" + rid.intValue() + ") != pduReqId of Pdu (" + rid2.intValue() + ")"); } if (newPdu == null) { if (AsnObject.debug > 3) { System.out.println( "ProcessIncomingMessage(): " + "Using pduReqId of msgId (" + rid.intValue() + ")"); } } } if (newPdu != null) { pdu = newPdu; } } else { if (AsnObject.debug > 6) { System.out.println("SnmpContextv3.ProcessIncomingMessage():" + " pduSeq is null."); } } if (pdu != null) { pdu.fillin(pduSeq); } else { if (AsnObject.debug > 6) { System.out.println("ProcessIncomingMessage(): No Pdu with reqid " + rid.intValue()); } } } catch (DecodingException exc) { if (pdu != null) { pdu.setErrorStatus(AsnObject.SNMP_ERR_DECODING_EXC, exc); pdu.fillin(null); } else { throw exc; } } } else { if (AsnObject.debug > 3) { System.out.println("Pdu of msgId " + msgId + " is already answered"); } rid = new Integer(-1); } }