2 //=============================================================================
6 * SNMP agent class definition. The sagent class provides an object oriented
7 * approach for creating SNMP Agents. The sagent class is an encapsulation
8 * of SNMP sessions, gets, sets, etc.
10 * @author Michael R. MacFaden
12 //=============================================================================
14 #include "ace/Reactor.h"
15 #include "ace/SOCK_Dgram.h"
17 #include "asnmp/oid.h" // snmp++ oid class
18 #include "asnmp/vb.h" // snbmp++ vb class
19 #include "asnmp/target.h" // snmp++ target class
20 #include "asnmp/pdu.h" // snmp++ pdu class
21 #include "asnmp/snmperrs.h" // error macros and strings
22 #include "asnmp/address.h" // snmp++ address class defs
23 #include "asnmp/snmp.h" // manager snmp interface
24 #include "asnmp/sagent.h" // agent interface
25 #include "asnmp/transaction.h" // convert from wire to API
27 sagent::sagent(unsigned short port
): Snmp(port
)
29 ACE_TRACE("sagent::sagent(short)");
34 ACE_TRACE("sagent::~sagent");
37 int sagent::handle_input(ACE_HANDLE fd
)
39 ACE_TRACE("sagent::handle_input");
41 transaction
tr(iv_snmp_session_
); // this section needs a better design
43 char rcv_com_str
[MAX_COMM_STR_LEN
];
44 if (tr
.result(pdu_
, rcv_com_str
) < 0)
46 OctetStr
community(rcv_com_str
);
47 const ACE_INET_Addr
&ta
= tr
.get_from_addr();
48 ACE_TCHAR buf_tmp
[MAXHOSTNAMELEN
+ 1];
49 ta
.addr_to_string (buf_tmp
, MAXHOSTNAMELEN
);
50 UdpAddress
ra (ACE_TEXT_ALWAYS_CHAR (buf_tmp
));
54 // process msg here by calling subclass's implementation
55 switch (pdu_
.get_type()){
57 tgt_
.set_read_community(community
);
58 this->handle_get(pdu_
, tgt_
);
61 case sNMP_PDU_GETNEXT
:
62 tgt_
.set_read_community(community
);
63 this->handle_get_next(pdu_
, tgt_
);
67 tgt_
.set_write_community(community
);
68 this->handle_set(pdu_
, tgt_
);
77 ACE_HANDLE
sagent::get_handle() const
79 ACE_TRACE("sagent::get_handle");
80 return iv_snmp_session_
.get_handle();
83 int sagent::respond(Pdu
& pdu
,UdpTarget
& tgt
)
85 pdu
.set_type(sNMP_PDU_RESPONSE
);
86 transaction
tr(pdu
, tgt
, iv_snmp_session_
);