Dangerous SNMP
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
encoding.hpp
1 #pragma once
2 
3 #include "dangerous/snmp/logger.hpp"
4 #include "dangerous/snmp/types.hpp"
5 #include "dangerous/snmp/pdu.hpp"
6 
7 #include "berstream.hpp"
8 
9 #include "../asn1/asn1.hpp"
10 
11 #include <iostream>
12 
13 
14 namespace dangerous { namespace snmp { namespace encoding {
15 
16 /*
17  * ASN.1 native types.
18  */
19 
20 class INTEGER : public asn1::type::INTEGER< asn1::Class::UNIVERSAL, asn1::Content::PRIMITIVE, 2, int32_t > {
21 public:
22  static constexpr const char* NAME = "INTEGER";
23 };
24 
25 class OCTET_STRING : public asn1::type::OCTET_STRING< asn1::Class::UNIVERSAL, asn1::Content::PRIMITIVE, 4 > {
26 public:
27  static constexpr const char* NAME = "OCTET STRING";
28 };
29 
30 class NULL_TYPE : public asn1::type::NULL_TYPE< asn1::Class::UNIVERSAL, asn1::Content::PRIMITIVE, 5 > {
31 public:
32  static constexpr const char* NAME = "NULL";
33 };
34 
35 class OBJECT_IDENTIFIER : public asn1::type::OBJECT_IDENTIFIER< asn1::Class::UNIVERSAL, asn1::Content::PRIMITIVE, 6 > {
36 public:
37  static constexpr const char* NAME = "OBJECT IDENTIFIER";
38 };
39 
40 /*
41  * SNMP "application" types.
42  */
43 
44 class IPADDRESS : public asn1::type::OCTET_STRING< asn1::Class::APPLICATION, asn1::Content::PRIMITIVE, 0 > {
45 public:
46  static constexpr const char* NAME = "IpAddress";
47 };
48 
49 class COUNTER32 : public asn1::type::INTEGER< asn1::Class::APPLICATION, asn1::Content::PRIMITIVE, 1, uint32_t > {
50 public:
51  static constexpr const char* NAME = "Counter32";
52 };
53 
54 class GAUGE32 : public asn1::type::INTEGER< asn1::Class::APPLICATION, asn1::Content::PRIMITIVE, 2, uint32_t > {
55 public:
56  static constexpr const char* NAME = "Gauge32"; //< Also known as "Unsigned32".
57 };
58 
59 class TIMETICKS : public asn1::type::INTEGER< asn1::Class::APPLICATION, asn1::Content::PRIMITIVE, 3, uint32_t > {
60 public:
61  static constexpr const char* NAME = "TimeTicks";
62 };
63 
64 class OPAQUE : public asn1::type::OCTET_STRING< asn1::Class::APPLICATION, asn1::Content::PRIMITIVE, 4 > {
65 public:
66  static constexpr const char* NAME = "Opaque";
67 };
68 
69 // Note: There is no [APPLICATION 5].
70 
71 class COUNTER64 : public asn1::type::INTEGER< asn1::Class::APPLICATION, asn1::Content::PRIMITIVE, 6, uint64_t > {
72 public:
73  static constexpr const char* NAME = "Counter64";
74 };
75 
76 /*
77  * SNMPv2 VarBind value choices (failure).
78  */
79 
80 class NOSUCHOBJECT : public asn1::type::NULL_TYPE< asn1::Class::CONTEXT_SPECIFIC, asn1::Content::PRIMITIVE, 0 > {
81 public:
82  static constexpr const char* NAME = "noSuchObject";
83 };
84 
85 class NOSUCHINSTANCE : public asn1::type::NULL_TYPE< asn1::Class::CONTEXT_SPECIFIC, asn1::Content::PRIMITIVE, 1 > {
86 public:
87  static constexpr const char* NAME = "noSuchInstance";
88 };
89 
90 class ENDOFMIBVIEW : public asn1::type::NULL_TYPE< asn1::Class::CONTEXT_SPECIFIC, asn1::Content::PRIMITIVE, 2 > {
91 public:
92  static constexpr const char* NAME = "endOfMibView";
93 };
94 
98 class VARIANT {
99 public:
100  typedef Variant value_type;
101 
108  static unsigned int length( const Variant& variant ) {
109  switch( variant.type() ) {
110  /*
111  * ASN.1 native types.
112  */
114  return INTEGER::length( variant.get_int32_t() );
115  case Variant::SIMPLE_OID:
116  return OBJECT_IDENTIFIER::length( variant.get_oid() );
118  return OCTET_STRING::length( variant.get_string() );
120  return NULL_TYPE::length( NULL_TYPE::throwaway );
121 
122  /*
123  * SNMP "application" types.
124  */
126  return IPADDRESS::length( variant.get_string() );
128  return COUNTER32::length( variant.get_uint32_t() );
130  return GAUGE32::length( variant.get_uint32_t() );
132  return TIMETICKS::length( variant.get_uint32_t() );
134  return OPAQUE::length( variant.get_string() );
136  return COUNTER64::length( variant.get_uint32_t() );
137 
138  /*
139  * SNMPv2 VarBind value choices (failure).
140  */
142  return NOSUCHOBJECT::length( NOSUCHOBJECT::throwaway );
144  return NOSUCHINSTANCE::length( NOSUCHINSTANCE::throwaway );
146  return ENDOFMIBVIEW::length( ENDOFMIBVIEW::throwaway );
147 
148  default:
149  if( logger.system( Logger::ENCODING ) ) {
150  logger.out() << "Warning: Unknown variant type: " << (int)variant.type() << "; using null." << std::endl;
151  }
152  return NULL_TYPE::length( NULL_TYPE::throwaway );
153  }
154  }
155 };
156 
160 class VARBIND {
161 public:
163  static constexpr const char* NAME = "VarBind";
164 
168  static const int TYPE = asn1::helper::SEQUENCE::TYPE;
169 
171  typedef std::unique_ptr<VarBind> value_type;
172 
173  static unsigned int length( const value_type& varbind ) {
174  unsigned int size = 0;
175 
176  if( logger.system( Logger::ENCODING ) ) {
177  logger.out() << "VARBIND: length: OID part: " << asn1::encodedSize<OBJECT_IDENTIFIER>( varbind->oid ) << std::endl;
178  logger.out() << "VARBIND: length: VAR part: " << asn1::encodedSize<VARIANT>( varbind->value ) << std::endl;
179  }
180 
181  size += asn1::encodedSize<OBJECT_IDENTIFIER>( varbind->oid );
182  size += asn1::encodedSize<VARIANT>( varbind->value );
183 
184  return size;
185  }
186 
187  static bool write( const value_type& varbind, char* buffer, unsigned int bufferSize ) {
189  ByteStream byteStream;
190  byteStream.linkFrom( (char*)buffer, bufferSize, ByteStream::READ_WRITE ); //< TODO: Consider doing this in a "const" fashion.
191 
192  BerStream berStream( &byteStream );
193 
194  bool success = berStream.write<OBJECT_IDENTIFIER>( varbind->oid );
195  if( ! success ) {
196  return false;
197  }
198 
199  switch( varbind->value.type() ) {
200  /*
201  * ASN.1 native types.
202  */
204  success = berStream.write<INTEGER>( varbind->value.get_int32_t() );
205  break;
206  case Variant::SIMPLE_OID:
207  success = berStream.write<OBJECT_IDENTIFIER>( varbind->value.get_oid() );
208  break;
210  success = berStream.write<OCTET_STRING>( varbind->value.get_string() );
211  break;
213  success = berStream.write<NULL_TYPE>( NULL_TYPE::throwaway );
214  break;
215 
216  /*
217  * SNMP "application" types.
218  */
220  success = berStream.write<IPADDRESS>( varbind->value.get_string() );
221  break;
223  success = berStream.write<COUNTER32>( varbind->value.get_uint32_t() );
224  break;
226  success = berStream.write<GAUGE32>( varbind->value.get_uint32_t() );
227  break;
229  success = berStream.write<TIMETICKS>( varbind->value.get_uint32_t() );
230  break;
232  success = berStream.write<OPAQUE>( varbind->value.get_string() );
233  break;
235  success = berStream.write<COUNTER64>( varbind->value.get_uint64_t() );
236  break;
237 
238  /*
239  * SNMPv2 VarBind value choices (failure).
240  */
242  success = berStream.write<NOSUCHOBJECT>( NOSUCHOBJECT::throwaway );
243  break;
245  success = berStream.write<NOSUCHINSTANCE>( NOSUCHINSTANCE::throwaway );
246  break;
248  success = berStream.write<ENDOFMIBVIEW>( ENDOFMIBVIEW::throwaway );
249  break;
250 
251  default:
252  if( logger.system( Logger::ENCODING ) ) {
253  logger.out() << "Warning: Unknown varbind->value type: " << (int)varbind->value.type() << "; using null." << std::endl;
254  }
255  success = berStream.write<NULL_TYPE>( NULL_TYPE::throwaway );
256  break;
257  }
258  if( ! success ) {
259  return false;
260  }
261 
262  if( berStream.remainingWriteLength() > 0 ) {
263  if( logger.system( Logger::ENCODING ) ) {
264  logger.out() << "VARBIND: write: Somehow, there are " << berStream.remainingWriteLength() << " bytes left over." << std::endl;
265  logger.out() << "VARBIND: write: Original length: " << bufferSize << std::endl;
266  }
267  return false;
268  }
269 
270  return true;
271  }
272 
273  static bool read( value_type& varbind, char* buffer, unsigned int bufferSize ) {
274  // Since a "VarBind" is composed of two entries, we're going to
275  // set up a ByteStream to handle it.
276 
278  ByteStream byteStream;
279  byteStream.linkFrom( (char*)buffer, bufferSize, ByteStream::READ_ONLY ); //< TODO: Consider doing this in a "const" fashion.
280 
281  BerStream berStream( &byteStream );
282 
283  // Read the OID and its value.
284 
285  bool success = true;
286 
287  success = berStream.read<OBJECT_IDENTIFIER>( varbind->oid );
288  if( ! success ) {
289  return false;
290  }
291 
292  uint8_t currentType;
293  success = berStream.peekType( currentType );
294  if( ! success ) {
295  return false;
296  }
297 
298  switch( currentType ) {
299  /*
300  * ASN.1 native types.
301  */
302  case INTEGER::TYPE: {
303  int32_t value = 0;
304  success = berStream.read<INTEGER>( value );
305  varbind->value.set_int32_t( Variant::SIMPLE_INTEGER, value );
306  break;
307  }
308  case OCTET_STRING::TYPE: {
309  std::string value;
310  success = berStream.read<OCTET_STRING>( value );
311  varbind->value.set_string( Variant::SIMPLE_STRING, value );
312  break;
313  }
314  case OBJECT_IDENTIFIER::TYPE: {
315  NumericOid value;
316  success = berStream.read<OBJECT_IDENTIFIER>( value );
317  varbind->value.set_oid( Variant::SIMPLE_OID, value );
318  break;
319  }
320  case NULL_TYPE::TYPE:
321  varbind->value.set_null( Variant::SIMPLE_NULL );
322  success = berStream.read<NULL_TYPE>( NULL_TYPE::throwaway );
323  break;
324  /*
325  * SNMP "application" types.
326  */
327  case IPADDRESS::TYPE: {
328  std::string value;
329  success = berStream.read<IPADDRESS>( value );
330  varbind->value.set_string( Variant::APPLICATION_IPADDRESS, value );
331  break;
332  }
333  case COUNTER32::TYPE: {
334  uint32_t value = 0;
335  success = berStream.read<COUNTER32>( value );
336  varbind->value.set_uint32_t( Variant::APPLICATION_COUNTER32, value );
337  break;
338  }
339  case GAUGE32::TYPE: {
340  uint32_t value = 0;
341  success = berStream.read<GAUGE32>( value );
342  varbind->value.set_uint32_t( Variant::APPLICATION_GAUGE32, value );
343  break;
344  }
345  case TIMETICKS::TYPE: {
346  uint32_t value = 0;
347  success = berStream.read<TIMETICKS>( value );
348  varbind->value.set_uint32_t( Variant::APPLICATION_TIMETICKS, value );
349  break;
350  }
351  case OPAQUE::TYPE: {
352  std::string value;
353  success = berStream.read<OPAQUE>( value );
354  varbind->value.set_string( Variant::APPLICATION_OPAQUE, value );
355  break;
356  }
357  case COUNTER64::TYPE: {
358  uint64_t value = 0;
359  success = berStream.read<COUNTER64>( value );
360  varbind->value.set_uint64_t( Variant::APPLICATION_COUNTER64, value );
361  break;
362  }
363 
364  /*
365  * SNMPv2 VarBind value choices (failure).
366  */
367  case NOSUCHOBJECT::TYPE:
368  varbind->value.set_null( Variant::CONTEXT_NOSUCHOBJECT );
369  success = berStream.read<NOSUCHOBJECT>( NOSUCHOBJECT::throwaway );
370  break;
371  case NOSUCHINSTANCE::TYPE:
372  varbind->value.set_null( Variant::CONTEXT_NOSUCHINSTANCE );
373  success = berStream.read<NOSUCHINSTANCE>( NOSUCHINSTANCE::throwaway );
374  break;
375  case ENDOFMIBVIEW::TYPE:
376  varbind->value.set_null( Variant::CONTEXT_ENDOFMIBVIEW );
377  success = berStream.read<ENDOFMIBVIEW>( ENDOFMIBVIEW::throwaway );
378  break;
379 
380  default:
381  if( logger.system( Logger::DECODING ) ) {
382  logger.out() << "Unknown type: " << (int)currentType << std::endl;
383  }
384  success = false;
385  }
386  if( ! success ) {
387  return false;
388  }
389 
390  return true;
391  }
392 };
393 
399 class VARBINDLIST {
400 public:
402  static constexpr const char* NAME = "SEQUENCE OF VarBind";
403 
405  static const int TYPE = asn1::helper::SEQUENCE::TYPE;
406 
409 
410  static unsigned int length( const VarBindList& varbinds ) {
411  unsigned int size = 0;
412  for( const auto& varbind : varbinds ) {
413  size += asn1::encodedSize<VARBIND>( varbind );
414  }
415 
416  return size;
417  }
418 
419  static bool write( const VarBindList& varbinds, char* buffer, unsigned int bufferSize ) {
421  ByteStream byteStream;
422  byteStream.linkFrom( buffer, bufferSize, ByteStream::READ_WRITE );
423 
424  BerStream berStream( &byteStream );
425 
426  for( const auto& varbind : varbinds ) {
427  bool success = berStream.write<VARBIND>( varbind );
428  if( ! success ) {
429  return false;
430  }
431  }
432 
433  return true;
434  }
435 
436  static bool read( value_type& varbinds, const char* buffer, unsigned int bufferSize ) {
437  // Since a "SEQUENCE OF VarBind" is composed of multiple "VarBind" entries, we're going to
438  // set up a ByteStream to handle it.
439 
441  ByteStream byteStream;
442  byteStream.linkFrom( (char*)buffer, bufferSize, ByteStream::READ_ONLY ); //< TODO: Consider doing this in a "const" fashion.
443 
444  BerStream berStream( &byteStream );
445 
446  // Read each of the VarBinds.
447 
448  bool success = true;
449 
450  while( berStream.remainingReadLength() > 0 ) { //< TODO: Too much access? Add more?
451  std::unique_ptr<VarBind> varbind( new VarBind );
452  success = berStream.read<VARBIND>( varbind );
453  if( ! success ) {
454  return false;
455  }
456 
457  varbinds.push_back( std::move(varbind) );
458  }
459 
460  return true;
461  }
462 };
463 
464 template<int tag,ConfirmedClass::Type confirmedClass>
465 class GenericPDU {
466 public:
467  // Note: No "NAME" is specified, so this CANNOT be used for
468  // encoding or decoding types. You MUST create a class that
469  // references this one as a templated parent.
470 
481  static constexpr const int TYPE = 0xa0 | tag;
482 
484  typedef PDU value_type;
485 
487  static constexpr const ConfirmedClass::Type confirmed = confirmedClass;
488 
489  static unsigned int length( const value_type& pdu ) {
490  unsigned int size = 0;
491  size += asn1::encodedSize<INTEGER>( pdu.requestId );
492  size += asn1::encodedSize<INTEGER>( pdu.errorStatus );
493  size += asn1::encodedSize<INTEGER>( pdu.errorIndex );
494  size += asn1::encodedSize<VARBINDLIST>( pdu.varbinds );
495  return size;
496  }
497 
498  static bool write( const value_type& pdu, char* buffer, unsigned int bufferSize ) {
500  ByteStream byteStream;
501  byteStream.linkFrom( (char*)buffer, bufferSize, ByteStream::READ_WRITE ); //< TODO: Consider doing this in a "const" fashion.
502 
503  BerStream berStream( &byteStream );
504 
505  bool success = true;
506 
507  // Write the header.
508 
509  success = berStream.write<INTEGER>( pdu.requestId );
510  if( ! success ) {
511  return false;
512  }
513  success = berStream.write<INTEGER>( pdu.errorStatus );
514  if( ! success ) {
515  return false;
516  }
517  success = berStream.write<INTEGER>( pdu.errorIndex );
518  if( ! success ) {
519  return false;
520  }
521 
522  // Write the payload.
523 
524  success = berStream.write<VARBINDLIST>( pdu.varbinds );
525  if( ! success ) {
526  return false;
527  }
528 
529  return true;
530  }
531 
532  static bool read( value_type& pdu, const char* buffer, unsigned int bufferSize ) {
533  // Since a PDU is composed of multiple other entities, we're going to
534  // set up a ByteStream to handle it.
535 
537  ByteStream byteStream;
538  byteStream.linkFrom( (char*)buffer, bufferSize, ByteStream::READ_ONLY ); //< TODO: Consider doing this in a "const" fashion.
539 
540  BerStream berStream( &byteStream );
541 
542  // Read the header.
543 
544  bool success = true;
545 
546  success = berStream.read<INTEGER>( pdu.requestId );
547  if( ! success ) {
548  return false;
549  }
550  success = berStream.read<INTEGER>( pdu.errorStatus );
551  if( ! success ) {
552  return false;
553  }
554  success = berStream.read<INTEGER>( pdu.errorIndex );
555  if( ! success ) {
556  return false;
557  }
558 
559  // Read the payload.
560 
561  success = berStream.read<VARBINDLIST>( pdu.varbinds );
562  if( ! success ) {
563  return false;
564  }
565 
566  return true;
567  }
568 };
569 
573 class GetRequestPDU : public GenericPDU<0,ConfirmedClass::Confirmed> {
574 public:
575  static constexpr const char* NAME = "GetRequest-PDU";
576 };
577 
581 class GetNextRequestPDU : public GenericPDU<1,ConfirmedClass::Confirmed> {
582 public:
583  static constexpr const char* NAME = "GetNextRequest-PDU";
584 };
585 
589 class ResponsePDU : public GenericPDU<2,ConfirmedClass::Unconfirmed> {
590 public:
591  static constexpr const char* NAME = "Response-PDU";
592 };
593 
597 class SetRequestPDU : public GenericPDU<3,ConfirmedClass::Confirmed> {
598 public:
599  static constexpr const char* NAME = "SetRequest-PDU";
600 };
601 
602 // NOTE: Trap-PDU is tag "4"; see RFC-1157.
603 
604 // TODO: Technically, a #5 is a BulkPDU, but they are physically identical.
608 class GetBulkRequestPDU : public GenericPDU<5,ConfirmedClass::Confirmed> {
609 public:
610  static constexpr const char* NAME = "GetBulkRequest-PDU";
611 };
612 
616 class InformRequestPDU : public GenericPDU<6,ConfirmedClass::Confirmed> {
617 public:
618  static constexpr const char* NAME = "InformRequest-PDU";
619 };
620 
624 class SnmpV2TrapPDU : public GenericPDU<7,ConfirmedClass::Unconfirmed> {
625 public:
626  static constexpr const char* NAME = "SNMPv2-Trap-PDU";
627 };
628 
632 class ReportPDU : public GenericPDU<8,ConfirmedClass::Unconfirmed> {
633 public:
634  static constexpr const char* NAME = "Report-PDU";
635 };
636 
637 } } }
638 
Stored as v.oid.
Definition: variant.hpp:91
static constexpr const char * NAME
This is the name of this entity.
Definition: encoding.hpp:402
A SetRequest-PDU is a PDU with tag "3".
Definition: encoding.hpp:597
bool write(const typename EncodingClass::value_type &value)
This performs a full, logical write of a kind of encoded data.
Definition: berstream.hpp:207
Definition: encoding.hpp:80
static bool read(value_type &pdu, const char *buffer, unsigned int bufferSize)
Definition: encoding.hpp:532
A SNMPv2-Trap-PDU is a PDU with tag "7".
Definition: encoding.hpp:624
bool system(System system)
This returns the logging status for the given system.
Definition: logger.hpp:47
Functionally SIMPLE_NULL.
Definition: variant.hpp:101
Definition: encoding.hpp:44
This class allows for the encoding and decoding of null values.
Definition: asn1.hpp:356
A PDU represents an SNMP Protocol Data Unit (PDU).
Definition: pdu.hpp:56
std::ostream & out()
This returns the output stream for the Logger.
Definition: logger.hpp:77
Functionally SIMPLE_NULL.
Definition: variant.hpp:99
static bool write(const value_type &pdu, char *buffer, unsigned int bufferSize)
Definition: encoding.hpp:498
A ByteStream is an object that is basically a big wrapper around a character buffer.
Definition: bytestream.hpp:30
Definition: encoding.hpp:49
VarBindList value_type
The value type that this class operates on is "VarBindList".
Definition: encoding.hpp:408
static const int TYPE
A VarBind list is a sequence:
Definition: encoding.hpp:405
A Variant defines an arbitrary value (within the scope of SNMP).
Definition: variant.hpp:78
PDU value_type
The value type that this class operates on is "PDU".
Definition: encoding.hpp:484
Definition: encoding.hpp:20
Stored as v.u64.
Definition: variant.hpp:98
Definition: encoding.hpp:71
Functionally SIMPLE_NULL.
Definition: variant.hpp:100
This defines a variable binding, or "varbind".
Definition: types.hpp:77
A InformRequest-PDU is a PDU with tag "6".
Definition: encoding.hpp:616
Stored as v.s.
Definition: variant.hpp:97
unsigned int remainingReadLength() const
This returns the number of bytes remaining in the stream.
Definition: berstream.hpp:32
Not stored.
Definition: variant.hpp:92
static bool write(const VarBindList &varbinds, char *buffer, unsigned int bufferSize)
Definition: encoding.hpp:419
A GetRequest-PDU is a PDU with tag "0".
Definition: encoding.hpp:573
Definition: encoding.hpp:465
Definition: asn1.hpp:148
Definition: encoding.hpp:64
Stored as v.u32.
Definition: variant.hpp:96
Stored as v.u32.
Definition: variant.hpp:95
Only read operations may be performed.
Definition: bytestream.hpp:38
A BerStream represents a BER-encoded stream of data.
Definition: berstream.hpp:16
A Report-PDU is a PDU with tag "8".
Definition: encoding.hpp:632
Both read and write operations may be performed.
Definition: bytestream.hpp:40
Definition: encoding.hpp:59
int errorStatus
This is the ErrorStatus for the PDU.
Definition: pdu.hpp:116
uint32_t get_uint32_t() const
This returns the 32-bit unsigned integer value of the Variant.
Definition: variant.hpp:450
static constexpr const char * NAME
This is the name of this entity.
Definition: encoding.hpp:163
A NumericOid represents an "true" OID; that is, one identified by a series of integers (as opposed to...
Definition: numericoid.hpp:22
Stored as v.i32.
Definition: variant.hpp:89
Definition: encoding.hpp:54
int errorIndex
This is the ErrorIndex for the PDU.
Definition: pdu.hpp:124
static bool write(const value_type &varbind, char *buffer, unsigned int bufferSize)
Definition: encoding.hpp:187
static unsigned int length(const value_type &value)
Definition: asn1.hpp:153
std::unique_ptr< VarBind > value_type
This class operates on unique VarBind pointers.
Definition: encoding.hpp:171
static constexpr const int TYPE
This is the type of the PDU.
Definition: encoding.hpp:481
This class allows for the encoding and decoding of VarBind pointers.
Definition: encoding.hpp:160
bool peekType(uint8_t &type)
This reads an ASN.1 type from the BerStream.
Logger logger
We will expose a global Logger instance.
static unsigned int length(const Variant &variant)
The byte size of a null value is always 2:
Definition: encoding.hpp:108
static constexpr const ConfirmedClass::Type confirmed
This is the "confirmed class" of the PDU.
Definition: encoding.hpp:487
This class allows for the encoding and decoding of VarBind lists.
Definition: encoding.hpp:399
Logging related to decoding messages.
Definition: logger.hpp:21
int32_t get_int32_t() const
This returns the 32-bit signed integer value of the Variant.
Definition: variant.hpp:417
A Response-PDU is a PDU with tag "2".
Definition: encoding.hpp:589
Definition: encoding.hpp:30
Type
A Type represents one of the two defined values for the "confirmed class" of a PDU.
Definition: types.hpp:65
Type type() const
This returns the type of the Variant.
Definition: variant.hpp:167
This class allows for the encoding and decoding of an arbitrary value.
Definition: encoding.hpp:98
unsigned int remainingWriteLength() const
This returns the number of bytes remaining in the stream.
Definition: berstream.hpp:38
void linkFrom(char *bytes, unsigned int bytesSize, Access access)
This links the bytes given to the ByteStream's character buffer.
Definition: encoding.hpp:90
A GetBulkRequest-PDU is a PDU with tag "5".
Definition: encoding.hpp:608
Definition: encoding.hpp:25
bool read(typename EncodingClass::value_type &value)
This performs a full, logical read of a kind of encoded data.
Definition: berstream.hpp:145
static bool read(value_type &varbind, char *buffer, unsigned int bufferSize)
Definition: encoding.hpp:273
const NumericOid & get_oid() const
This returns the OID value of the Variant.
Definition: variant.hpp:549
Stored as v.s.
Definition: variant.hpp:90
static bool read(value_type &varbinds, const char *buffer, unsigned int bufferSize)
Definition: encoding.hpp:436
Stored as v.s.
Definition: variant.hpp:93
int requestId
This is the RequestID for the PDU.
Definition: pdu.hpp:109
std::vector< std::unique_ptr< VarBind > > VarBindList
This defines a list of varbinds.
Definition: types.hpp:116
const std::string & get_string() const
This returns the string value of the Variant.
Definition: variant.hpp:516
VarBindList varbinds
This is the list of VarBinds in the PDU.
Definition: pdu.hpp:127
Stored as v.u32.
Definition: variant.hpp:94
static const int TYPE
A VarBind is encoded as a sequence with two children:
Definition: encoding.hpp:168
A GetNextRequest-PDU is a PDU with tag "1".
Definition: encoding.hpp:581