C# Class SnmpSharpNet.SnmpPacket

Base SNMP packet class.
All SNMP packets begin with the SMI_SEQUENCE header and SNMP protocol version number. This class parses and encodes these values. Derived classes parse further information from SNMP packets.
显示文件 Open project: griffina/SnmpSharpNet Class Usage Examples

Protected Properties

Property Type Description
_protocolVersion Integer32

Public Methods

Method Description
GetProtocolVersion ( byte buffer, int bufferLength ) : int

Get SNMP protocol version from the packet. This routine does not verify if version number is valid. Caller should verify that returned value represents a valid SNMP protocol version number. int protocolVersion = Packet.GetProtocolVersion(inPacket, inLength); if( protocolVersion != -1 ) { if( protocolVersion == SnmpConstants.SNMPV1 || protocolVersion == SnmpConstants.SNMPV2 || protocolVersion == SnmpConstants.SNMPV3 ) { // do something } else { Console.WriteLine("Invalid SNMP protocol version."); } } else { Console.WriteLine("Invalid SNMP packet."); }

SnmpPacket ( ) : System

Constructor. Sets SNMP version to SNMPV1.

SnmpPacket ( SnmpVersion protocolVersion ) : System

Constructor. Initialize SNMP version as supplied.

decode ( byte buffer, int length ) : int

Decode SNMP packet header. This class decodes the initial sequence and SNMP protocol version number.

encode ( ) : byte[]

Place holder for derived class implementations.

encode ( MutableByte buffer ) : void

Wrap BER encoded SNMP information contained in the parameter MutableByte class. Information in the parameter is prepended by the SNMP version field and wrapped in a sequence header. Derived classes call this method to finalize SNMP packet encoding.

Method Details

GetProtocolVersion() public static method

Get SNMP protocol version from the packet. This routine does not verify if version number is valid. Caller should verify that returned value represents a valid SNMP protocol version number. int protocolVersion = Packet.GetProtocolVersion(inPacket, inLength); if( protocolVersion != -1 ) { if( protocolVersion == SnmpConstants.SNMPV1 || protocolVersion == SnmpConstants.SNMPV2 || protocolVersion == SnmpConstants.SNMPV3 ) { // do something } else { Console.WriteLine("Invalid SNMP protocol version."); } } else { Console.WriteLine("Invalid SNMP packet."); }
Thrown when invalid sequence type is found at the start of the SNMP packet being decoded
public static GetProtocolVersion ( byte buffer, int bufferLength ) : int
buffer byte BER encoded SNMP packet
bufferLength int Length of the BER encoded packet
return int

SnmpPacket() public method

Constructor. Sets SNMP version to SNMPV1.
public SnmpPacket ( ) : System
return System

SnmpPacket() public method

Constructor. Initialize SNMP version as supplied.
public SnmpPacket ( SnmpVersion protocolVersion ) : System
protocolVersion SnmpVersion Protocol version. Acceptable values are SnmpConstants.SNMPV1, /// SnmpConstants.SNMPV2 and SnmpConstants.SNMPV3
return System

decode() public method

Decode SNMP packet header. This class decodes the initial sequence and SNMP protocol version number.
Thrown when invalid sequence type is found at the start of the SNMP packet being decoded
public decode ( byte buffer, int length ) : int
buffer byte BER encoded SNMP packet
length int Packet length
return int

encode() public abstract method

Place holder for derived class implementations.
public abstract encode ( ) : byte[]
return byte[]

encode() public method

Wrap BER encoded SNMP information contained in the parameter MutableByte class. Information in the parameter is prepended by the SNMP version field and wrapped in a sequence header. Derived classes call this method to finalize SNMP packet encoding.
public encode ( MutableByte buffer ) : void
buffer MutableByte Buffer containing BER encoded SNMP information
return void

Property Details

_protocolVersion protected_oe property

SNMP protocol version
protected Integer32 _protocolVersion
return Integer32