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.
CopyC#
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.");
}

Namespace: SnmpSharpNet
Assembly: SnmpSharpNet (in SnmpSharpNet.dll) Version: 0.9.1.0 (0.9.1)

Syntax

C#
public static int GetProtocolVersion(
	byte[] buffer,
	int bufferLength
)
Visual Basic
Public Shared Function GetProtocolVersion ( _
	buffer As Byte(), _
	bufferLength As Integer _
) As Integer
Visual C++
public:
static int GetProtocolVersion(
	array<unsigned char>^ buffer, 
	int bufferLength
)

Parameters

buffer
Type: array<System..::..Byte>[]()[][]
BER encoded SNMP packet
bufferLength
Type: System..::..Int32
Length of the BER encoded packet

Return Value

Returns SNMP protocol version, if packet is not valid returned value is -1.

Exceptions

ExceptionCondition
SnmpSharpNet..::..SnmpDecodingExceptionThrown when invalid sequence type is found at the start of the SNMP packet being decoded

See Also