WSnmpUtil.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //****************************************************************
  2. //
  3. // header file for wsnmputil.cpp utility.
  4. //
  5. //****************************************************************
  6. #ifndef _WSNMP_UTIL_
  7. #define _WSNMP_UTIL_ 1
  8. #include <winsock2.h>
  9. //**************************************************************************
  10. //
  11. // definitions.
  12. //
  13. //**************************************************************************
  14. #define WM_SNMP_INCOMING (WM_USER + 1)
  15. #define WM_SNMP_DONE (WM_USER + 2)
  16. #define NOTIFICATION_CLASS "SNMPUTIL NOTIFICATION CLASS"
  17. #define SNMP_FAILURE(s) ((s) == SNMPAPI_FAILURE)
  18. #define BUFFER_LEN 255
  19. #define MAXENTITYSTRLEN 128
  20. #define IPADDRLEN 4
  21. #define MINVARBINDLEN 2
  22. #define SYSUPTIMEINDEX 0
  23. #define SNMPTRAPOIDINDEX 1
  24. #define DEFAULT_ADDRESS_IP "127.0.0.1"
  25. #define CMD_LINE_ARGS 255 // maximum command line arguments
  26. #define MAX_GETBLK_OIDS 10
  27. #define MAX_BUFFER_LEN 2048
  28. // defintions that define the operation we are about to do.
  29. #define GET 1
  30. #define GET_NEXT 2
  31. #define WALK 3
  32. #define SET 4
  33. #define TRAP 5
  34. #define GET_BULK 6
  35. #define SUB_TREE 7
  36. //**************************************************************************
  37. //
  38. // Structure definitions.
  39. //
  40. //**************************************************************************
  41. typedef struct _SNMP_MGR_SESSION
  42. {
  43. HSNMP_SESSION hSnmpSession; // handle to winsnmp session
  44. HSNMP_ENTITY hAgentEntity; // handle to agent entity
  45. HSNMP_ENTITY hManagerEntity; // handle to manager entity
  46. HSNMP_CONTEXT hViewContext; // handle to view context
  47. HSNMP_PDU hPdu; // handle to snmp pdu
  48. HSNMP_VBL hVbl; // handle to var bind list
  49. HWND hWnd; // handle to window
  50. smiINT32 nPduType; // current pdu type
  51. smiINT32 nRequestId; // current request id
  52. smiINT32 nError; // last system error
  53. smiINT32 nErrorStatus; // error status
  54. smiINT32 nErrorIndex; // error index
  55. } SNMP_MGR_SESSION, *PSNMP_MGR_SESSION;
  56. //****************************************************************
  57. //
  58. // global vars.
  59. //
  60. //****************************************************************
  61. class GlobalVars
  62. {
  63. public:
  64. GlobalVars( )
  65. {
  66. nTimeOut = 6000;
  67. nRetries = 3;
  68. nRequestId = 1;
  69. oidCount = 0;
  70. pAgentStrAddr = NULL;
  71. pAgentCommunity = NULL;
  72. pSetValue = NULL;
  73. fDone = FALSE; // default
  74. version = FALSE; // Use v1 by default;
  75. doSet = FALSE; // dont do set by default.
  76. }
  77. ~GlobalVars( ) { }
  78. HINSTANCE g_hInst; // module handle.
  79. smiINT32 oidCount; // number of Oids.
  80. smiINT32 operation; // define the operation
  81. smiINT32 nTimeOut; // timeout in milli-seconds
  82. smiINT32 nRetries; // number of retries
  83. smiINT32 nRequestId; // request id.
  84. smiVALUE value; // encapsulate in global vars
  85. smiOID startOid; // starting OID.
  86. smiOID oid; // oid from the command line.
  87. smiINT non_repeaters; // non_repeaters field of SNMP_PDU_GETBULK
  88. smiINT max_repetitions; // max_repetitions field of SNMP_PDU_GETBULK
  89. BOOL doSet; // should we do a set?
  90. BOOL fDone; // A bool var
  91. BOOL version; // if TRUE -> v2C else use v1.
  92. CHAR *pAgentStrAddr; // pointer to agent string
  93. CHAR *pSetValue; // pointer to the SET value in ASCII
  94. CHAR *pAgentCommunity; // pointer to agent community string
  95. CHAR *pszOid[ CMD_LINE_ARGS ]; // pointer to OID string
  96. struct sockaddr_in agentSockAddr; // agent string converted to proper address.
  97. };
  98. extern GlobalVars gVars;
  99. //****************************************************************
  100. //
  101. // function prototypes.
  102. //
  103. //****************************************************************
  104. //
  105. // following functions are defined in wsnmputil.cpp
  106. //
  107. BOOL OpenWinSNMPSession( PSNMP_MGR_SESSION pSession );
  108. BOOL CloseWinSNMPSession( PSNMP_MGR_SESSION pSession );
  109. BOOL CreateNotificationWindow( PSNMP_MGR_SESSION pSession );
  110. BOOL DestroyNotificationWindow( PSNMP_MGR_SESSION pSession );
  111. LRESULT CALLBACK NotificationWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  112. BOOL ProcessNotification( PSNMP_MGR_SESSION pSession );
  113. BOOL WaitForTraps( PSNMP_MGR_SESSION pSession );
  114. BOOL ProcessAgentResponse( PSNMP_MGR_SESSION pSession );
  115. BOOL CreateVbl( PSNMP_MGR_SESSION pSession, smiOID *pOid, smiVALUE * pValue );
  116. void FreeVblandPdu( PSNMP_MGR_SESSION pSession );
  117. BOOL CreatePduSendRequest( PSNMP_MGR_SESSION pSession, smiVALUE *pValue );
  118. //
  119. // following functions are defined in helper.cpp
  120. //
  121. void Usage( );
  122. void PrintDbgMessage( LPSTR, ... );
  123. BOOL ConvertTexttoIp( char *agentAddress );
  124. BOOL ParseCommandLine( int argc, char **argv );
  125. void ConvertStringToSmiValue( smiVALUE *pValue );
  126. void PrintOidValue( smiVALUE *value );
  127. BOOL PrintVarBind( PSNMP_MGR_SESSION pSession );
  128. void ParseAndPrintv2Trap( PSNMP_MGR_SESSION pSession );
  129. #endif