Reputation: 31
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
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