diff options
author | mrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-09-04 23:48:12 +0000 |
---|---|---|
committer | mrm <mrm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-09-04 23:48:12 +0000 |
commit | ef570e751faf30666708533b0b5678d8117fa783 (patch) | |
tree | ce3827afdecfc2ab71da9ab19a9c7c266bfbd9a9 /ASNMP/asnmp/sagent.cpp | |
parent | 3078456790c19208fa32223a395731df551c6176 (diff) | |
download | ATCD-ef570e751faf30666708533b0b5678d8117fa783.tar.gz |
agent api
Diffstat (limited to 'ASNMP/asnmp/sagent.cpp')
-rw-r--r-- | ASNMP/asnmp/sagent.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/ASNMP/asnmp/sagent.cpp b/ASNMP/asnmp/sagent.cpp new file mode 100644 index 00000000000..d7330815aa0 --- /dev/null +++ b/ASNMP/asnmp/sagent.cpp @@ -0,0 +1,93 @@ +/* -*-C++-*- */ +// ============================================================================ +// +// = LIBRARY +// asnmp +// +// = FILENAME +// sagent.cpp +// +// = DESCRIPTION +// SNMP agent class defintion. The sagent class provides an object oriented +// approach for creating SNMP Agents. The sagent class is an encapsulation of SNMP +// sessions, gets, sets, etc. +// +// = AUTHOR +// Michael R. MacFaden +// +// ============================================================================ +#include "ace/Reactor.h" +#include "ace/SOCK_Dgram.h" + +#include "asnmp/oid.h" // snmp++ oid class +#include "asnmp/vb.h" // snbmp++ vb class +#include "asnmp/target.h" // snmp++ target class +#include "asnmp/pdu.h" // snmp++ pdu class +#include "asnmp/snmperrs.h" // error macros and strings +#include "asnmp/address.h" // snmp++ address class defs +#include "asnmp/snmp.h" // manager snmp interface +#include "asnmp/sagent.h" // agent interface +#include "asnmp/transaction.h" // convert from wire to API + +sagent::sagent(unsigned short port): Snmp(port) +{ + ACE_TRACE("sagent::sagent(short)"); +} + +sagent::~sagent() +{ + ACE_TRACE("sagent::~sagent"); +} + +int sagent::handle_input(ACE_HANDLE fd) +{ + ACE_TRACE("sagent::handle_input"); + + transaction tr(iv_snmp_session_); // this section needs a better design + tr.handle_input(fd); + char rcv_com_str[MAX_COMM_STR_LEN]; + tr.result(pdu_, rcv_com_str); + OctetStr community(rcv_com_str); + const ACE_INET_Addr &ta = tr.get_from_addr(); + char buf_tmp[MAXHOSTNAMELEN + 1]; + ta.addr_to_string (buf_tmp, MAXHOSTNAMELEN); + UdpAddress ra(buf_tmp); + tgt_.set_address(ra); + + + // process msg here by calling subclass's implementation + switch (pdu_.get_type()){ + case sNMP_PDU_GET: + tgt_.set_read_community(community); + this->handle_get(pdu_, tgt_); + break; + + case sNMP_PDU_GETNEXT: + tgt_.set_read_community(community); + this->handle_get_next(pdu_, tgt_); + break; + + case sNMP_PDU_SET: + tgt_.set_write_community(community); + this->handle_set(pdu_, tgt_); + break; + + default: + ACE_ASSERT(0); + } + return 0; +} + +ACE_HANDLE sagent::get_handle() const +{ + ACE_TRACE("sagent::get_handle"); + return iv_snmp_session_.get_handle(); +} + +int sagent::respond(Pdu& pdu,UdpTarget& tgt) +{ + transaction tr(pdu, tgt, iv_snmp_session_); + tr.send(); + return 0; +} + |