SnmpSharpNet.AsnType.BuildHeader C# (CSharp) Method

BuildHeader() static private method

Build ASN.1 header in the MutableByte array.
Header is the TL part of the TLV (type, length, value) BER encoded data representation. Each value is encoded as a Type byte, length of the data field and the actual, encoded data. This method will encode the type and length fields.
static private BuildHeader ( MutableByte mb, byte asnType, int asnLength ) : void
mb MutableByte MurableByte array
asnType byte ASN.1 header type
asnLength int Length of the data contained in the header
return void
        internal static void BuildHeader(MutableByte mb, byte asnType, int asnLength)
        {
            mb.Append(asnType);
            BuildLength(mb, asnLength);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Encode SNMP packet for sending.
        /// </summary>
        /// <returns>BER encoded SNMP packet.</returns>
        public override byte[] Encode()
        {
            MutableByte buf = new MutableByte();

            if (Pdu.Type != PduType.Get && Pdu.Type != PduType.GetNext &&
                Pdu.Type != PduType.Set && Pdu.Type != PduType.V2Trap &&
                Pdu.Type != PduType.Response && Pdu.Type != PduType.GetBulk &&
                Pdu.Type != PduType.Inform)
            {
                throw new SnmpInvalidPduTypeException("Invalid SNMP PDU type while attempting to encode PDU: " + string.Format("0x{0:x2}", Pdu.Type));
            }

            // snmp version
            _protocolVersion.Encode(buf);

            // community string
            _snmpCommunity.Encode(buf);

            // pdu
            _pdu.Encode(buf);

            // wrap the packet into a sequence
            MutableByte tmpBuf = new MutableByte();

            AsnType.BuildHeader(tmpBuf, SnmpConstants.SMI_SEQUENCE, buf.Length);

            buf.Prepend(tmpBuf);
            return(buf);
        }
All Usage Examples Of SnmpSharpNet.AsnType::BuildHeader