상속: AsnType, ICloneable
예제 #1
0
 /// <summary>
 /// Decode SNMP packet header. This class decodes the initial sequence and SNMP protocol version
 /// number.
 /// </summary>
 /// <param name="buffer">BER encoded SNMP packet</param>
 /// <param name="length">Packet length</param>
 /// <returns>Offset position after the initial sequence header and protocol version value</returns>
 /// <exception cref="SnmpDecodingException">Thrown when invalid sequence type is found at the start of the SNMP packet being decoded</exception>
 public virtual int decode(byte[] buffer, int length)
 {
     int offset = 0;
     if (length < 2)
     {
         // we need at least 2 bytes
         throw new OverflowException("Packet too small.");
     }
     // make sure you get the right length buffer to be able to check for over/under flow errors
     MutableByte buf = new MutableByte(buffer, length);
     Sequence seq = new Sequence();
     offset = seq.decode(buf, offset);
     if( seq.Type != SnmpConstants.SMI_SEQUENCE )
         throw new SnmpDecodingException("Invalid sequence type at the start of the SNMP packet.");
     offset = _protocolVersion.decode(buf, offset);
     return offset;
 }