SNMP++
3.3.11
|
SNMP class definition. More...
#include <uxsnmp.h>
Classes | |
struct | V3CallBackData |
Internal used callback data structure for async v3 requests. More... | |
Public Member Functions | |
virtual int | cancel (const unsigned long rid) |
Cancel a pending request. More... | |
virtual int | send_raw_data (unsigned char *send_buf, size_t send_len, UdpAddress &address, SnmpSocket fd=INVALID_SOCKET) |
Send raw UDP data. More... | |
const IpAddress & | get_listen_address () const |
bool | start_poll_thread (const int timeout) |
Start one thread listening for responses and notifications. More... | |
void | stop_poll_thread () |
Stop the thread listening for responses and notifications. More... | |
EventListHolder * | get_eventListHolder () |
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. More... | |
Snmp (int &status, const UdpAddress &addr) | |
Construct a new SNMP session using the given UDP address. More... | |
Snmp (int &status, const UdpAddress &addr_v4, const UdpAddress &addr_v6) | |
Construct a new SNMP session using the given UDP addresses. More... | |
virtual | ~Snmp () |
Destructor. More... | |
Sending SNMP Pdus | |
virtual int | get (Pdu &pdu, SnmpTarget &target) |
Send a blocking SNMP-GET request. More... | |
virtual int | get (Pdu &pdu, SnmpTarget &target, const snmp_callback callback, const void *callback_data=0) |
Send a async SNMP-GET request. More... | |
virtual int | get_next (Pdu &pdu, SnmpTarget &target) |
Send a blocking SNMP-GETNEXT request. More... | |
virtual int | get_next (Pdu &pdu, SnmpTarget &target, const snmp_callback callback, const void *callback_data=0) |
Send a async SNMP-GETNEXT request. More... | |
virtual int | set (Pdu &pdu, SnmpTarget &target) |
Send a blocking SNMP-SET request. More... | |
virtual int | set (Pdu &pdu, SnmpTarget &target, const snmp_callback callback, const void *callback_data=0) |
Send a async SNMP-SET request. More... | |
virtual int | get_bulk (Pdu &pdu, SnmpTarget &target, const int non_repeaters, const int max_reps) |
Send a blocking SNMP-GETBULK request. More... | |
virtual int | get_bulk (Pdu &pdu, 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. More... | |
virtual int | trap (Pdu &pdu, const SnmpTarget &target) |
Send a SNMP-TRAP. More... | |
virtual int | report (Pdu &pdu, SnmpTarget &target) |
Send a SNMPv3-REPORT. More... | |
virtual int | inform (Pdu &pdu, SnmpTarget &target) |
Send a blocking INFORM-REQ. More... | |
virtual int | inform (Pdu &pdu, SnmpTarget &target, const snmp_callback callback, const void *callback_data=0) |
Send a async INFORM-REQ. More... | |
virtual int | response (Pdu &pdu, SnmpTarget &target, SnmpSocket fd=INVALID_SOCKET) |
Send a RESPONSE. More... | |
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. More... | |
virtual int | engine_id_discovery (OctetStr &engine_id, const int timeout_sec, const UdpAddress &addr) |
Trap and Inform handling | |
virtual void | notify_set_listen_port (const int port) |
Set the port for listening to traps and informs. More... | |
virtual int | notify_get_listen_port () |
Get the port that is used for listening to traps and informs. More... | |
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. More... | |
virtual int | notify_unregister () |
Unregister to get traps and informs. More... | |
virtual int | get_notify_filter (OidCollection &trapids, TargetCollection &targets) |
Get notify register info. More... | |
snmp_callback | get_notify_callback () |
Get a pointer to the callback function used for trap reception. More... | |
void * | get_notify_callback_data () |
Get a pointer to the data that is passed to the callback function. More... | |
Public Member Functions inherited from SnmpSynchronized | |
SnmpSynchronized () | |
virtual | ~SnmpSynchronized () |
void | lock () |
void | unlock () |
Static Public Member Functions | |
static const char * | get_version () |
Get the version of the snmp++ library. More... | |
static const char * | error_msg (const int c) |
Returns a human readable error string. More... | |
static int | error_code (const Oid &v3Oid) |
Returns the error code for a SNMPv3 report Oid. More... | |
static const char * | error_msg (const Oid &v3Oid) |
Returns a human readable error string. More... | |
static void | socket_startup () |
Initialize the Winsock library (WSAStartup). More... | |
static void | socket_cleanup () |
Shut down the Winsock library (WSACleanup). More... | |
Protected Member Functions | |
bool | is_running () const |
Check for the status of the worker thread. More... | |
long | MyMakeReqId () |
Generate a unique (for this Snmp obect) request id. More... | |
void | init (int &status, IpAddress *[2], const unsigned short port_v4, const unsigned short port_v6) |
Common init function used by constructors. More... | |
void | check_notify_timestamp (Pdu &pdu) |
Set the notify timestamp of a trap pdu if the user did not set it. More... | |
int | snmp_engine (Pdu &pdu, long int non_reps, long int max_reps, SnmpTarget &target, const snmp_callback cb, const void *cbd, SnmpSocket fd=INVALID_SOCKET, int reports_received=0) |
gets, sets and get nexts go through here.... More... | |
void | map_action (unsigned short action, unsigned short &pdu_action) |
Static Protected Member Functions | |
static void * | process_thread (void *snmp) |
This is a working thread for the recovery of the pending events. More... | |
Protected Attributes | |
SnmpSocket | iv_snmp_session |
IpAddress | listen_address |
long | current_rid |
snmp_callback | notifycallback |
void * | notifycallback_data |
EventListHolder * | eventListHolder |
Private Attributes | |
bool | m_isThreadRunning |
int | m_pollTimeOut |
pthread_t | m_hThread |
Friends | |
void | v3CallBack (int reason, Snmp *snmp, Pdu &pdu, SnmpTarget &target, void *v3cd) |
void | deleteV3Callback (struct Snmp::V3CallBackData *&cbData) |
Additional Inherited Members | |
Public Attributes inherited from SnmpSynchronized | |
pthread_mutex_t | _mutex |
SNMP class definition.
The Snmp class provides an object oriented approach to SNMP. The SNMP class is an encapsulation of SNMP sessions, get, set and get next operations. The class manages all SNMP resources and provides complete retry and timeout capability.
This class is thread save.
Snmp::Snmp | ( | int & | status, |
const unsigned short | port = 0 , |
||
const bool | bind_ipv6 = false |
||
) |
Construct a new SNMP session using the given UDP port.
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.
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.
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 |
Destructor.
|
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.
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 |
Cancel a pending request.
rid | - The request id to cancel |
|
protected |
Set the notify timestamp of a trap pdu if the user did not set it.
|
virtual |
|
static |
|
static |
Returns a human readable error string.
c | - Error code returned by any method of this class |
|
inlinestatic |
|
virtual |
Send a blocking SNMP-GET request.
pdu | - Pdu to send |
target | - Target for the get |
|
virtual |
Send a async SNMP-GET request.
pdu | - Pdu to send |
target | - Target for the get |
callback | - User callback function to use |
callback_data | - User definable data pointer |
|
virtual |
Send a blocking SNMP-GETBULK request.
pdu | - Pdu to send |
target | - Target for the getbulk |
non_repeaters | - number of non repeaters |
max_reps | - maximum number of repetitions |
|
virtual |
Send a async SNMP-GETBULK request.
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 |
|
inline |
|
virtual |
Send a blocking SNMP-GETNEXT request.
pdu | - Pdu to send |
target | - Target for the getnext |
|
virtual |
Send a async SNMP-GETNEXT request.
pdu | - Pdu to send |
target | - Target for the getnext |
callback | - User callback function to use |
callback_data | - User definable data pointer |
|
inline |
Get a pointer to the callback function used for trap reception.
|
inline |
Get a pointer to the data that is passed to the callback function.
|
virtual |
Get notify register info.
trapids | - ids listened for |
targets | - targets listened for |
|
static |
Get the version of the snmp++ library.
|
virtual |
Send a blocking INFORM-REQ.
pdu | - Pdu to send |
target | - Target for the inform |
|
virtual |
Send a async INFORM-REQ.
pdu | - Pdu to send |
target | - Target for the inform |
callback | - User callback function to use |
callback_data | - User definable data pointer |
|
protected |
Common init function used by constructors.
|
inlineprotected |
|
protected |
|
protected |
Generate a unique (for this Snmp obect) request id.
|
virtual |
Get the port that is used for listening to traps and informs.
|
virtual |
Register to get traps and informs.
trapids | - ids to listen for |
targets | - targets to listen for |
callback | - User callback function to use |
callback_data | - User definable data pointer |
|
virtual |
Set the port for listening to traps and informs.
|
virtual |
Unregister to get traps and informs.
Undo the call to notify_register().
|
staticprotected |
This is a working thread for the recovery of the pending events.
snmp | [in] pointer to the whole object |
|
virtual |
|
virtual |
Send a RESPONSE.
pdu | - Pdu to send |
target | - Target for the response |
fd | - file descriptor to use, should be the one that was passed to the callback function |
|
virtual |
Send raw UDP data.
This method may be used to send any data to the recepient.
send_buf | - Data buffer |
send_len | - Length of the data |
address | - Recipient |
fd | - socket to use, if not specified, the socket of the object is used |
|
virtual |
Send a blocking SNMP-SET request.
pdu | - Pdu to send |
target | - Target for the set |
|
virtual |
Send a async SNMP-SET request.
pdu | - Pdu to send |
target | - Target for the set |
callback | - User callback function to use |
callback_data | - User definable data pointer |
|
protected |
|
static |
Shut down the Winsock library (WSACleanup).
|
static |
bool Snmp::start_poll_thread | ( | const int | timeout | ) |
Start one thread listening for responses and notifications.
This method is used to start response and notification processing in a multi threaded setup.
timeout | - Timeout for each call of the select() or poll() system call. |
void Snmp::stop_poll_thread | ( | ) |
Stop the thread listening for responses and notifications.
This method is used to stop the thread started with start_poll_thread().
|
virtual |
Send a SNMP-TRAP.
pdu | - Pdu to send |
target | - Target for the trap |
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |