4 //=============================================================================
8 * SNMP class definition. The Snmp class provides an object oriented
9 * approach to SNMP. The SNMP class is an encapsulation of SNMP
10 * sessions, gets, sets, etc. The class manages all SNMP
11 * resources and provides complete retry and timeout capability.
13 * @author Peter E Mellquist design
14 * @author first implementation Michael R. MacFaden port to ACE / use Reactor pattern
16 //=============================================================================
18 /*===================================================================
20 Hewlett-Packard Company
22 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
23 Permission to use, copy, modify, distribute and/or sell this software
24 and/or its documentation is hereby granted without fee. User agrees
25 to display the above copyright notice and this license notice in all
26 copies of the software and any documentation of the software. User
27 agrees to assume all liability for the use of the software; Hewlett-Packard
28 makes no representations about the suitability of this software for any
29 purpose. It is provided "AS-IS without warranty of any kind,either express
30 or implied. User hereby grants a royalty-free license to any and all
31 derivatives based upon this software code base.
32 =====================================================================*/
34 #include "ace/Reactor.h"
36 #if !defined (ACE_LACKS_PRAGMA_ONCE)
38 #endif /* ACE_LACKS_PRAGMA_ONCE */
40 #include "ace/SOCK_Dgram.h"
42 #include "asnmp/oid.h" // snmp++ oid class
43 #include "asnmp/vb.h" // snbmp++ vb class
44 #include "asnmp/target.h" // snmp++ target class
45 #include "asnmp/pdu.h" // snmp++ pdu class
46 #include "asnmp/snmperrs.h" // error macros and strings
47 #include "asnmp/address.h" // snmp++ address class defs
48 #include "asnmp/transaction_result.h"
49 #include "asnmp/ASNMP_Export.h"
52 class ASNMP_Export Snmp_Result
56 virtual ~Snmp_Result();
57 virtual void result(Snmp
*snmp
, int result
) = 0;
60 // Snmp session class - supports Version 1 operations in blocking mode
64 * @brief Concrete class Snmp defined the session and interface to
65 * communicate with another SNMP Version 1 agent
67 class ASNMP_Export Snmp
: public transaction_result
69 Snmp_Result
* result_
;
71 unsigned hold_req_id_
;
73 Snmp(unsigned short port
= INADDR_ANY
);
76 /// retrieve data from a peer agent for a given list of oid values
78 int get( Pdu
&pdu
, UdpTarget
&target
, Snmp_Result
* cb
= 0);
81 * retrieve data lexically adjacent to the oids specified in the pdu
85 int get_next( Pdu
&pdu
, UdpTarget
&target
, Snmp_Result
* cb
= 0);
87 /// set data in the agent from the list of oids in the pdu
89 int set( Pdu
&pdu
, UdpTarget
&target
, Snmp_Result
* cb
= 0);
91 /// send an SNMPv1 trap (unreliable) to a remote system (def port 162)
92 int trap( Pdu
&pdu
, UdpTarget
&target
);
94 /// status of object after construction
97 /// given error code, return string reason
98 static const char * error_string(int code
);
100 /// retrieve a reason string if any of the above commands fail
101 const char * error_string();
103 /// for async transaction results
104 void result(transaction
* t
, int rc
);
106 /// allow the host name to be overriden
107 static void override_host_name(const char* name
);
109 /// returns the overriden host name
110 static void get_host_name(char* name
, int len
);
113 void check_default_port(UdpTarget
& target
,unsigned short port
=DEF_AGENT_PORT
);
114 int run_transaction(Pdu
& pdu
, UdpTarget
& target
);
115 int run_transaction(Pdu
& pdu
, UdpTarget
& target
, Snmp_Result
* cb
);
116 int validate_args(const Pdu
& pdu
, const UdpTarget
& target
) const;
121 ACE_SOCK_Dgram iv_snmp_session_
;
123 /// status of construction
124 int construct_status_
;
126 /// result code from last transaction
127 int last_transaction_status_
;
129 /// transaction request id
132 static char host_name_
[MAXHOSTNAMELEN
];