SNMPpp  v0.0.3-20-7eeb228
Classes, methods, and functions to use net-snmp from C++
PDU.hpp
Go to the documentation of this file.
1 // SNMPpp: https://sourceforge.net/p/snmppp/
2 // SNMPpp project uses the MIT license. See LICENSE for details.
3 // Copyright (C) 2013 Stephane Charette <stephanecharette@gmail.com>
4 
5 #pragma once
6 
7 #include <map>
8 #include <string>
9 #include <SNMPpp/net-snmppp.hpp>
10 #include <SNMPpp/OID.hpp>
11 #include <SNMPpp/Varlist.hpp>
12 
13 
14 namespace SNMPpp
15 {
34  class PDU
35  {
36  public:
37 
41  enum EType
42  {
43  kInvalid = 0 ,
44  kUnknown = 0 , // alias
45  // SNMPv1 and higher:
46  kGet = SNMP_MSG_GET ,
47  kGetNext = SNMP_MSG_GETNEXT ,
48  kResponse = SNMP_MSG_RESPONSE ,
49  kSet = SNMP_MSG_SET ,
50  // SNMPv2 and higher:
51  kGetBulk = SNMP_MSG_GETBULK ,
52  kInform = SNMP_MSG_INFORM ,
53  kTrap2 = SNMP_MSG_TRAP2 ,
54  kReport = SNMP_MSG_REPORT
55  };
56 
58  virtual ~PDU( void );
59 
61  PDU( const EType t );
62 
64  PDU( netsnmp_pdu *p );
65 
67  virtual void free( void );
68 
70  virtual EType getType( void ) const { return type; }
71 
80  virtual void clear( void );
81 
83  virtual bool empty( void ) const;
84 
88  virtual PDU clone( void ) const;
89 
91  virtual operator netsnmp_pdu*( void ) { return pdu; }
92 
94  virtual const SNMPpp::Varlist varlist( void ) const;
95 
97  virtual SNMPpp::Varlist varlist( void );
98 
100  virtual operator netsnmp_variable_list *( void );
101 
103  virtual netsnmp_variable_list * operator[]( const size_t idx );
104 
106  virtual PDU &setVarlist( Varlist &vl );
107 
109  virtual PDU &setVarlist( netsnmp_variable_list *vl );
110 
111  // for convenience, expose a few of the Varlist members we're likely to use in simple cases
112 
114  virtual size_t size( void ) const;
115 
117  virtual bool contains( const SNMPpp::OID &o ) const;
118 
120  virtual SNMPpp::OID firstOID( void ) const;
121 
123  virtual PDU &addNullVar( const SNMPpp::OID &o );
124 
129  virtual PDU &addNullVars( const SNMPpp::SetOID &s );
130 
135  virtual PDU &addNullVars( const SNMPpp::VecOID &v );
136 
137  protected:
138 
140  netsnmp_pdu *pdu; // beware -- this pointer *can* be null if a PDU hasn't been defined or if it has been clear()
141  };
142 };
143 
144 
148 std::ostream &operator<<( std::ostream &os, const SNMPpp::PDU &pdu );
EType type
Definition: PDU.hpp:139
All net-snmp includes needed by SNMPpp can be easily included by using net-snmppp.hpp.
virtual netsnmp_variable_list * operator[](const size_t idx)
Get access to a specific varlist for this PDU.
Definition: PDU.cpp:138
SNMPv1+ ???
Definition: PDU.hpp:48
Definition: Get.hpp:13
virtual size_t size(void) const
Return the size of the variable list or zero if the PDU is empty.
Definition: PDU.cpp:181
virtual PDU & addNullVars(const SNMPpp::SetOID &s)
Add numerous OIDs to the variable list.
Definition: PDU.cpp:237
Definition: PDU.hpp:44
virtual bool empty(void) const
Returns TRUE if the PDU or the varlist is NULL.
Definition: PDU.cpp:73
Definition: PDU.hpp:43
SNMPv2+ ???
Definition: PDU.hpp:54
virtual PDU & setVarlist(Varlist &vl)
Free the existing variable list and use this one instead.
Definition: PDU.cpp:156
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&#39;t keep the pointer to the old memory location.
Definition: PDU.cpp:64
SNMPv2+ traps with replies.
Definition: PDU.hpp:52
EType
When creating a new PDU, the type of PDU (how it will be used) needs to be declared so it can be crea...
Definition: PDU.hpp:41
Wrapper for net-snmp&#39;s PDU structures.
Definition: PDU.hpp:34
std::set< OID > SetOID
A std::set of OIDs.
Definition: OID.hpp:317
virtual bool contains(const SNMPpp::OID &o) const
Return TRUE if the variable list contains the given OID.
Definition: PDU.cpp:192
virtual ~PDU(void)
Destructor.
Definition: PDU.cpp:11
SNMPv2+ traps.
Definition: PDU.hpp:53
virtual PDU clone(void) const
Make a copy of this PDU using snmp_clone_pdu().
Definition: PDU.cpp:84
virtual SNMPpp::OID firstOID(void) const
Return the first OID object in the variable list.
Definition: PDU.cpp:204
virtual const SNMPpp::Varlist varlist(void) const
Get access to the varlist for this PDU. This will throw if the PDU is empty.
Definition: PDU.cpp:92
virtual void free(void)
Free up the underlying net-snmp structure using snmp_free_pdu().
Definition: PDU.cpp:52
SNMPv1+ get the OID that comes after the one specified.
Definition: PDU.hpp:47
virtual PDU & addNullVar(const SNMPpp::OID &o)
Add an OID as ASN_NULL to the variable list.
Definition: PDU.cpp:212
netsnmp_pdu * pdu
Definition: PDU.hpp:140
Wrapper for net-snmp&#39;s snmp_variable_list pointer.
Definition: Varlist.hpp:22
SNMPv2+ get many OIDs at once.
Definition: PDU.hpp:51
PDU(const EType t)
Create a PDU of the given type.
Definition: PDU.cpp:19
virtual EType getType(void) const
Get the PDU type.
Definition: PDU.hpp:70
SNMPv1+ set the specified OID.
Definition: PDU.hpp:49
Wrapper for net-snmp&#39;s OID arrays.
Definition: OID.hpp:26
std::ostream & operator<<(std::ostream &os, const SNMPpp::PDU &pdu)
Can be used to log or display some debugging information on the PDU, including all OIDs contained wit...
Definition: PDU.cpp:287
std::vector< OID > VecOID
A std::vector of OIDs.
Definition: OID.hpp:320
SNMPv1+ get the specified OIDs.
Definition: PDU.hpp:46