Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

Snmp Class Reference

#include <uxsnmp.h>

Inheritance diagram for Snmp:

[legend]
Collaboration diagram for Snmp:
[legend]
List of all members.

Detailed Description

SNMP class defintion.

The Snmp class provides an object oriented approach to SNMP. The SNMP class is an encapsulation of SNMP sessions, gets, sets and get nexts. The class manages all SNMP resources and provides complete retry and timeout capability.

This class is thread save.

Note:
If you use the async methods to send requests you MUST call Snmp::eventListHolder->SNMPProcessPendingEvents() while waiting for the responses. This function triggers the resend of packets and calls your callback function if the response is received.

Call srand() before creating the first Snmp object.

Definition at line 106 of file uxsnmp.h.

Public Member Functions

virtual int cancel (const unsigned long rid)
 Cancel a pending request.

virtual int send_raw_data (unsigned char *send_buf, size_t send_len, UdpAddress &address, int fd=0)
 Send raw UDP data.

const IpAddressget_listen_address () const
Constructors and Destructor
 Snmp (int &status, const unsigned short port=0, const bool bind_ipv6=false)
 Construct a new SNMP session using the given UDP port.

 Snmp (int &status, const UdpAddress &addr)
 Construct a new SNMP session using the given UDP address.

 Snmp (int &status, const UdpAddress &addr_v4, const UdpAddress &addr_v6)
 Construct a new SNMP session using the given UDP addresses.

virtual ~Snmp ()
 Destructor.

Sending SNMP Pdus
virtual int get (Pdu &pdu, const SnmpTarget &target)
 Send a blocking SNMP-GET request.

virtual int get (Pdu &pdu, const SnmpTarget &target, const snmp_callback callback, const void *callback_data=0)
 Send a async SNMP-GET request.

virtual int get_next (Pdu &pdu, const SnmpTarget &target)
 Send a blocking SNMP-GETNEXT request.

virtual int get_next (Pdu &pdu, const SnmpTarget &target, const snmp_callback callback, const void *callback_data=0)
 Send a async SNMP-GETNEXT request.

virtual int set (Pdu &pdu, const SnmpTarget &target)
 Send a blocking SNMP-SET request.

virtual int set (Pdu &pdu, const SnmpTarget &target, const snmp_callback callback, const void *callback_data=0)
 Send a async SNMP-SET request.

virtual int get_bulk (Pdu &pdu, const SnmpTarget &target, const int non_repeaters, const int max_reps)
 Send a blocking SNMP-GETBULK request.

virtual int get_bulk (Pdu &pdu, const SnmpTarget &target, const int non_repeaters, const int max_reps, const snmp_callback callback, const void *callback_data=0)
 Send a async SNMP-GETBULK request.

virtual int trap (Pdu &pdu, const SnmpTarget &target)
 Send a SNMP-TRAP.

virtual int report (Pdu &pdu, const SnmpTarget &target)
 Send a SNMPv3-REPORT.

virtual int inform (Pdu &pdu, const SnmpTarget &target)
 Send a blocking INFORM-REQ.

virtual int inform (Pdu &pdu, const SnmpTarget &target, const snmp_callback callback, const void *callback_data=0)
 Send a async INFORM-REQ.

virtual int response (Pdu &pdu, const SnmpTarget &target)
 Send a RESPONSE.

virtual int broadcast_discovery (UdpAddressCollection &addresses, const int timeout_sec, const UdpAddress &addr, const snmp_version version, const OctetStr *community=0)
 Send a SNMP Broadcast message.

Trap and Inform handling
virtual int notify_register (const OidCollection &trapids, const TargetCollection &targets, const snmp_callback callback, const void *callback_data=0)
 Register to get traps and informs.

virtual int notify_register (const OidCollection &trapids, const TargetCollection &targets, const AddressCollection &listen_addresses, const snmp_callback callback, const void *callback_data=0)
 Register to get traps and informs.

virtual int notify_unregister ()
 Unregister to get traps and informs.

virtual int get_notify_filter (OidCollection &trapids, TargetCollection &targets)
 Get notify register info.

virtual int get_notify_filter (OidCollection &trapids, TargetCollection &targets, AddressCollection &listen_addresses)
 Get notify register info.

snmp_callback get_notify_callback ()
 Get a pointer to the callback function used for trap reception.

void * get_notify_callback_data ()
 Get a pointer to the data that is passed to the callback function.


