int main(void) { unsigned char pkt[200]; req r; ssize_t len; unsigned int i; FILE *in; uint32_t seed; signal(SIGALRM, tooslow); alarm(TIMEOUT); // set up the head of the SNMP MIB tree InitTree(); SetCount = 0; ErrCount = 0; // seed the prng if ((in = fopen("/dev/urandom", "r")) == NULL) { exit(-1); } if (fread(&seed, 1, 4, in) != 4) { exit(-1); } fclose(in); srand(seed); // init the MIB with some objects PopulateMIB(); while (1) { if (ErrCount > MAX_ERRORS) { DestroyTree(MIB); exit(-1); } bzero(pkt, 200); bzero(&r, sizeof(req)); if ((len = ReceivePacket(pkt, 200)) == 0) { DestroyTree(MIB); exit(-1); } // reset the timer alarm(TIMEOUT); // parse the packet and handle the particular request if (ParseSnmpPkt(pkt, len, &r)) { if (r.type == GET_REQUEST) { HandleGetRequest(&r); } else if (r.type == GET_NEXT_REQUEST) { HandleGetNextRequest(&r); } else if (r.type == SET_REQUEST) { HandleSetRequest(&r); } } else { // error parsing packet ErrCount++; } } }
void GRIProcessThread::HandleDynamicCommand(ProcessCommand *pc) { if (!pc) return; switch (pc->command_type) { case RUN_ACTION: DynamicRunAction(pc->key); case SET: HandleSetRequest(pc); case GET: HandleGetRequest(pc); } delete pc; }