1 // This server daemon processes SNMPv1 requests over MIB II System group
3 #include "snmp_agent.h"
4 #include "agent_impl.h" // actual implementation
5 #include "ace/Argv_Type_Converter.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Reactor.h"
10 #define SNMP_AGENT_PORT (161)
11 #define WR_COM ACE_TEXT ("private")
12 #define RD_COM ACE_TEXT ("public")
14 snmp_agent::snmp_agent() : agent_(0)
16 ACE_TRACE("snmp_agent::snmp_agent");
19 snmp_agent::~snmp_agent()
21 ACE_TRACE("snmp_agent::~snmp_agent");
26 int snmp_agent::valid() const
28 ACE_TRACE("snmp_agent::valid");
32 int snmp_agent::set_args(int argc
, char *argv
[])
34 ACE_TRACE("snmp_agent::set_args");
35 unsigned short port
= SNMP_AGENT_PORT
;
36 const ACE_TCHAR
*rd
= RD_COM
;
37 const ACE_TCHAR
*wr
= WR_COM
;
38 ACE_Argv_Type_Converter
to_tchar (argc
, argv
);
41 (argc
, to_tchar
.get_TCHAR_argv (), ACE_TEXT ("p:w:r:hv"));
43 for (int c
; (c
= get_opt ()) != -1; )
48 port
= (ACE_OS::atoi (get_opt
.optarg
));
50 case 'w': // write community string
53 case 'r': // read community string
56 case 'h': // help & version info
60 ACE_TEXT ("(%P|%t) Example SNMP Version 1 Agent - ASNMP/ACE\n")));
63 return -1; // invalid arg
67 agent_
= new agent_impl(port
,
68 ACE_TEXT_ALWAYS_CHAR (rd
),
69 ACE_TEXT_ALWAYS_CHAR (wr
)); // opens OS IO port
75 ACE_TRACE("snmp_agent::run");
80 if (agent_
->open_port()) {
81 ACE_DEBUG((LM_DEBUG
, "(%P|%t) open port %d failed\n", agent_
->get_port()));
86 // Run forever, processing SNMP requests.
89 ACE_TEXT ("(%P|%t) starting up snmp agent (server) daemon\n")));
91 agent_
->process_requests();
95 ACE_TEXT ("(%P|%t) shutting down snmp agent (server) daemon\n")));