Exemplo n.º 1
0
        /// <summary>
        /// Constructs the byte representation of the ProtocolDataUnit
        /// </summary>
        /// <returns>A Byte List which represents the ProtocolDataUnit</returns>
        public List <byte> ToPdu()
        {
            List <byte> Pdu          = new List <byte>();
            List <byte> _RequestId   = BasicEncodingRules.EncodeInteger32(this.RequestId);
            List <byte> _ErrorStatus = BasicEncodingRules.EncodeInteger32((int)this.ErrorStatus);
            List <byte> _ErrorIndex  = BasicEncodingRules.EncodeInteger32(this.ErrorIndex);
            List <byte> _Bindings    = BasicEncodingRules.EncodeSequence(this.Bindings);

            Pdu.AddRange(_RequestId);
            Pdu.AddRange(_ErrorStatus);
            Pdu.AddRange(_ErrorIndex);
            Pdu.AddRange(_Bindings);
            Pdu.InsertRange(0, BasicEncodingRules.EncodeSequenceHeader(PduType, Pdu.Count, true));
            Pdu.TrimExcess();
            return(Pdu);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs the byte representation of the SnmpPacket
        /// </summary>
        /// <returns>A Byte List which represents this ProtocolDataUnit as a SnmpPacket</returns>
        public List <byte> ToPacket(PmppEndPoint?EndPoint)
        {
            try
            {
                List <byte> Bytes = new List <byte>();

                Bytes.AddRange(BasicEncodingRules.EncodeInteger32(this.version));
                Bytes.AddRange(BasicEncodingRules.EncodeOctetString(this.CommunityName));
                Bytes.AddRange(ToPdu());
                Bytes.InsertRange(0, BasicEncodingRules.EncodeSequenceHeader(SnmpType.Sequence, Bytes.Count, true));

                Bytes.TrimExcess();
                if (EndPoint.HasValue)
                {
                    Bytes = Bytes.PmppEncode(EndPoint.Value.Address, EndPoint.Value.Control, EndPoint.Value.ProtocolIdentifier);
                }

                return(Bytes);
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a Integer 32 Variable
 /// </summary>
 /// <param name="value">The System.Integer32 Value of the Variable</param>
 /// <returns>A Integer Variable with the given value</returns>
 public static Variable CreateInteger32(int value)
 {
     return(Variable.FromBytes(BasicEncodingRules.EncodeInteger32(value)));
 }