예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Encode SNMP packet for sending.
        /// </summary>
        /// <returns>BER encoded SNMP packet.</returns>
        public override byte[] Encode()
        {
            MutableByte tmpBuffer = new MutableByte();

            // encode the community strings
            snmpCommunity.Encode(tmpBuffer);
            Pdu.Encode(tmpBuffer);

            Encode(tmpBuffer);

            return(tmpBuffer);
        }