Exemplo n.º 1
0
        /// <summary>
        /// Constructs a Managed Protocol Data Unit from a List of Byte
        /// </summary>
        /// <param name="Pdu">The List of Byte to Construct a Protocol Data Unit from</param>
        public ProtocolDataUnit(List <byte> SnmpPacket)
        {
            int Pos = 0;
            int End = BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, SnmpType.Sequence);

            Version       = BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);
            CommunityName = BasicEncodingRules.DecodeOctetString(BasicEncodingRules.DecodeOctetString(ref SnmpPacket, ref Pos));
            PduType       = (SnmpType)SnmpPacket[Pos];

            BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, PduType);
            RequestId   = (int)BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);
            ErrorStatus = (ErrorStatus)BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);
            ErrorIndex  = (int)BasicEncodingRules.DecodeInteger32(ref SnmpPacket, ref Pos);

            //Gets PDU Length
            int pduLeng = BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, SnmpType.Sequence);

            if (Pos >= End)
            {
                return;
            }
            Bindings = new List <Variable>();
            while (Pos < End)
            {
                try
                {
                    BasicEncodingRules.DecodeLength(ref SnmpPacket, ref Pos, SnmpType.Sequence);
                    Bindings.Add(BasicEncodingRules.DecodeSequence(ref SnmpPacket, ref Pos));
                }
                catch
                {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a Varaible from a List of bytes
        /// </summary>
        /// <param name="bytes">The List of bytes</param>
        /// <returns>A Variable constructs from the given bytes</returns>
        public static Variable FromBytes(List <byte> bytes)
        {
            int      position = 0;
            Variable result   = new Variable();

            if (bytes[position].ToSnmpType() == SnmpType.ObjectIdentifier)
            {
                result.Identifier = BasicEncodingRules.DecodeObjectId(ref bytes, ref position);
            }
            result.TypeCode = bytes[position].ToSnmpType();
            int Length = BasicEncodingRules.DecodeLength(ref bytes, ref position, result.TypeCode);

            result.Value = bytes.GetRange(position, Length);
            return(result);
        }