Static Public Member Functions

const char * get_version ()
 Get the version of the snmp++ library.

const char * error_msg (const int c)
 Returns a human readable error string.

const char * error_msg (const Oid &v3Oid)
 Returns a human readable error string.

void socket_startup ()
 Initialize the Winsock library (WSAStartup).

void socket_cleanup ()
 Shut down the Winsock library (WSACleanup).


Public Attributes

EventListHoldereventListHolder

Static Public Attributes

SnmpSynchronized v3Lock

Protected Member Functions

long MyMakeReqId ()
 Generate a unique (for this Snmp obect) request id.

int snmp_engine (Pdu &pdu, long int non_reps, long int max_reps, const SnmpTarget &target, const snmp_callback cb, const void *cbd)
 gets, sets and get nexts go through here....

void map_action (unsigned short action, unsigned short &pdu_action)
void init (int &status, IpAddress *[2], const unsigned short port_v4, const unsigned short port_v6)
void check_notify_timestamp (Pdu &pdu)
 Set the notify timestamp of a trap pdu if the user did not set it.


Protected Attributes

SNMPHANDLE iv_snmp_session
SNMPHANDLE iv_snmp_session_ipv6
IpAddress listen_address
int iv_notify_fd
SNMPHANDLE pdu_handler
SNMPHANDLE pdu_handler_ipv6
int construct_status
int construct_status_ipv6
long current_rid
snmp_callback notifycallback
void * notifycallback_data

Friends

void v3CallBack (int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *v3cd)


Constructor & Destructor Documentation

Snmp::Snmp int &  status,
const unsigned short  port = 0,
const bool  bind_ipv6 = false
 

Construct a new SNMP session using the given UDP port.

Parameters:
status after creation of the session this parameter will hold the creation status.
port an UDP port to be used for the session
bind_ipv6 Set this to true if IPv6 should be used. The default is IPv4.

Snmp::Snmp int &  status,
const UdpAddress addr
 

Construct a new SNMP session using the given UDP address.

Thus, binds the session on a specific IPv4 or IPv6 address.

Parameters:
status after creation of the session this parameter will hold the creation status.
addr an UDP address to be used for the session

Snmp::Snmp int &  status,
const UdpAddress addr_v4,
const UdpAddress addr_v6
 

Construct a new SNMP session using the given UDP addresses.

Using this constructor will bind to both IPv4 and IPv6 ports.

Parameters:
status after creation of the session this parameter will hold the creation status.
addr_v4 an IPv4 UDP address to be used for the session
addr_v6 an IPv6 UDP address to be used for the session

virtual Snmp::~Snmp  )  [virtual]
 

Destructor.


Member Function Documentation

virtual int Snmp::broadcast_discovery UdpAddressCollection addresses,
const int  timeout_sec,
const UdpAddress addr,
const snmp_version  version,
const OctetStr community = 0
[virtual]
 

Send a SNMP Broadcast message.

This member function sends out a valid SNMP message to a broadcast address and waits for responses. The source addresses of the response messages are added to the collection.

The message is sent only once.

Note:
SNMP_BROADCAST has to be defined in config_snmp_pp.h.

There is no SNMP standard that defines "SNMP Broadcast discovery". SNMP agents are not forced to answer requests that are sent to a broadcast address.

Do not use this method while waiting for other responses, as these responses will be added to the collection and dropped by this method. Solution for this problem: Use a special Snmp object only for broadcasts.

Parameters:
addresses - The addresses of the agents, that answered.
timeout_sec - Timeout in seconds
addr - Broadcast address
version - SNMP version to use
community - Only needed for SNMPv1/v2c, defaults to "public"

virtual int Snmp::cancel const unsigned long  rid  )  [virtual]
 

Cancel a pending request.

Parameters:
rid - The request id to cancel
Returns:
SNMP_CLASS_SUCCES or SNMP_CLASS_INVALID_REQID on failure

void Snmp::check_notify_timestamp Pdu pdu  )  [protected]
 

Set the notify timestamp of a trap pdu if the user did not set it.

const char* Snmp::error_msg const Oid v3Oid  )  [static]
 

Returns a human readable error string.

If a report message is returned, then the contained Oid can be used to get a error string.

Parameters:
v3Oid - Oid of a SNMPv3 report Pdu
Returns:
Null terminated error string.

