snmpmsg.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*_############################################################################
  2. _##
  3. _## snmpmsg.h
  4. _##
  5. _## SNMP++v3.2.23
  6. _## -----------------------------------------------
  7. _## Copyright (c) 2001-2007 Jochen Katz, Frank Fock
  8. _##
  9. _## This software is based on SNMP++2.6 from Hewlett Packard:
  10. _##
  11. _## Copyright (c) 1996
  12. _## Hewlett-Packard Company
  13. _##
  14. _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  15. _## Permission to use, copy, modify, distribute and/or sell this software
  16. _## and/or its documentation is hereby granted without fee. User agrees
  17. _## to display the above copyright notice and this license notice in all
  18. _## copies of the software and any documentation of the software. User
  19. _## agrees to assume all liability for the use of the software;
  20. _## Hewlett-Packard and Jochen Katz make no representations about the
  21. _## suitability of this software for any purpose. It is provided
  22. _## "AS-IS" without warranty of any kind, either express or implied. User
  23. _## hereby grants a royalty-free license to any and all derivatives based
  24. _## upon this software code base.
  25. _##
  26. _## Stuttgart, Germany, Sun Nov 11 15:10:59 CET 2007
  27. _##
  28. _##########################################################################*/
  29. /*===================================================================
  30. Copyright (c) 1999
  31. Hewlett-Packard Company
  32. ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  33. Permission to use, copy, modify, distribute and/or sell this software
  34. and/or its documentation is hereby granted without fee. User agrees
  35. to display the above copyright notice and this license notice in all
  36. copies of the software and any documentation of the software. User
  37. agrees to assume all liability for the use of the software; Hewlett-Packard
  38. makes no representations about the suitability of this software for any
  39. purpose. It is provided "AS-IS without warranty of any kind,either express
  40. or implied. User hereby grants a royalty-free license to any and all
  41. derivatives based upon this software code base.
  42. SNMP++ S N M P M E S S A G E . H
  43. SNMPMESSAGE CLASS DEFINITION
  44. DESIGN + AUTHOR:
  45. Peter E Mellquist
  46. LANGUAGE:
  47. ANSI C++
  48. OPERATING SYSTEMS:
  49. Win 32
  50. BSD UNIX
  51. DESCRIPTION:
  52. ASN.1 encoding / decoding class
  53. =====================================================================*/
  54. // $Id: snmpmsg.h 287 2007-03-22 22:37:09Z katz $
  55. #ifndef _SNMPMSG
  56. #define _SNMPMSG
  57. #include "snmp_pp/config_snmp_pp.h"
  58. #include "snmp_pp/smival.h"
  59. #include "snmp_pp/pdu.h"
  60. #include "snmp_pp/target.h"
  61. #include "snmp_pp/asn1.h"
  62. #include "snmp_pp/mp_v3.h"
  63. #ifdef SNMP_PP_NAMESPACE
  64. namespace Snmp_pp {
  65. #endif
  66. DLLOPT void freeSmivalDescriptor( SmiVALUE* );
  67. DLLOPT int convertVbToSmival( const Vb&, SmiVALUE* );
  68. #define SNMP_MSG_OID_SYSUPTIME "1.3.6.1.2.1.1.3.0"
  69. #define SNMP_MSG_OID_TRAPID "1.3.6.1.6.3.1.1.4.1.0"
  70. class Snmp;
  71. // SnmpMessage Class
  72. class DLLOPT SnmpMessage
  73. {
  74. public:
  75. // construct a SnmpMessage object
  76. SnmpMessage() : bufflen(MAX_SNMP_PACKET), valid_flag(false) {};
  77. // load up using a Pdu, community and SNMP version
  78. // performs ASN.1 serialization
  79. // result status returned
  80. private:
  81. int load( const Pdu &pdu, // Pdu to serialize
  82. const OctetStr &community, // community name to use
  83. const snmp_version version, // SNMP version, v1 or v2
  84. const OctetStr *engine_id, // optional v3
  85. const OctetStr *security_name, // optional v3
  86. const int security_model); // optional v3
  87. public:
  88. int load( const Pdu &pdu, // Pdu to serialize
  89. const OctetStr &community, // community name to use
  90. const snmp_version version) // SNMP version, v1 or v2
  91. { return load(pdu, community, version, 0, 0, 0); };
  92. // load up message using ASN.1 data stream
  93. // status is returned
  94. int load( unsigned char *data, // data to be loaded
  95. unsigned long len); // len of data to be loaded
  96. // unload ( unserialize ) into SNMP++ Pdu, community and version
  97. // status is returned
  98. private:
  99. int unload( Pdu &pdu, // Pdu returned
  100. OctetStr &community, // community name
  101. snmp_version &version, // version
  102. OctetStr *engine_id, // optional v3
  103. OctetStr *security_name, // optional v3
  104. long int *security_model,
  105. UdpAddress *from_addr,
  106. Snmp *snmp_session);
  107. public:
  108. int unload( Pdu &pdu, // Pdu returned
  109. OctetStr &community, // community name
  110. snmp_version &version) // version
  111. { return unload(pdu, community, version, 0, 0, 0, 0, 0); };
  112. #ifdef _SNMPv3
  113. int loadv3( const Pdu &pdu, // Pdu to serialize
  114. const OctetStr &engine_id, // engine_id to use
  115. const OctetStr &sec_name, // securit_name to use
  116. const int sec_model, // security_model to use
  117. const snmp_version version) // SNMP version, v3
  118. { return load(pdu, "", version, &engine_id, &sec_name, sec_model); }
  119. int unloadv3( Pdu &pdu, // Pdu returned
  120. snmp_version &version, // version
  121. OctetStr &engine_id, // optional v3
  122. OctetStr &security_name, // optional v3
  123. long int &security_model,
  124. UdpAddress &from_addr,
  125. Snmp &snmp_session);
  126. // returns TRUE if the message in the buffer is a v3 message
  127. bool is_v3_message() {return v3MP::is_v3_msg(databuff, (int)bufflen);};
  128. #endif
  129. // return the validity of the message
  130. bool valid() const { return valid_flag;};
  131. // return raw data
  132. // check validity
  133. unsigned char *data() { return databuff; };
  134. // returns len
  135. // check validity
  136. unsigned long len() const { return bufflen; };
  137. protected:
  138. unsigned char databuff[MAX_SNMP_PACKET];
  139. unsigned int bufflen;
  140. bool valid_flag;
  141. };
  142. #ifdef SNMP_PP_NAMESPACE
  143. } // end of namespace Snmp_pp
  144. #endif
  145. #endif // _SNMPMSG