Wrapper for net-snmp's PDU structures. More...
#include <PDU.hpp>
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 PDU & | addNullVar (const SNMPpp::OID &o) |
Add an OID as ASN_NULL to the variable list. More... | |
virtual PDU & | addNullVars (const SNMPpp::SetOID &s) |
Add numerous OIDs to the variable list. More... | |
virtual PDU & | addNullVars (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 PDU & | setVarlist (Varlist &vl) |
Free the existing variable list and use this one instead. More... | |
virtual PDU & | setVarlist (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 |
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.
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 )
.
enum SNMPpp::PDU::EType |
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+ ??? |
|
virtual |
Destructor.
SNMPpp::PDU::PDU | ( | const EType | t) |
SNMPpp::PDU::PDU | ( | netsnmp_pdu * | p) |
Inherit a PDU from net-snmp. It is valid for p
to be NULL.
|
virtual |
|
virtual |
Add numerous OIDs to the variable list.
std::logic_error | if the PDU is NULL. |
|
virtual |
Add numerous OIDs to the variable list.
std::logic_error | if the PDU is NULL. |
|
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.
snmp_free_pdu()
hasn't yet been called.
|
virtual |
|
virtual |
Return TRUE
if the variable list contains the given OID.
|
virtual |
|
virtual |
Return the first OID object in the variable list.
|
virtual |
Free up the underlying net-snmp structure using snmp_free_pdu()
.
|
inlinevirtual |
|
inlinevirtual |
Convert the PDU to a net-snmp pointer for passing into the net-snmp API.
|
virtual |
|
virtual |
Get access to a specific varlist for this PDU.
|
virtual |
Free the existing variable list and use this one instead.
|
virtual |
Free the existing variable list and use this one instead.
std::logic_error | if the PDU is NULL. |
|
virtual |
Return the size of the variable list or zero if the PDU is empty.
|
virtual |
|
virtual |
|
protected |
|
protected |