1 /*_############################################################################
6 _## -----------------------------------------------
7 _## Copyright (c) 2001-2010 Jochen Katz, Frank Fock
9 _## This software is based on SNMP++2.6 from Hewlett Packard:
11 _## Copyright (c) 1996
12 _## Hewlett-Packard Company
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.
26 _## Stuttgart, Germany, Thu Sep 2 00:07:47 CEST 2010
28 _##########################################################################*/
29 /*===================================================================
32 Hewlett-Packard Company
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.
46 SNMP++ S N M P M E S S A G E . H
48 SNMPMESSAGE CLASS DEFINITION
50 DESIGN + AUTHOR: Peter E Mellquist
53 ASN.1 encoding / decoding class
55 =====================================================================*/
56 // $Id: snmpmsg.h 1541 2009-05-29 11:29:22Z katz $
61 #include "snmp_pp/config_snmp_pp.h"
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"
69 #ifdef SNMP_PP_NAMESPACE
73 DLLOPT void freeSmivalDescriptor( SmiVALUE* );
74 DLLOPT int convertVbToSmival( const Vb&, SmiVALUE* );
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"
82 class DLLOPT SnmpMessage
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
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
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); };
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
109 // unload ( unserialize ) into SNMP++ Pdu, community and version
110 // status is returned
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,
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); };
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); }
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,
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);};
148 // return the validity of the message
149 bool valid() const { return valid_flag;};
153 unsigned char *data() { return databuff; };
157 unsigned long len() const { return bufflen; };
161 unsigned char databuff[MAX_SNMP_PACKET];
162 unsigned int bufflen;
166 #ifdef SNMP_PP_NAMESPACE
167 } // end of namespace Snmp_pp