+
+bool WaitPackets(int sd)
+{
+fd_set rfds;
+FD_ZERO(&rfds);
+FD_SET(sd, &rfds);
+
+struct timeval tv;
+tv.tv_sec = 0;
+tv.tv_usec = 500000;
+
+int res = select(sd + 1, &rfds, NULL, NULL, &tv);
+if (res == -1) // Error
+ {
+ if (errno != EINTR)
+ {
+ printfd(__FILE__, "Error on select: '%s'\n", strerror(errno));
+ }
+ return false;
+ }
+
+if (res == 0) // Timeout
+ {
+ return false;
+ }
+
+return true;
+}
+
+bool SNMP_AGENT::DispatchPDUs(const SMUX_PDUs_t * pdus)
+{
+SMUXHandlers::iterator it;
+it = smuxHandlers.find(pdus->present);
+if (it != smuxHandlers.end())
+ {
+ return (this->*(it->second))(pdus);
+ }
+else
+ {
+ switch (pdus->present)
+ {
+ case SMUX_PDUs_PR_NOTHING:
+ printfd(__FILE__, "PDUs: nothing\n");
+ break;
+ case SMUX_PDUs_PR_open:
+ printfd(__FILE__, "PDUs: open\n");
+ break;
+ case SMUX_PDUs_PR_registerRequest:
+ printfd(__FILE__, "PDUs: registerRequest\n");
+ break;
+ default:
+ printfd(__FILE__, "PDUs: undefined\n");
+ }
+ asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+ }
+return false;
+}
+
+bool SNMP_AGENT::CloseHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::CloseHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::RegisterResponseHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::RegisterResponseHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::PDUsHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::PDUsHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+PDUsHandlers::iterator it;
+it = pdusHandlers.find(pdus->choice.pdus.present);
+if (it != pdusHandlers.end())
+ {
+ return (this->*(it->second))(&pdus->choice.pdus);
+ }
+else
+ {
+ switch (pdus->present)
+ {
+ case PDUs_PR_NOTHING:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - nothing\n");
+ break;
+ case PDUs_PR_get_response:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - get response\n");
+ break;
+ case PDUs_PR_trap:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - trap\n");
+ break;
+ default:
+ printfd(__FILE__, "SNMP_AGENT::PDUsHandler() - undefined\n");
+ }
+ }
+return false;
+}
+
+bool SNMP_AGENT::CommitOrRollbackHandler(const SMUX_PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::CommitOrRollbackHandler()\n");
+asn_fprint(stderr, &asn_DEF_SMUX_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::GetRequestHandler(const PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::GetRequestHandler()\n");
+asn_fprint(stderr, &asn_DEF_PDUs, pdus);
+SendGetResponsePDU(sock, &pdus->choice.get_request);
+return false;
+}
+
+bool SNMP_AGENT::GetNextRequestHandler(const PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::GetNextRequestHandler()\n");
+asn_fprint(stderr, &asn_DEF_PDUs, pdus);
+return false;
+}
+
+bool SNMP_AGENT::SetRequestHandler(const PDUs_t * pdus)
+{
+printfd(__FILE__, "SNMP_AGENT::SetRequestHandler()\n");
+asn_fprint(stderr, &asn_DEF_PDUs, pdus);
+SendSetResponsePDU(sock, &pdus->choice.set_request);
+return false;
+}
+