]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/include/snmp_pp/snmpmsg.h
Initial adding
[ssmd.git] / 3rdparty / snmp++ / include / snmp_pp / snmpmsg.h
1 /*_############################################################################
2   _## 
3   _##  snmpmsg.h  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 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, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 /*===================================================================
30
31   Copyright (c) 1999
32   Hewlett-Packard Company
33
34   ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
35   Permission to use, copy, modify, distribute and/or sell this software
36   and/or its documentation is hereby granted without fee. User agrees
37   to display the above copyright notice and this license notice in all
38   copies of the software and any documentation of the software. User
39   agrees to assume all liability for the use of the software; Hewlett-Packard
40   makes no representations about the suitability of this software for any
41   purpose. It is provided "AS-IS without warranty of any kind,either express
42   or implied. User hereby grants a royalty-free license to any and all
43   derivatives based upon this software code base.
44
45
46   SNMP++ S N M P M E S S A G E . H
47
48   SNMPMESSAGE CLASS DEFINITION
49
50   DESIGN + AUTHOR:  Peter E Mellquist
51
52   DESCRIPTION:
53   ASN.1 encoding / decoding class
54                 
55 =====================================================================*/
56 // $Id: snmpmsg.h 1541 2009-05-29 11:29:22Z katz $
57
58 #ifndef _SNMPMSG
59 #define _SNMPMSG
60
61 #include "snmp_pp/config_snmp_pp.h"
62
63 #include "snmp_pp/smival.h"
64 #include "snmp_pp/pdu.h"
65 #include "snmp_pp/target.h"
66 #include "snmp_pp/asn1.h"
67 #include "snmp_pp/mp_v3.h"
68
69 #ifdef SNMP_PP_NAMESPACE
70 namespace Snmp_pp {
71 #endif
72
73 DLLOPT void freeSmivalDescriptor( SmiVALUE* );
74 DLLOPT int convertVbToSmival( const Vb&, SmiVALUE* );
75
76 #define SNMP_MSG_OID_SYSUPTIME "1.3.6.1.2.1.1.3.0"
77 #define SNMP_MSG_OID_TRAPID    "1.3.6.1.6.3.1.1.4.1.0"
78
79 class Snmp;
80
81 // SnmpMessage Class
82 class DLLOPT SnmpMessage
83 {
84  public:
85
86   // construct a SnmpMessage object
87   SnmpMessage() : bufflen(MAX_SNMP_PACKET), valid_flag(false) {};
88         // load up using a Pdu, community and SNMP version
89         // performs ASN.1 serialization
90         // result status returned
91  private:
92         int load( const Pdu &pdu,                // Pdu to serialize
93                   const OctetStr &community,     // community name to use
94                   const snmp_version version,    // SNMP version, v1 or v2
95                   const OctetStr *engine_id,     // optional v3
96                   const OctetStr *security_name, // optional v3
97                   const int security_model);     // optional v3
98  public:
99         int load( const Pdu &pdu,              // Pdu to serialize
100                   const OctetStr &community,   // community name to use
101                   const snmp_version version)  // SNMP version, v1 or v2
102           { return load(pdu, community, version, 0, 0, 0); };
103
104         // load up message using ASN.1 data stream
105         // status is returned
106         int load( unsigned char *data,         // data to be loaded
107                   unsigned long len);          // len of data to be loaded
108
109         // unload ( unserialize ) into SNMP++ Pdu, community and version
110         // status is returned
111  private:
112         int unload( Pdu &pdu,                    // Pdu returned
113                     OctetStr &community,         // community name
114                     snmp_version &version,       // version
115                     OctetStr *engine_id,         // optional v3
116                     OctetStr *security_name, // optional v3
117                     long int *security_model,
118                     UdpAddress *from_addr,
119                     Snmp *snmp_session);
120  public:
121         int unload( Pdu &pdu,                    // Pdu returned
122                     OctetStr &community,         // community name
123                     snmp_version &version)       // version
124           { return unload(pdu, community, version, 0, 0, 0, 0, 0); };
125
126
127 #ifdef _SNMPv3
128         int loadv3( const Pdu &pdu,               // Pdu to serialize
129                     const OctetStr &engine_id,    // engine_id to use
130                     const OctetStr &sec_name,     // securit_name to use
131                     const int sec_model,          // security_model to use
132                     const snmp_version version)   // SNMP version, v3
133         { return load(pdu, "", version, &engine_id, &sec_name, sec_model); }
134
135         int unloadv3( Pdu &pdu,                  // Pdu returned
136                       snmp_version &version,     // version
137                       OctetStr &engine_id,       // optional v3
138                       OctetStr &security_name,   // optional v3
139                       long int &security_model,
140                       UdpAddress &from_addr,
141                       Snmp &snmp_session);
142
143         // returns TRUE if the message in the buffer is a v3 message
144         bool is_v3_message() {return v3MP::is_v3_msg(databuff, (int)bufflen);};
145
146 #endif
147
148         // return the validity of the message
149         bool valid() const         { return valid_flag;};
150
151         // return raw data
152         // check validity
153         unsigned char *data()     { return databuff; };
154
155         // returns len
156         // check validity
157         unsigned long len() const { return bufflen; };
158
159 protected:
160
161         unsigned char databuff[MAX_SNMP_PACKET];
162         unsigned int bufflen;
163         bool valid_flag;
164 };
165
166 #ifdef SNMP_PP_NAMESPACE
167 } // end of namespace Snmp_pp
168 #endif 
169
170 #endif  // _SNMPMSG