const char* Snmp::error_msg const int  c  )  [static]
 

Returns a human readable error string.

Parameters:
c - Error code returned by any method of this class
Returns:
Null terminated error string.

virtual int Snmp::get Pdu pdu,
const SnmpTarget target,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Send a async SNMP-GET request.

Parameters:
pdu - Pdu to send
target - Target for the get
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::get Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a blocking SNMP-GET request.

Parameters:
pdu - Pdu to send
target - Target for the get
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::get_bulk Pdu pdu,
const SnmpTarget target,
const int  non_repeaters,
const int  max_reps,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Send a async SNMP-GETBULK request.

Parameters:
pdu - Pdu to send
target - Target for the getbulk
non_repeaters - number of non repeaters
max_reps - maximum number of repetitions
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::get_bulk Pdu pdu,
const SnmpTarget target,
const int  non_repeaters,
const int  max_reps
[virtual]
 

Send a blocking SNMP-GETBULK request.

Parameters:
pdu - Pdu to send
target - Target for the getbulk
non_repeaters - number of non repeaters
max_reps - maximum number of repetitions
Returns:
SNMP_CLASS_SUCCES or a negative error code

const IpAddress& Snmp::get_listen_address  )  const [inline]
 

Definition at line 526 of file uxsnmp.h.

virtual int Snmp::get_next Pdu pdu,
const SnmpTarget target,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Send a async SNMP-GETNEXT request.

Parameters:
pdu - Pdu to send
target - Target for the getnext
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::get_next Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a blocking SNMP-GETNEXT request.

Parameters:
pdu - Pdu to send
target - Target for the getnext
Returns:
SNMP_CLASS_SUCCES or a negative error code

snmp_callback Snmp::get_notify_callback  )  [inline]
 

Get a pointer to the callback function used for trap reception.

Returns:
Pointer to the function set through notify_register()

Definition at line 499 of file uxsnmp.h.

References snmp_callback.

void* Snmp::get_notify_callback_data  )  [inline]
 

Get a pointer to the data that is passed to the callback function.

Returns:
Pointer to the data set through notify_register()

Definition at line 506 of file uxsnmp.h.

virtual int Snmp::get_notify_filter OidCollection trapids,
TargetCollection targets,
AddressCollection listen_addresses
[virtual]
 

Get notify register info.

Parameters:
trapids - ids listened for
targets - targets listened for
listen_addresses - interfaces listened on
Returns:
SNMP_CLASS_SUCCESS or SNMP_CLASS_INVALID if not registered

virtual int Snmp::get_notify_filter OidCollection trapids,
TargetCollection targets
[inline, virtual]
 

Get notify register info.

Parameters:
trapids - ids listened for
targets - targets listened for
Returns:
SNMP_CLASS_SUCCESS or SNMP_CLASS_INVALID if not registered

Definition at line 475 of file uxsnmp.h.

const char* Snmp::get_version  )  [static]
 

Get the version of the snmp++ library.

Returns:
The version of the snmp++ lib at runtime.

virtual int Snmp::inform Pdu pdu,
const SnmpTarget target,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Send a async INFORM-REQ.

Parameters:
pdu - Pdu to send
target - Target for the inform
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::inform Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a blocking INFORM-REQ.

Parameters:
pdu - Pdu to send
target - Target for the inform
Returns:
SNMP_CLASS_SUCCES or a negative error code

void Snmp::init int &  status,
IpAddress [2],
const unsigned short  port_v4,
const unsigned short  port_v6
[protected]
 

void Snmp::map_action unsigned short  action,
unsigned short &  pdu_action
[protected]
 

long Snmp::MyMakeReqId  )  [protected]
 

Generate a unique (for this Snmp obect) request id.

Returns:
Unique id between PDU_MIN_RID and PDU_MAX_RID

virtual int Snmp::notify_register const OidCollection trapids,
const TargetCollection targets,
const AddressCollection listen_addresses,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Register to get traps and informs.

Note:
listen_addresses param is ignored!

Every call to one of the notify_register() methods overwrites the previous given values.

Parameters:
trapids - ids to listen for
targets - targets to listen for
listen_addresses - interfaces to listen on
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCESS, SNMP_CLASS_TL_FAILED or SNMP_CLASS_TL_IN_USE

virtual int Snmp::notify_register const OidCollection trapids,
const TargetCollection targets,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Register to get traps and informs.

