main (int argc, char* argv[]) { if (argc>1) port = atoi(argv[1]); else port = 4700; #ifndef _NO_LOGGING DefaultLog::log->set_filter(ERROR_LOG, 8); DefaultLog::log->set_filter(WARNING_LOG, 8); DefaultLog::log->set_filter(EVENT_LOG, 8); DefaultLog::log->set_filter(INFO_LOG, 8); DefaultLog::log->set_filter(DEBUG_LOG, 8); #endif int status; Snmpx snmp(status, port); if (status == SNMP_CLASS_SUCCESS) { LOG_BEGIN(EVENT_LOG | 1); LOG("main: SNMP listen port"); LOG(port); LOG_END; } else { LOG_BEGIN(ERROR_LOG | 0); LOG("main: SNMP port init failed"); LOG(status); LOG_END; exit(1); } #ifdef _SNMPv3 char *filename = "snmpv3_boot_counter"; unsigned int snmpEngineBoots = 0; OctetStr engineId(SnmpEngineID::create_engine_id(port)); // you may use your own methods to load/store this counter status = getBootCounter(filename, engineId, snmpEngineBoots); if ((status != SNMPv3_OK) && (status < SNMPv3_FILEOPEN_ERROR)) cerr << "Error loading snmpEngineBoots counter: " << status << endl; snmpEngineBoots++; status = saveBootCounter(filename, engineId, snmpEngineBoots); if (status != SNMPv3_OK) cerr << "Error saving snmpEngineBoots counter: " << status << endl; mpInit(&snmp, engineId, snmpEngineBoots); #endif mib = new MasterAgentXMib(); init_signals(); reqList = new RequestList(); // register requestList for outgoing requests mib->set_request_list(reqList); AgentXMaster* agentx = new AgentXMaster(); agentx->set_connect_mode(AX_USE_TCP_SOCKET | AX_USE_UNIX_SOCKET); #ifdef AX_UNIX_SOCKET agentx->set_unix_port_loc("/var/agentx/"); #endif mib->set_agentx(agentx); init(*mib); // add MIB objects and setup USM/VACM reqList->set_snmp(&snmp); // start AgentX master mib->init(); // main loop Request* req; for (;;) { req = reqList->receive(120); if (req) { mib->process_request(req); } else { mib->cleanup(); } } return 0; }