SNMP version 3 packet implementation class.

Namespace:  SnmpSharpNet
Assembly:  SnmpSharpNet (in SnmpSharpNet.dll) Version: 0.5.0.0 (0.5.0.0)

Syntax

         
 C#  Visual Basic  Visual C++ 
public class SnmpV3Packet : SnmpPacket
Public Class SnmpV3Packet _
	Inherits SnmpPacket
public ref class SnmpV3Packet : public SnmpPacket

Members

            
 All Members  Constructors   Properties   Methods  
 Public

 Protected
 Instance

 Static 
 Declared

 Inherited
 XNA Framework Only 

 .NET Compact Framework Only 

 MemberDescription
SnmpV3Packet()()()
Standard constructor.
SnmpV3Packet(ScopedPdu)
Standard constructor. Sets internal ScopedPdu class to the argument supplied instance of the class. This is a good cheat that will allow you direct access to the internal ScopedPdu class since it is not cloned by assigned to the internal variable.
authNoPriv(array<Byte>[]()[], array<Byte>[]()[], AuthenticationDigests)
Set class security to enabled authentication and no privacy. To perform authentication, authentication password needs to be supplied and authentication protocol to be used to perform authentication. This method does not initialize the packet user name. Use SNMPV3Packet.SecurityName method to set the security name (also called user name) for this request.
authPriv(array<Byte>[]()[], array<Byte>[]()[], AuthenticationDigests, array<Byte>[]()[], PrivacyProtocols)
Set packet security to authentication enabled and privacy protection enabled (SNMP v3 mode authPriv)
BuildInformResponse()()()
Build SNMP RESPONSE packet for the received INFORM packet.
BuildInformResponse(SnmpV3Packet)
Build SNMP RESPONSE packet for the INFORM packet class.
decode(array<Byte>[]()[], Int32)
Decode SNMP version 3 packet. This method will perform authentication check and decode privacy protected ScopedPdu. This method will not check for the timeliness of the packet, correct engine boot value or engine id because it does not have a reference to the engine time prior to this call.
(Overrides SnmpPacket..::.decode(array<Byte>[]()[], Int32).)
DiscoveryRequest()()()
Build an SNMP version 3 packet suitable for use in discovery process.
DiscoveryResponse(Int32, Int32, OctetString, Int32, Int32, Int32)
Build SNMP discovery response packet.
encode()()()
Encode SNMP version 3 packet
(Overrides SnmpPacket..::.encode()()().)
encode(MutableByte)
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.
(Inherited from SnmpPacket.)
Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
GetHashCode()()()
Serves as a hash function for a particular type.
(Inherited from Object.)
GetType()()()
Gets the Type of the current instance.
(Inherited from Object.)
GetUSM(array<Byte>[]()[], Int32)
"Look-ahead" decode of SNMP packet header including USM information
IsDiscoveryPacket
Packet is a discovery request
IsNotification
Packet is a notification
(Inherited from SnmpPacket.)
IsReport
Packet is a report
(Inherited from SnmpPacket.)
IsReportable
Get or set SNMP version 3 packet Reportable flag in the message flags section. By default this value is set to true.
IsRequest
Packet is a request
(Inherited from SnmpPacket.)
IsResponse
Packet is a response
(Inherited from SnmpPacket.)
MaxMessageSize
Get maximum message size to be sent to the agent in the request.
MessageId
Get SNMP version 3 message id object.
MsgFlags
Message flags interface. Allows you to directly set or clear SNMP version 3 header flags field. Available flags are MsgFlags.Authentication, MsgFlags.Privacy and MsgFlags.Reportable. Please be careful how you use this property. After setting authentication or privacy parameters to true, you will need to update UserSecurityModel authentication and privacy types to the correct values otherwise encoding/decoding will not work.
NoAuthNoPriv()()()
Set class security to no authentication and no privacy. User name is set to "initial" (suitable for SNMP version 3 discovery process). Change username before using if discovery is not being performed.
NoAuthNoPriv(array<Byte>[]()[])
Set class security to no authentication and no privacy with the specific user name.
Pdu
Override base class implementation. Returns class ScopedPdu cast as Pdu
(Overrides SnmpPacket..::.Pdu.)
ScopedPdu
Access packet ScopedPdu class.
SetEngineId(array<Byte>[]()[])
Set authoritative engine id
SetEngineTime(Int32, Int32)
Set engine time and boots values
ToString()()()
Returns a String that represents the current Object.
(Inherited from Object.)
USM
Get UserSecurityModel class reference.
Version
SNMP Protocol version
(Inherited from SnmpPacket.)

Remarks

Available packet classes are: This class is provided to simplify encoding and decoding of packets and to provide consistent interface for users who wish to handle transport part of protocol on their own without using the UdpTarget class. SnmpPacket and derived classes have been developed to implement SNMP version 1, 2 and 3 packet support. For SNMP version 1 and 2 packet, SnmpV1Packet and SnmpV2Packet classes provide sufficient support for encoding and decoding data to/from BER buffers to satisfy requirements of most applications. SNMP version 3 on the other hand requires a lot more information to be passed to the encoder method and returned by the decode method. While using SnmpV3Packet class for full packet handling is possible, transport specific class UdpTarget uses SecureAgentParameters class to store protocol version 3 specific information that carries over from request to request when used on the same SNMP agent and therefore simplifies both initial definition of agents configuration (mostly security) as well as removes the need for repeated initialization of the packet class for subsequent requests. If you decide not to use transport helper class(es) like UdpTarget, BER encoding and decoding and packets is easily done with SnmpPacket derived classes. Example, SNMP version 1 packet encoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.SnmpCommunity.Set("public");
packetv1.Pdu.Set(mypdu);
byte[] berpacket = packetv1.encode();
Example, SNMP version 3 noAuthNoPriv encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.noAuthNoPriv("myusername");
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authNoPriv using MD5 authentication packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authNoPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authPriv using MD5 authentication and DES encryption packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5,
       "myPrivacyPassword", PrivacyProtocols.DES);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
When decoding SNMP version 3 packets, SnmpV3Packet class needs to be initialized with the same values security values as a request does. This includes, authoritative engine id, engine boots and engine time, if authentication is used, authentication digest and password and for encryption, password and privacy protocol used. Without these parameters packet class will not be able to verify the incoming packet and responses will be discarded even if they are valid.

Inheritance Hierarchy

System..::.Object
  SnmpSharpNet..::.SnmpPacket
    SnmpSharpNet..::.SnmpV3Packet

See Also