Note:
Every call to one of the notify_register() methods overwrites the previous given values.
Parameters:
trapids - ids to listen for
targets - targets to listen for
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCESS, SNMP_CLASS_TL_FAILED or SNMP_CLASS_TL_IN_USE

virtual int Snmp::notify_unregister  )  [virtual]
 

Unregister to get traps and informs.

Undo the call to notify_register().

Returns:
Always SNMP_CLASS_SUCCESS

virtual int Snmp::report Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a SNMPv3-REPORT.

Parameters:
pdu - Pdu to send
target - Target for the report (must be a UTarget)
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::response Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a RESPONSE.

Parameters:
pdu - Pdu to send
target - Target for the response
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::send_raw_data unsigned char *  send_buf,
size_t  send_len,
UdpAddress address,
int  fd = 0
[virtual]
 

Send raw UDP data.

This method may be used to send any data to the recepient.

Parameters:
send_buf - Data buffer
send_len - Length of the data
address - Recepient
fd - socket to use, if not specified, the socket of the object is used
Returns:
0 on success, -1 on failure

virtual int Snmp::set Pdu pdu,
const SnmpTarget target,
const snmp_callback  callback,
const void *  callback_data = 0
[virtual]
 

Send a async SNMP-SET request.

Parameters:
pdu - Pdu to send
target - Target for the set
callback - User callback function to use
callback_data - User definable data pointer
Returns:
SNMP_CLASS_SUCCES or a negative error code

virtual int Snmp::set Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a blocking SNMP-SET request.

Parameters:
pdu - Pdu to send
target - Target for the set
Returns:
SNMP_CLASS_SUCCES or a negative error code

int Snmp::snmp_engine Pdu pdu,
long int  non_reps,
long int  max_reps,
const SnmpTarget target,
const snmp_callback  cb,
const void *  cbd
[protected]
 

gets, sets and get nexts go through here....

This mf does all snmp sending and reception except for traps which are sent using trap().

Note:
that for a UTarget with an empty enngine id the Utarget::set_engine_id() may be called.

void Snmp::socket_cleanup  )  [static]
 

Shut down the Winsock library (WSACleanup).

void Snmp::socket_startup  )  [static]
 

Initialize the Winsock library (WSAStartup).

Note:
on Win32 this method *must* be called before creating Snmp or Address objects.

virtual int Snmp::trap Pdu pdu,
const SnmpTarget target
[virtual]
 

Send a SNMP-TRAP.

Parameters:
pdu - Pdu to send
target - Target for the trap
Returns:
SNMP_CLASS_SUCCES or a negative error code


Friends And Related Function Documentation

void v3CallBack int  reason,
Snmp snmp,
Pdu pdu,
SnmpTarget target,
void *  v3cd
[friend]
 


Member Data Documentation

int Snmp::construct_status [protected]
 

Definition at line 596 of file uxsnmp.h.

int Snmp::construct_status_ipv6 [protected]
 

Definition at line 597 of file uxsnmp.h.

long Snmp::current_rid [protected]
 

Definition at line 598 of file uxsnmp.h.

EventListHolder* Snmp::eventListHolder
 

Definition at line 529 of file uxsnmp.h.

int Snmp::iv_notify_fd [protected]
 

Definition at line 593 of file uxsnmp.h.

SNMPHANDLE Snmp::iv_snmp_session [protected]
 

Definition at line 589 of file uxsnmp.h.

SNMPHANDLE Snmp::iv_snmp_session_ipv6 [protected]
 

Definition at line 590 of file uxsnmp.h.

IpAddress Snmp::listen_address [protected]
 

Definition at line 592 of file uxsnmp.h.

snmp_callback Snmp::notifycallback [protected]
 

Definition at line 601 of file uxsnmp.h.

void* Snmp::notifycallback_data [protected]
 

Definition at line 602 of file uxsnmp.h.

SNMPHANDLE Snmp::pdu_handler [protected]
 

Definition at line 594 of file uxsnmp.h.

SNMPHANDLE Snmp::pdu_handler_ipv6 [protected]
 

Definition at line 595 of file uxsnmp.h.

SnmpSynchronized Snmp::v3Lock [static]
 

Definition at line 533 of file uxsnmp.h.


The documentation for this class was generated from the following file:
Generated on Tue Jan 4 22:42:20 2005 for SNMP++ by doxygen 1.3.2