SNMPpp Wiki
Easy-to-use C++ library for various SNMP tasks
Status: Alpha
Brought to you by:
s_charette
net-snmp uses C arrays of unsigned longs as OIDs, and because there is no way to determine the length of arrays, a length must always accompany the array.
Note that net-snmp typedefs oid
, so the lowercase "oid" unfortunately makes for a bad variable name to use if you have all warnings enabled in your compiler.
The C++ OID class uses std::vector<unsigned long>
to store the components of arrays. This makes it relatively easy to use C++ OIDs when calling net-snmp C APIs.
Constructing, parsing, passing, and displaying OIDs has been made as easy as possible. For example:
SNMPpp::OID oid1( ".1.3.6.1.4.1.38322.1.1.1" ); SNMPpp::OID oid2( oid1 ); oid2 += "1.0"; std::cout << "OID is: " << oid2 << std::endl; if ( oid2.isChildOf( oid1 ) ) { ...etc...
With conversion operators, the net-snmp APIs can easily be passed C++ OIDs. For example:
SNMP::OID o( ".1.3.6.1.4.1.38322" ); snmp_add_null_var( pdu, o, o ); // where the 1st "o" results in a call to "operator const unsigned long *() const" // where the 2nd "o" results in a call to "operator size_t() const"