Ayan
Ayan

Reputation: 31

Encode and Decode SNMP PDU support in Sharpsnmp

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

Upvotes: 0

Views: 330

Answers (1)

Raleigh Krezzler
Raleigh Krezzler

Reputation: 9

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());

Upvotes: 1

Related Questions