/// <summary> Constructs a new trap pdu that is identical to the /// passed pdu. /// </summary> /// <param name="second">The object to copy. /// </param> public TrapPdu(TrapPdu second) : this() { _enterprise.Set(second._enterprise); _agentAddr.Set(second._agentAddr); _generic.Value = second.Generic; _specific.Value = second.Specific; _timeStamp.Value = second.TimeStamp; for (int x = 0; x < second.VbList.Count; x++) { VbList = (VbCollection)second.VbList.Clone(); } }
/// <summary>Constructs a new trap pdu that is identical to the passed pdu.</summary> /// <param name="second">The object to copy. /// </param> public TrapPdu(TrapPdu second) : this() { enterprise.Set(second.enterprise); agentAddr.Set(second.agentAddr); generic.Value = second.Generic; specific.Value = second.Specific; timeStamp.Value = second.TimeStamp; for (int x = 0; x < second.variables.Count; x++) { variables = (VbCollection)second.VbList.Clone(); } }
/// <summary>Decode BER encoded Pdu</summary> /// <remarks> /// Decodes the protocol data unit from the passed buffer. If an error /// occurs during the decoding sequence then an AsnDecodingException is /// thrown by the method. The value is decoded using the AsnEncoder /// passed to the object. /// </remarks> /// <param name="buffer">BER encoded buffer</param> /// <param name="offset">The offset byte to begin decoding</param> /// <returns>Buffer position after the decoded value</returns> /// <exception cref="OverflowException">Thrown when header points to more data then is available.</exception> public override int Decode(byte[] buffer, int offset) { byte asnType = ParseHeader(buffer, ref offset, out int headerLength); if (offset + headerLength > buffer.Length) { throw new OverflowException("Insufficient data in packet"); } base.Type = asnType; // request id offset = requestId.Decode(buffer, offset); // error status offset = errorStatus.Decode(buffer, offset); // error index offset = errorIndex.Decode(buffer, offset); // clean out the current variables VbList.Clear(); // decode the Variable binding collection offset = VbList.Decode(buffer, offset); // if Pdu is an SNMP version 2 TRAP, remove sysUpTime and trapObjectID from the VarBinds array if (Type == EPduType.V2Trap || Type == EPduType.Inform) { if (VbList.Count > 0) { if (VbList[0].Oid.Equals(SnmpConstants.SysUpTime)) { TrapSysUpTime.Set(VbList[0].Value); VbList.RemoveAt(0); // remove sysUpTime } } if (VbList.Count > 0) { if (VbList[0].Oid.Equals(SnmpConstants.TrapObjectId)) { trapObjectID.Set((Oid)VbList[0].Value); VbList.RemoveAt(0); // remove sysUpTime } } } return(offset); }