⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trapd.cpp

📁 JdonFramework need above jdk 1.4.0 This version has passed under Tomcat 4.x/5.x JBoss 3.x/JBoss 4.0
💻 CPP
字号:
/*  Trapd.cpp  Simple example of a trap daemon  version 2.8  Copyright (c) 1999  Hewlett-Packard Company  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.  Permission to use, copy, modify, distribute and/or sell this software  and/or its documentation is hereby granted without fee. User agrees  to display the above copyright notice and this license notice in all  copies of the software and any documentation of the software. User  agrees to assume all liability for the use of the software; Hewlett-Packard  makes no representations about the suitability of this software for any  purpose. It is provided "AS-IS" without warranty of any kind,either express  or implied. User hereby grants a royalty-free license to any and all  derivatives based upon this software code base.  Peter E. Mellquist*/#include "snmp_pp.h"#include "eventlist.h"   // needed for my own main loop#include <iostream.h>#include <stdlib.h>#include <stdio.h>// trap function callbackvoid trap_callback( int reason,                    Snmp *session,                    Pdu &pdu,                    SnmpTarget &target,                    void *cbd) {  char outbuff[1024];  char scratch[256];  GenAddress address;  Oid trapid;  Vb vb;  TimeTicks timestamp;  if ( reason == SNMP_CLASS_NOTIFICATION) {     target.get_address( address);         pdu.get_notify_id( trapid);         pdu.get_notify_timestamp( timestamp);         strcpy( outbuff,"Trap From:");         strcat( outbuff, address.get_printable());         strcat( outbuff, "\n");         strcat( outbuff, "Trap ID:");         strcat( outbuff, trapid.get_printable());         strcat( outbuff, "\n");         strcat( outbuff, "Trap Time:");         strcat( outbuff, timestamp.get_printable());         strcat( outbuff, "\n");         for( int z=0;z<pdu.get_vb_count();z++) {            strcat( outbuff,"Vb# ");                sprintf( scratch,"%d",z+1);                strcat( outbuff, scratch);                strcat( outbuff, "\n");                pdu.get_vb(vb,z);                sprintf( scratch,"Oid = %s\nValue= %s\n", vb.get_printable_oid(), vb.get_printable_value());                strcat( outbuff, scratch);     }     printf(outbuff);  }};int main( )  {   int maxfds;   fd_set readfds, writefds, exceptfds;   TargetCollection targets;   OidCollection oids;     //----------[ create a SNMP++ session ]-----------------------------------   int status;    Snmp snmp( status);                // check construction status   if ( status != SNMP_CLASS_SUCCESS) {      cout << "SNMP++ Session Create Fail, " << snmp.error_msg(status) << "\n";      return 0;   }   //----------[ register to receive traps ]---------------------------------   status = snmp.notify_register( oids, targets, &trap_callback, NULL);   if ( status != SNMP_CLASS_SUCCESS) {      cout << "SNMP++ Session Create Fail, " << snmp.error_msg(status) << "\n";      return 0;   }   //---------[ set up the select loop ]-------------------------------------   SNMPGetFdSets(maxfds, readfds, writefds, exceptfds);   for (;;) {      select( maxfds, &readfds, & writefds, &exceptfds,NULL);      SNMPProcessPendingEvents();   };   return 0;}  // end get

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -