SNMPpp  v0.0.3-20-7eeb228
Classes, methods, and functions to use net-snmp from C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SNMPpp::PDU Class Reference

Wrapper for net-snmp's PDU structures. More...

#include <PDU.hpp>

Collaboration diagram for SNMPpp::PDU:

Public Types

enum  EType {
  kInvalid = 0,
  kUnknown = 0,
  kGet = SNMP_MSG_GET,
  kGetNext = SNMP_MSG_GETNEXT,
  kResponse = SNMP_MSG_RESPONSE,
  kSet = SNMP_MSG_SET,
  kGetBulk = SNMP_MSG_GETBULK,
  kInform = SNMP_MSG_INFORM,
  kTrap2 = SNMP_MSG_TRAP2,
  kReport = SNMP_MSG_REPORT
}
 When creating a new PDU, the type of PDU (how it will be used) needs to be declared so it can be created correctly. More...
 

Public Member Functions

 PDU (const EType t)
 Create a PDU of the given type. More...
 
 PDU (netsnmp_pdu *p)
 Inherit a PDU from net-snmp. It is valid for p to be NULL. More...
 
virtual ~PDU (void)
 Destructor. More...
 
virtual PDUaddNullVar (const SNMPpp::OID &o)
 Add an OID as ASN_NULL to the variable list. More...
 
virtual PDUaddNullVars (const SNMPpp::SetOID &s)
 Add numerous OIDs to the variable list. More...
 
virtual PDUaddNullVars (const SNMPpp::VecOID &v)
 Add numerous OIDs to the variable list. More...
 
virtual void clear (void)
 If a net-snmp function has been called which we know has already freed the PDU pointer, call clear() to ensure this C++ wrapper object doesn't keep the pointer to the old memory location. More...
 
virtual PDU clone (void) const
 Make a copy of this PDU using snmp_clone_pdu(). More...
 
virtual bool contains (const SNMPpp::OID &o) const
 Return TRUE if the variable list contains the given OID. More...
 
virtual bool empty (void) const
 Returns TRUE if the PDU or the varlist is NULL. More...
 
virtual SNMPpp::OID firstOID (void) const
 Return the first OID object in the variable list. More...
 
virtual void free (void)
 Free up the underlying net-snmp structure using snmp_free_pdu(). More...
 
virtual EType getType (void) const
 Get the PDU type. More...
 
virtual operator netsnmp_pdu * (void)
 Convert the PDU to a net-snmp pointer for passing into the net-snmp API. More...
 
virtual operator netsnmp_variable_list * (void)
 Get access to the varlist for this PDU. This will throw if the PDU is empty. More...
 
virtual netsnmp_variable_list * operator[] (const size_t idx)
 Get access to a specific varlist for this PDU. More...
 
virtual PDUsetVarlist (Varlist &vl)
 Free the existing variable list and use this one instead. More...
 
virtual PDUsetVarlist (netsnmp_variable_list *vl)
 Free the existing variable list and use this one instead. More...
 
virtual size_t size (void) const
 Return the size of the variable list or zero if the PDU is empty. More...
 
virtual const SNMPpp::Varlist varlist (void) const
 Get access to the varlist for this PDU. This will throw if the PDU is empty. More...
 
virtual SNMPpp::Varlist varlist (void)
 Get access to the varlist for this PDU. This will throw if the PDU is empty. More...
 

Protected Attributes

netsnmp_pdu * pdu
 
EType type
 

Detailed Description

Wrapper for net-snmp's PDU structures.

These objects are extremely small (just a pointer) and can easily be created on the stack or as a member of another class.

Many other parts of SNMPpp can accept PDU objects by reference, and PDU includes the necessary operators so they can be used wherever net-snmp netsnmp_pdu * pointers are typically used.

Note
Request PDUs are automatically freed by net-snmp when requests are handled, but responses typically need to be manually freed by the caller to prevent memory leaks.

This C++ class doesn't solve this problem. In the C++ PDU destructor don't expect the underlying pdu to be freed. You still need to ensure response PDUs are freed, either by calling SNMPpp::PDU::free() or net-snmp's snmp_free_pdu( pdu ).

Member Enumeration Documentation

When creating a new PDU, the type of PDU (how it will be used) needs to be declared so it can be created correctly.

Enumerator
kInvalid 
kUnknown 
kGet 

SNMPv1+ get the specified OIDs.

kGetNext 

SNMPv1+ get the OID that comes after the one specified.

kResponse 

SNMPv1+ ???

kSet 

SNMPv1+ set the specified OID.

kGetBulk 

SNMPv2+ get many OIDs at once.

kInform 

SNMPv2+ traps with replies.

kTrap2 

SNMPv2+ traps.

kReport 

SNMPv2+ ???

Constructor & Destructor Documentation

SNMPpp::PDU::~PDU ( void  )
virtual

