<< Back to man.lupaworld.com

18.  SnmpMessage Class

The SnmpMessage class allows Abstract Syntax Notation One ( ASN.1) / Basic Encoding Rules (BER) encoding and decoding of SNMP++ objects into SNMP messages ready for transport on the wire. This class allows for easy serialization of Pdu objects which then can be used in any manner desired. Most users of SNMP++ should not have to use this class since the Snmp class takes care of this task including handling timeout and retries. There are cases however where a programmer would like to encode messages. For example, many proxy systems utilize there own transport layer. The SnmpMessage class supports a variety of member functions as shown in the table below.

 

 

 

 

SnmpMessage Class Member Functions

Description

Constructors

 

     SnmpMessage::SnmpMessage( void);

Construct an empty SnmpMessage object.

Member Functions

 

     int load( Pdu pdu, OctetStr community,

                     snmp_version version);

Load a SnmpMessage object with a Pdu, community name and version. Version can be SNMP version 1 or version 2. Returned is the error status.

     int load( unsigned char * data, unsigned long len);

Load a SnmpMessage object with a raw data stream. This is useful where a datagram has beeen received across the wire and by loading it into a SnmpMessage object it can then be decoded.

     int unload( Pdu &pdu, OctetStr &community,

                       snmp_version &version);

Unload an already loaded SnmpMessage object. This allows getting a Pdu, community and version.

     unsigned char * data();

Access the raw ASN.1/BER serialized data buffer. The length of this buffer can be accessed via the ::len() memeber function.

     unsigned long len()

Return the length of the raw data buffer.

      int valid();

Determine if the SnmpMessage object is valid.