Encode and Decode SNMP PDU support in Sharpsnmp

264 views Asked by At

I like to understand if there are any APIs available in lextm sharpsnmp library to encode SNMPv1/v2c/V3 PDU to byte array and also API to construct a SnmpPdu (SNMP v1/v2c/v3) based on a byte array. Thank you in Advance

1

There are 1 answers

0
Raleigh Krezzler On

To get the raw bytes of a PDU, use ISnmpMessage.ToBytes:

GetRequestMessage getRequest = new(requestID, VersionCode.V1, new OctetString("public"), new Variable[] { variable });

byte[] getRequestBytes = getRequest.ToBytes();

To build a PDU from raw bytes, use MessageFactory.ParseMessages:

byte[] rawBytes = { 0x30, byte2, byte3, ... };

IList<ISnmpMessage> message = MessageFactory.ParseMessages(rawBytes, new UserRegistry());