Destructor.

SNMPpp::PDU::PDU ( const EType  t)

Create a PDU of the given type.

Exceptions
std::runtime_errorif snmp_pdu_create() cannot allocate the PDU.
SNMPpp::PDU::PDU ( netsnmp_pdu *  p)

Inherit a PDU from net-snmp. It is valid for p to be NULL.

Member Function Documentation

SNMPpp::PDU & SNMPpp::PDU::addNullVar ( const SNMPpp::OID o)
virtual

Add an OID as ASN_NULL to the variable list.

Exceptions
std::logic_errorif the PDU is NULL.

Here is the call graph for this function:

Here is the caller graph for this function:

SNMPpp::PDU & SNMPpp::PDU::addNullVars ( const SNMPpp::SetOID s)
virtual

Add numerous OIDs to the variable list.

See Also
SNMPpp::PDU::addNullVar( const SNMPpp::OID &o )
SNMPpp::PDU::addNullVars( const SNMPpp::VecOID &v )
Exceptions
std::logic_errorif the PDU is NULL.

Here is the call graph for this function:

Here is the caller graph for this function:

SNMPpp::PDU & SNMPpp::PDU::addNullVars ( const SNMPpp::VecOID v)
virtual

Add numerous OIDs to the variable list.

See Also
SNMPpp::PDU::addNullVar( const SNMPpp::OID &o )
SNMPpp::PDU::addNullVars( const SNMPpp::SetOID &s )
Exceptions
std::logic_errorif the PDU is NULL.

Here is the call graph for this function:

void SNMPpp::PDU::clear ( void  )
virtual

If a net-snmp function has been called which we know has already freed the PDU pointer, call clear() to ensure this C++ wrapper object doesn't keep the pointer to the old memory location.

Note
Don't miss the difference between clear() and free(). clear() will leak memory if snmp_free_pdu() hasn't yet been called.
See Also
free()

Here is the caller graph for this function:

SNMPpp::PDU SNMPpp::PDU::clone ( void  ) const
virtual

Make a copy of this PDU using snmp_clone_pdu().

Both of the PDU objects will eventually need to be freed.

bool SNMPpp::PDU::contains ( const SNMPpp::OID o) const
virtual

Return TRUE if the variable list contains the given OID.

bool SNMPpp::PDU::empty ( void  ) const
virtual

Returns TRUE if the PDU or the varlist is NULL.

Here is the caller graph for this function:

SNMPpp::OID SNMPpp::PDU::firstOID ( void  ) const
virtual

Return the first OID object in the variable list.

See Also
SNMPpp::PDU::varlist() const for the exceptions this may throw.
void SNMPpp::PDU::free ( void  )
virtual

Free up the underlying net-snmp structure using snmp_free_pdu().

Here is the caller graph for this function:

virtual EType SNMPpp::PDU::getType ( void  ) const
inlinevirtual

Get the PDU type.

Here is the caller graph for this function:

virtual SNMPpp::PDU::operator netsnmp_pdu * ( void  )
inlinevirtual

Convert the PDU to a net-snmp pointer for passing into the net-snmp API.

SNMPpp::PDU::operator netsnmp_variable_list * ( void  )
virtual

Get access to the varlist for this PDU. This will throw if the PDU is empty.

Exceptions
std::logic_errorif the PDU is NULL.
netsnmp_variable_list * SNMPpp::PDU::operator[] ( const size_t  idx)
virtual

Get access to a specific varlist for this PDU.

Returns
Returns a NULL pointer if the index is larger than the number of items in the variable list.
SNMPpp::PDU & SNMPpp::PDU::setVarlist ( Varlist vl)
virtual

Free the existing variable list and use this one instead.

SNMPpp::PDU & SNMPpp::PDU::setVarlist ( netsnmp_variable_list *  vl)
virtual

Free the existing variable list and use this one instead.

Exceptions
std::logic_errorif the PDU is NULL.
size_t SNMPpp::PDU::size ( void  ) const
virtual

Return the size of the variable list or zero if the PDU is empty.

const SNMPpp::Varlist SNMPpp::PDU::varlist ( void  ) const
virtual

Get access to the varlist for this PDU. This will throw if the PDU is empty.

Exceptions
std::logic_errorif the PDU is NULL.
std::logic_errorif the PDU does not yet have a variable list.

Here is the caller graph for this function:

SNMPpp::Varlist SNMPpp::PDU::varlist ( void  )
virtual

Get access to the varlist for this PDU. This will throw if the PDU is empty.

Exceptions
std::logic_errorif the PDU is NULL.
std::logic_errorif the PDU does not yet have a variable list.

Member Data Documentation

netsnmp_pdu* SNMPpp::PDU::pdu
protected
EType SNMPpp::PDU::type
protected

The documentation for this class was generated from the following files: