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.5.0.0 (0.5.0.0)

Syntax

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

Parameters

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

Return Value

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

See Also