Wrapper for net-snmp's OID arrays. More...
#include <OID.hpp>
Public Types | |
enum | ECommon { kInvalid = 0, kEmpty = 1, kInternet = 2, kPrivateEnterprise = 3, kSysUpTime = 4, kTrap = 5 } |
An enum to represent some of the common OIDs applications may need. More... | |
enum | ENameLookup { kUnknown = 0, kLeafOnly = 1, kPartial = 2, kInverted = 3, kFull = 4 } |
An enum to indicate what kind of name lookup is required when calling SNMPpp::OID::nameFromMib(). More... | |
Public Member Functions | |
OID (void) | |
Empty OID, does not have any value. More... | |
OID (const OID &oid) | |
Copy an OID from an existing object. More... | |
OID (const char *const s) | |
Initialize using a text string with the familiar numeric value. More... | |
OID (const std::string &s) | |
Similar to OID( const char * const s ). More... | |
OID (const SNMPpp::OID::ECommon &location) | |
Construct an OID from one of the few common locations described by SNMPpp::OID::ECommon. More... | |
OID (const oid *o, const size_t len) | |
Construct an OID using a net-snmp oid array. More... | |
OID (const netsnmp_variable_list *vl) | |
Construct an OID from the first OID in the given variable list pointer. More... | |
virtual | ~OID (void) |
Destructor. More... | |
virtual OID & | clear (void) |
Clear the OID value in the object (clears the vector). More... | |
virtual bool | empty (void) const |
Return TRUE if the OID object is completely empty. More... | |
virtual struct module * | getModule (const bool exact=false) const |
Get the net-snmp module pointer for this OID. More... | |
virtual struct tree * | getTree (const bool exact=false) const |
Get the net-snmp tree pointer for this OID. More... | |
virtual bool | isChildOf (const SNMPpp::OID &rhs) const |
Similar to SNMPpp::OID::isImmediateChildOf(). More... | |
virtual bool | isImmediateChildOf (const SNMPpp::OID &rhs) const |
Similar to SNMPpp::OID::isChildOf(). More... | |
virtual bool | isImmediateParentOf (const SNMPpp::OID &rhs) const |
Similar to SNMPpp::OID::isParentOf(). More... | |
virtual bool | isParentOf (const SNMPpp::OID &rhs) const |
Similar to SNMPpp::OID::isImmediateParentOf(). More... | |
virtual size_t | len (void) const |
Alias for operator size_t(). More... | |
virtual std::string | mibModuleFile (const bool exact=false) const |
Get information on the MIB filename. More... | |
virtual std::string | mibModuleName (const bool exact=false) const |
Get information on the MIB file which describes this OID. More... | |
virtual std::string | nameFromMib (const SNMPpp::OID::ENameLookup lookup=SNMPpp::OID::kFull) const |
Get the OID's name from MIB files (if possible). More... | |
virtual | operator bool (void) const |
Return TRUE if the OID object is not empty. More... | |
virtual | operator const oid * (void) const |
Convert the const OID to an array of unsigned longs (aka oid * ) the way net-snmp needs for most API calls. More... | |
virtual | operator const unsigned char * (void) const |
Alias to uchar* for some of the original net-snmp functions. More... | |
virtual | operator const void * (void) const |
Alias to oid* for some of the original net-snmp functions. More... | |
virtual | operator oid * (void) |
Convert the OID to an array of unsigned longs (aka oid * ) the way net-snmp needs for most API calls. More... | |
virtual | operator size_t (void) const |
Return the number of values in the OID vector. More... | |
virtual | operator std::string (void) const |
Convert the OID to the familiar numeric format, such as .1.3.6.1.4.x.x.x . More... | |
virtual OID | operator+ (const oid o) const |
Append a single numeric value and return a new OID. More... | |
virtual OID | operator+ (const std::string &s) const |
Append one or more values and return a new OID. More... | |
virtual OID & | operator+= (const oid o) |
Append a single numeric value to the current OID. More... | |
virtual OID & | operator+= (const std::string &s) |
Append one or more values to the current OID. More... | |
virtual OID & | operator= (const std::string &s) |
Alias for SNMPpp::OID::set(). More... | |
virtual OID & | operator= (const char *const s) |
Alias for SNMPpp::OID::set(). More... | |
virtual oid | operator[] (const size_t idx) const |
Return the value at the specified index into the OID vector. More... | |
virtual OID | parent (const size_t level=1) const |
Get the parent OID. More... | |
virtual OID & | set (const OID &oid) |
Reuse an OID object by setting the numeric values as indicated. More... | |
virtual OID & | set (const char *const s) |
Reuse an OID object by setting the numeric values as indicated. More... | |
virtual OID & | set (const std::string &s) |
Reuse an OID object by setting the numeric values as indicated. More... | |
virtual OID & | set (const SNMPpp::OID::ECommon &location) |
Reuse an OID object by setting the numeric values as indicated. More... | |
virtual size_t | size (void) const |
Alias for operator size_t(). More... | |
virtual std::string | to_str (void) const |
Alias to operator std::string() for convenience. More... | |
virtual bool | operator< (const SNMPpp::OID &rhs) const |
Comparison operator for OIDs. More... | |
virtual bool | operator<= (const SNMPpp::OID &rhs) const |
Comparison operator for OIDs. More... | |
virtual bool | operator> (const SNMPpp::OID &rhs) const |
Comparison operator for OIDs. More... | |
virtual bool | operator>= (const SNMPpp::OID &rhs) const |
Comparison operator for OIDs. More... | |
virtual bool | operator== (const SNMPpp::OID &rhs) const |
Comparison operator for OIDs. More... | |
virtual bool | operator!= (const SNMPpp::OID &rhs) const |
Comparison operator for OIDs. More... | |
Protected Attributes | |
std::vector< oid > | v |
Wrapper for net-snmp's OID arrays.
These objects are extremely small (just a std::vector) and can easily be created on the stack or as a member of another class.
Many other parts of SNMPpp can accept OID objects by reference, and OID includes the necessary operators so they can be used wherever net-snmp oid
arrays are typically used.
enum SNMPpp::OID::ECommon |
An enum to indicate what kind of name lookup is required when calling SNMPpp::OID::nameFromMib().
Value | Meaning | Example |
---|---|---|
kLeafOnly | Only the very last name is returned. | .1.3.6.1 -> "internet" |
kPartial | Start of OID combined with the last name. | .1.3.6.1 -> ".1.3.6.internet" |
kInverted | The opposite of kPartial. | .1.3.6.1 -> ".iso.org.dod.1" |
kFull | All names are looked up. | .1.3.6.1 -> ".iso.org.dod.internet" |
Enumerator | |
---|---|
kUnknown | |
kLeafOnly | |
kPartial | |
kInverted | |
kFull |
|
virtual |
Destructor.
SNMPpp::OID::OID | ( | const char *const | s) |
Initialize using a text string with the familiar numeric value.
For example:
SNMPpp::OID::OID | ( | const std::string & | s) |
Similar to OID( const char * const s ).
SNMPpp::OID::OID | ( | const SNMPpp::OID::ECommon & | location) |
Construct an OID from one of the few common locations described by SNMPpp::OID::ECommon.
For example:
SNMPpp::OID::OID | ( | const oid * | o, |
const size_t | len | ||
) |
Construct an OID using a net-snmp oid
array.
|
explicit |
Construct an OID from the first OID in the given variable list pointer.
It is perfectly valid to use a NULL pointer.
This constructor is explicit
to prevent accidentally converting an entire SNMPpp::Varlist to a single OID. It requires and explicit netsnmp_variable_list * pointer.
|
virtual |
Clear the OID value in the object (clears the vector).
|
inlinevirtual |
|
virtual |
Get the net-snmp module pointer for this OID.
[in] | exact | see SNMPpp::OID::getTree() for details. |
|
virtual |
Get the net-snmp tree pointer for this OID.
[in] | exact | When set to true the tree returned must exactly match the OID. By default when called with false , if an exact match cannot be made, then a parent or grandparent of the OID may be returned instead. Usually, this means the required MIB is not installed or hasn't been loaded. For example, if the OID is .1.3.6.1.4.1.38322.1.1.1.3.0 but that specific device's custom MIB isn't available, then the closest grandparent likely to be returned is .1.3.6.1.4.1. If exact is set to true then in this scenario getTree() will return a NULL pointer rather than the pointer representing .1.3.6.1.4.1. |
|
virtual |
Similar to SNMPpp::OID::isImmediateChildOf().
But this includes grandchildren, etc. For example:
|
virtual |
Similar to SNMPpp::OID::isChildOf().
The child<->parent relationship must be exact. Grandparents and grandchildren will return FALSE
. For example:
|
virtual |
Similar to SNMPpp::OID::isParentOf().
The child<->parent relationship must be exact. Grandparents and grandchildren will return FALSE
. For example:
|
virtual |
Similar to SNMPpp::OID::isImmediateParentOf().
But this includes grandparents, etc. For example:
|
inlinevirtual |
Alias for operator size_t().
|
virtual |
Get information on the MIB filename.
For example:
...might display /usr/share/mibs/ietf/SNMPv2-SMI
on a linux system if the MIBs have been installed.
[in] | exact | see SNMPpp::OID::getTree() for details. |
|
virtual |
Get information on the MIB file which describes this OID.
For example:
...might display the name SNMPv2-SMI
if the MIBs are installed on the system.
[in] | exact | see SNMPpp::OID::getTree() for details. |
|
virtual |
Get the OID's name from MIB files (if possible).
netsnmp_init_mib()
prior to nameFromMib(). Otherwise the MIB files haven't been loaded, and the OID wont map to a known name.The different lookup types determine how the name is shown:
Value | Meaning | Example |
---|---|---|
kLeafOnly | Only the very last name is returned. | .1.3.6.1 -> "internet" |
kPartial | Start of OID combined with the last name. | .1.3.6.1 -> ".1.3.6.internet" |
kInverted | The opposite of kPartial. | .1.3.6.1 -> ".iso.org.dod.1" |
kFull | All names are looked up. | .1.3.6.1 -> ".iso.org.dod.internet" |
If the MIB files haven't been installed or initialized, the same example would look like this:
Value | Meaning | Example |
---|---|---|
kLeafOnly | Only the very last name is returned. | .1.3.6.1 -> "1" |
kPartial | Start of OID combined with the last name. | .1.3.6.1 -> ".1.3.6.1" |
kInverted | The opposite of kPartial. | .1.3.6.1 -> ".1.3.6.1" |
kFull | All names are looked up. | .1.3.6.1 -> ".1.3.6.1" |
std::invalid_argument | if the lookup type is not one of the 4 values described above. |
|
inlinevirtual |
|
virtual |
|
inlinevirtual |
Alias to uchar* for some of the original net-snmp functions.
|
inlinevirtual |
Alias to oid* for some of the original net-snmp functions.
|
virtual |
|
inlinevirtual |
Return the number of values in the OID vector.
unsigned long
, while some of the net-snmp API calls expect the number of bytes, in which case you must multiply by sizeof(ulong)
.
|
virtual |
Convert the OID to the familiar numeric format, such as .1.3.6.1.4.x.x.x
.
|
inlinevirtual |
Comparison operator for OIDs.
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
inlinevirtual |
Comparison operator for OIDs.
|
inlinevirtual |
Comparison operator for OIDs.
|
inlinevirtual |
|
inlinevirtual |
|
inlinevirtual |
Comparison operator for OIDs.
|
inlinevirtual |
Comparison operator for OIDs.
|
inlinevirtual |
Comparison operator for OIDs.
|
virtual |
|
virtual |
Get the parent OID.
For example, if we have this:
SNMPpp::OID oid1( ".1.2.3.4.5" ); SNMPpp::OID oid2 = oid1.parent(); SNMPpp::OID oid3 = oid1.parent(3);
...then the value of oid2 will be .1.2.3.4
, and the value of oid3 will be .1.2
.
|
virtual |
Reuse an OID object by setting the numeric values as indicated.
|
virtual |
Reuse an OID object by setting the numeric values as indicated.
|
virtual |
Reuse an OID object by setting the numeric values as indicated.
|
virtual |
Reuse an OID object by setting the numeric values as indicated.
|
inlinevirtual |
Alias for operator size_t().
|
inlinevirtual |
Alias to operator std::string() for convenience.
Sometimes it looks cleaner to call to_str() than the wordier operator...()
.
|
protected |