SNMPpp  v0.0.3-20-7eeb228
Classes, methods, and functions to use net-snmp from C++
SNMPpp::OID Class Reference

Wrapper for net-snmp's OID arrays. More...

#include <OID.hpp>

Collaboration diagram for SNMPpp::OID:

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 OIDclear (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 const struct module * getModule (const bool exact=false) const
 Get the net-snmp module pointer for this OID. More...
 
virtual const 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 OIDoperator+= (const oid o)
 Append a single numeric value to the current OID. More...
 
virtual OIDoperator+= (const std::string &s)
 Append one or more values to the current OID. More...
 
virtual OIDoperator= (const std::string &s)
 Alias for SNMPpp::OID::set(). More...
 
virtual OIDoperator= (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 OIDset (const OID &oid)
 Reuse an OID object by setting the numeric values as indicated. More...
 
virtual OIDset (const char *const s)
 Reuse an OID object by setting the numeric values as indicated. More...
 
virtual OIDset (const std::string &s)
 Reuse an OID object by setting the numeric values as indicated. More...
 
virtual OIDset (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
 

Detailed Description

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.

Member Enumeration Documentation

◆ ECommon

An enum to represent some of the common OIDs applications may need.

Enumerator
kInvalid 

n/a

kEmpty 

n/a

kInternet 

.1.3.6.1

kPrivateEnterprise 

.1.3.6.1.4

kSysUpTime 

.1.3.6.1.2.1.1.3.0

kTrap 

.1.3.6.1.6.3.1.1.4.1.0

◆ ENameLookup

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 

Constructor & Destructor Documentation

◆ ~OID()

SNMPpp::OID::~OID ( void  )
virtual

Destructor.

Here is the call graph for this function:

◆ OID() [1/7]

SNMPpp::OID::OID ( void  )

Empty OID, does not have any value.

For example:

OID oid1;

◆ OID() [2/7]

SNMPpp::OID::OID ( const OID oid)

Copy an OID from an existing object.

◆ OID() [3/7]

SNMPpp::OID::OID ( const char *const  s)

Initialize using a text string with the familiar numeric value.

For example:

OID oid1( ".1.3.6.1.4" );

◆ OID() [4/7]

SNMPpp::OID::OID ( const std::string &  s)

◆ OID() [5/7]

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:

OID oid1( SNMPpp::OID::kInternet ); // .1.3.6

◆ OID() [6/7]

SNMPpp::OID::OID ( const oid *  o,
const size_t  len 
)

Construct an OID using a net-snmp oid array.

◆ OID() [7/7]

SNMPpp::OID::OID ( const netsnmp_variable_list *  vl)
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.

Member Function Documentation

◆ clear()

SNMPpp::OID & SNMPpp::OID::clear ( void  )
virtual

Clear the OID value in the object (clears the vector).

Here is the caller graph for this function:

◆ empty()

virtual bool SNMPpp::OID::empty ( void  ) const
inlinevirtual

Return TRUE if the OID object is completely empty.

Here is the caller graph for this function:

◆ getModule()

const struct module * SNMPpp::OID::getModule ( const bool  exact = false) const
virtual

Get the net-snmp module pointer for this OID.

Parameters
[in]exactsee SNMPpp::OID::getTree() for details.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTree()

const struct tree * SNMPpp::OID::getTree ( const bool  exact = false) const
virtual

Get the net-snmp tree pointer for this OID.

Parameters
[in]exactWhen 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isChildOf()

bool SNMPpp::OID::isChildOf ( const SNMPpp::OID rhs) const
virtual

Similar to SNMPpp::OID::isImmediateChildOf().

But this includes grandchildren, etc. For example:

OID oid( ".1.3.6.4.1" );
...
if ( oid.isChildOf( ".1.3.6" ) // == TRUE
See also
SNMPpp::OID::isImmediateChildOf()
SNMPpp::OID::isImmediateParentOf()
SNMPpp::OID::isParentOf()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isImmediateChildOf()

bool SNMPpp::OID::isImmediateChildOf ( const SNMPpp::OID rhs) const
virtual

Similar to SNMPpp::OID::isChildOf().

The child<->parent relationship must be exact. Grandparents and grandchildren will return FALSE. For example:

OID oid( ".1.3.6.4.1" );
...
if ( oid.isImmediateChildOf( "1.3.6" ) // == FALSE
...
if ( oid.isImmediateChildOf( "1.3.6.4" ) // == TRUE
See also
SNMPpp::OID::isImmediateParentOf()
SNMPpp::OID::isChildOf()
SNMPpp::OID::isParentOf()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isImmediateParentOf()

bool SNMPpp::OID::isImmediateParentOf ( const SNMPpp::OID rhs) const
virtual

Similar to SNMPpp::OID::isParentOf().

The child<->parent relationship must be exact. Grandparents and grandchildren will return FALSE. For example:

OID oid( ".1.3.6" );
...
if ( oid.isImmediateParentOf( "1.3.6.4.1" ) // == FALSE
...
if ( oid.isImmediateParentOf( "1.3.6.4" ) // == TRUE
See also
SNMPpp::OID::isImmediateChildOf()
SNMPpp::OID::isChildOf()
SNMPpp::OID::isParentOf()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isParentOf()

bool SNMPpp::OID::isParentOf ( const SNMPpp::OID rhs) const
virtual

Similar to SNMPpp::OID::isImmediateParentOf().

But this includes grandparents, etc. For example:

OID oid( ".1.3.6" );
if ( oid.isParentOf( "1.3.6.4.1" ) // == TRUE
See also
SNMPpp::OID::isImmediateChildOf()
SNMPpp::OID::isImmediateParentOf()
SNMPpp::OID::isChildOf()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ len()

virtual size_t SNMPpp::OID::len ( void  ) const
inlinevirtual

Alias for operator size_t().

◆ mibModuleFile()

std::string SNMPpp::OID::mibModuleFile ( const bool  exact = false) const
virtual

Get information on the MIB filename.

For example:

SNMPpp::OID o( ".1.3.6.1" );
std::cout << o.mibModuleFile() << std::endl;

...might display /usr/share/mibs/ietf/SNMPv2-SMI on a linux system if the MIBs have been installed.

Parameters
[in]exactsee SNMPpp::OID::getTree() for details.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mibModuleName()

std::string SNMPpp::OID::mibModuleName ( const bool  exact = false) const
virtual

Get information on the MIB file which describes this OID.

For example:

SNMPpp::OID o( ".1.3.6.1" );
std::cout << o.mibModuleName() << std::endl;

...might display the name SNMPv2-SMI if the MIBs are installed on the system.

Parameters
[in]exactsee SNMPpp::OID::getTree() for details.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nameFromMib()

std::string SNMPpp::OID::nameFromMib ( const SNMPpp::OID::ENameLookup  lookup = SNMPpp::OID::kFull) const
virtual

Get the OID's name from MIB files (if possible).

See also
SNMPpp::OID::ENameLookup
Note
If net-snmp hasn't yet been initialized, you must call 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"
Exceptions
std::invalid_argumentif the lookup type is not one of the 4 values described above.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

virtual SNMPpp::OID::operator bool ( void  ) const
inlinevirtual

Return TRUE if the OID object is not empty.

Here is the call graph for this function:

◆ operator const oid *()

SNMPpp::OID::operator const oid * ( void  ) const
virtual

Convert the const OID to an array of unsigned longs (aka oid *) the way net-snmp needs for most API calls.

Returns
NULL if the OID is empty.
The address of the first value in the vector.
Here is the call graph for this function:

◆ operator const unsigned char *()

virtual SNMPpp::OID::operator const unsigned char * ( void  ) const
inlinevirtual

Alias to uchar* for some of the original net-snmp functions.

◆ operator const void *()

virtual SNMPpp::OID::operator const void * ( void  ) const
inlinevirtual

Alias to oid* for some of the original net-snmp functions.

Here is the call graph for this function:

◆ operator oid *()

SNMPpp::OID::operator oid * ( void  )
virtual

Convert the OID to an array of unsigned longs (aka oid *) the way net-snmp needs for most API calls.

Returns
NULL if the OID is empty.
The address of the first value in the vector.
Here is the call graph for this function:

◆ operator size_t()

virtual SNMPpp::OID::operator size_t ( void  ) const
inlinevirtual

Return the number of values in the OID vector.

Note
Remember this is the number of unsigned long, while some of the net-snmp API calls expect the number of bytes, in which case you must multiply by sizeof(ulong).

◆ operator std::string()

SNMPpp::OID::operator std::string ( void  ) const
virtual

Convert the OID to the familiar numeric format, such as .1.3.6.1.4.x.x.x.

◆ operator!=()

virtual bool SNMPpp::OID::operator!= ( const SNMPpp::OID rhs) const
inlinevirtual

Comparison operator for OIDs.

Here is the call graph for this function:

◆ operator+() [1/2]

SNMPpp::OID SNMPpp::OID::operator+ ( const oid  o) const
virtual

Append a single numeric value and return a new OID.

For example:

OID oid1( ".1.3.6" );
OID oid2 = oid1 + 1; // == .1.3.6.1
Here is the caller graph for this function:

◆ operator+() [2/2]

SNMPpp::OID SNMPpp::OID::operator+ ( const std::string &  s) const
virtual

Append one or more values and return a new OID.

For example:

OID oid1( ".1.3.6" );
OID oid2 = oid1 + ".1.4"; // == .1.3.6.1.4

◆ operator+=() [1/2]

SNMPpp::OID & SNMPpp::OID::operator+= ( const oid  o)
virtual

Append a single numeric value to the current OID.

For example:

OID oid1( ".1.3.6" );
oid1 += 1; // == .1.3.6.1
Here is the caller graph for this function:

◆ operator+=() [2/2]

SNMPpp::OID & SNMPpp::OID::operator+= ( const std::string &  s)
virtual

Append one or more values to the current OID.

For example:

OID oid1( ".1.3.6" );
oid1 += ".1.4"; // == .1.3.6.1.4
Here is the call graph for this function:

◆ operator<()

virtual bool SNMPpp::OID::operator< ( const SNMPpp::OID rhs) const
inlinevirtual

Comparison operator for OIDs.

◆ operator<=()

virtual bool SNMPpp::OID::operator<= ( const SNMPpp::OID rhs) const
inlinevirtual

Comparison operator for OIDs.

◆ operator=() [1/2]

virtual OID& SNMPpp::OID::operator= ( const std::string &  s)
inlinevirtual

Alias for SNMPpp::OID::set().

◆ operator=() [2/2]

virtual OID& SNMPpp::OID::operator= ( const char *const  s)
inlinevirtual

Alias for SNMPpp::OID::set().

Here is the call graph for this function:

◆ operator==()

virtual bool SNMPpp::OID::operator== ( const SNMPpp::OID rhs) const
inlinevirtual

Comparison operator for OIDs.

◆ operator>()

virtual bool SNMPpp::OID::operator> ( const SNMPpp::OID rhs) const
inlinevirtual

Comparison operator for OIDs.

◆ operator>=()

virtual bool SNMPpp::OID::operator>= ( const SNMPpp::OID rhs) const
inlinevirtual

Comparison operator for OIDs.

◆ operator[]()

oid SNMPpp::OID::operator[] ( const size_t  idx) const
virtual

Return the value at the specified index into the OID vector.

For example:

OID o( ".1.3.6" );
if ( o[0] == 1 ) ... // TRUE
if ( o[2] != 6 ) ... // FALSE
Exceptions
std::invalid_argumentif the index is larger than the OID.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parent()

SNMPpp::OID SNMPpp::OID::parent ( const size_t  level = 1) const
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.

Returns
If the level is greater than or equal to the number of values in the OID, then an empty OID is returned to the caller.
If the level is smaller than the number of values in the OID, then the vector is truncated by the appropriate amount and a new OID is returned to the caller.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set() [1/4]

SNMPpp::OID & SNMPpp::OID::set ( const OID oid)
virtual

Reuse an OID object by setting the numeric values as indicated.

Here is the call graph for this function:

◆ set() [2/4]

SNMPpp::OID & SNMPpp::OID::set ( const char *const  s)
virtual

Reuse an OID object by setting the numeric values as indicated.

Here is the call graph for this function:

◆ set() [3/4]

SNMPpp::OID & SNMPpp::OID::set ( const std::string &  s)
virtual

Reuse an OID object by setting the numeric values as indicated.

Here is the call graph for this function:

◆ set() [4/4]

SNMPpp::OID & SNMPpp::OID::set ( const SNMPpp::OID::ECommon location)
virtual

Reuse an OID object by setting the numeric values as indicated.

Here is the call graph for this function:

◆ size()

virtual size_t SNMPpp::OID::size ( void  ) const
inlinevirtual

Alias for operator size_t().

Here is the caller graph for this function:

◆ to_str()

virtual std::string SNMPpp::OID::to_str ( void  ) const
inlinevirtual

Alias to operator std::string() for convenience.

Sometimes it looks cleaner to call to_str() than the wordier operator...().

Here is the caller graph for this function:

Member Data Documentation

◆ v

std::vector< oid > SNMPpp::OID::v
protected

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