BER.pm

filter: Statementstmt 38.4% 155 / 403 Branchbran 27.3% 59 / 216 Conditioncond 7.8% 7 / 89 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 39.7% 31 / 78 Podpod 27.4% 20 / 73 totaltotal 30.1% 272 / 903 CC 141 SCAR 44.8
CC
141
Cov
31%
pretty_print
342.0
decode_by_template_2
192.5
pretty_generic_sequence
182.0
CRAP 88.6
« SNMP_util.pm ↑ Summary SNMP_Session.pm »
1 ### -*- mode: Perl -*-
2 ######################################################################
3 ### BER (Basic Encoding Rules) encoding and decoding.
4 ######################################################################
5 ### Copyright (c) 1995-2009, Simon Leinen.
6 ###
7 ### This program is free software; you can redistribute it under the
8 ### "Artistic License 2.0" included in this distribution
9 ### (file "Artistic").
10 ######################################################################
11 ### This module implements encoding and decoding of ASN.1-based data
12 ### structures using the Basic Encoding Rules (BER). Only the subset
13 ### necessary for SNMP is implemented.
14 ######################################################################
15 ### Create by: See AUTHORS below
16 ######################################################################
17  
18 package BER;
19  
20 =head1 NAME
21  
22 BER - Basic Encoding Rules (BER) of Abstract Syntax Notation One (ASN.1)
23  
24 =head1 SYNOPSIS
25  
26 use BER;
27 $encoded = encode_sequence (encode_int (123), encode_string ("foo"));
28 ($i, $s) = decode_by_template ($encoded, "%{%i%s");
29 # $i will now be 123, $s the string "foo".
30  
31 =head1 DESCRIPTION
32  
33 This is a simple library to encode and decode data using the Basic
34 Encoding Rules (BER) of Abstract Syntax Notation One (ASN.1). It does
35 not claim to be a complete implementation of the standard, but
36 implements enough of the BER standard to encode and decode SNMP
37 messages.
38  
39 =cut
40  
41 1 require 5.002;
42  
43 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use vars qw(@ISA @EXPORT $VERSION $pretty_print_timeticks
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 %pretty_printer %default_printer $errmsg);
46 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 1 $VERSION = '1.16';
50  
51 1 @ISA = qw(Exporter);
52  
53 1 @EXPORT = qw(context_flag constructor_flag
54 encode_int encode_int_0 encode_null encode_oid
55 encode_sequence encode_tagged_sequence
56 encode_string encode_ip_address encode_timeticks
57 encode_uinteger32 encode_counter32 encode_counter64
58 encode_gauge32
59 decode_sequence decode_by_template
60 pretty_print pretty_print_timeticks
61 hex_string hex_string_of_type
62 encoded_oid_prefix_p errmsg
63 register_pretty_printer unregister_pretty_printer);
64  
65 =head1 VARIABLES
66  
67 =cut
68  
69 =head2 $pretty_print_timeticks (default: 1)
70  
71 If non-zero (the default), C<pretty_print> will convert TimeTicks to
72 "human readable" strings containing days, hours, minutes and seconds.
73  
74 If the variable is zero, C<pretty_print> will simply return an
75 unsigned integer representing hundredths of seconds. If you prefer
76 this, bind C<$pretty_print_timeticks> to zero.
77  
78 =cut
79  
80 1 $pretty_print_timeticks = 1;
81  
82 =head2 $errmsg - error message from last failed operation.
83  
84 When they encounter errors, the routines in this module will generally
85 return C<undef>) and leave an informative error message in
86 C<$errmsg>).
87  
88 =cut
89  
90 ### Prototypes
91 sub encode_header ($$);
92 sub encode_int_0 ();
93 sub encode_int ($);
94 sub encode_oid (@);
95 sub encode_null ();
96 sub encode_sequence (@);
97 sub encode_tagged_sequence ($@);
98 sub encode_string ($);
99 sub encode_ip_address ($);
100 sub encode_timeticks ($);
101 sub pretty_print ($);
102 sub pretty_using_decoder ($$);
103 sub pretty_string ($);
104 sub pretty_intlike ($);
105 sub pretty_unsignedlike ($);
106 sub pretty_oid ($);
107 sub pretty_uptime ($);
108 sub pretty_uptime_value ($);
109 sub pretty_ip_address ($);
110 sub pretty_generic_sequence ($);
111 sub register_pretty_printer ($);
112 sub unregister_pretty_printer ($);
113 sub hex_string ($);
114 sub hex_string_of_type ($$);
115 sub decode_oid ($);
116 sub decode_by_template;
117 sub decode_by_template_2;
118 sub decode_sequence ($);
119 sub decode_int ($);
120 sub decode_intlike ($);
121 sub decode_unsignedlike ($);
122 sub decode_intlike_s ($$);
123 sub decode_string ($);
124 sub decode_length ($@);
125 sub encoded_oid_prefix_p ($$);
126 sub decode_subid ($$$);
127 sub decode_generic_tlv ($);
128 sub error (@);
129 sub template_error ($$$);
130  
131 0 ▶sub version () { $VERSION; }
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
132  
133 =head1 METHODS
134 =cut
135  
136 ### Flags for different types of tags
137  
138 0 ▶sub universal_flag { 0x00 }
Subroutine universal_flag: not called CC=1 SCAR=6.9
Pod undocumented
139 5 ▶sub application_flag { 0x40 }
Subroutine application_flag: called CC=1 SCAR=0.0
Pod undocumented
140 0 ▶sub context_flag { 0x80 }
Subroutine context_flag: not called CC=1 SCAR=6.9
Pod undocumented
141 0 ▶sub private_flag { 0xc0 }
Subroutine private_flag: not called CC=1 SCAR=6.9
Pod undocumented
142  
143 0 ▶sub primitive_flag { 0x00 }
Subroutine primitive_flag: not called CC=1 SCAR=6.9
Pod undocumented
144 6 ▶sub constructor_flag { 0x20 }
Subroutine constructor_flag: called CC=1 SCAR=0.0
Pod undocumented
145  
146 ### Universal tags
147  
148 0 ▶sub boolean_tag { 0x01 }
Subroutine boolean_tag: not called CC=1 SCAR=6.9
Pod undocumented
149 13 ▶sub int_tag { 0x02 }
Subroutine int_tag: called CC=1 SCAR=0.0
Pod undocumented
150 0 ▶sub bit_string_tag { 0x03 }
Subroutine bit_string_tag: not called CC=1 SCAR=6.9
Pod undocumented
151 7 ▶sub octet_string_tag { 0x04 }
Subroutine octet_string_tag: called CC=1 SCAR=0.0
Pod undocumented
152 0 ▶sub null_tag { 0x05 }
Subroutine null_tag: not called CC=1 SCAR=6.9
Pod undocumented
153 2 ▶sub object_id_tag { 0x06 }
Subroutine object_id_tag: called CC=1 SCAR=0.0
Pod undocumented
154 5 ▶sub sequence_tag { 0x10 }
Subroutine sequence_tag: called CC=1 SCAR=0.0
Pod undocumented
155 0 ▶sub set_tag { 0x11 }
Subroutine set_tag: not called CC=1 SCAR=6.9
Pod undocumented
156 0 ▶sub uptime_tag { 0x43 }
Subroutine uptime_tag: not called CC=1 SCAR=6.9
Pod undocumented
157  
158 ### Flag for length octet announcing multi-byte length field
159  
160 23 ▶sub long_length { 0x80 }
Subroutine long_length: called CC=1 SCAR=0.0
Pod undocumented
161  
162 ### SNMP specific tags
163  
164 1 ▶sub snmp_ip_address_tag { 0x00 | application_flag () }
Subroutine snmp_ip_address_tag: called CC=1 SCAR=0.0
Pod undocumented
165 1 ▶sub snmp_counter32_tag { 0x01 | application_flag () }
Subroutine snmp_counter32_tag: called CC=1 SCAR=0.0
Pod undocumented
166 1 ▶sub snmp_gauge32_tag { 0x02 | application_flag () }
Subroutine snmp_gauge32_tag: called CC=1 SCAR=0.0
Pod undocumented
167 0 ▶sub snmp_timeticks_tag { 0x03 | application_flag () }
Subroutine snmp_timeticks_tag: not called CC=1 SCAR=6.9
Pod undocumented
168 0 ▶sub snmp_opaque_tag { 0x04 | application_flag () }
Subroutine snmp_opaque_tag: not called CC=1 SCAR=6.9
Pod undocumented
169 0 ▶sub snmp_nsap_address_tag { 0x05 | application_flag () }
Subroutine snmp_nsap_address_tag: not called CC=1 SCAR=6.9
Pod undocumented
170 1 ▶sub snmp_counter64_tag { 0x06 | application_flag () }
Subroutine snmp_counter64_tag: called CC=1 SCAR=0.0
Pod undocumented
171 1 ▶sub snmp_uinteger32_tag { 0x07 | application_flag () }
Subroutine snmp_uinteger32_tag: called CC=1 SCAR=0.0
Pod undocumented
172  
173 ## Error codes (SNMPv2 and later)
174 ##
175 0 ▶sub snmp_nosuchobject { context_flag () | 0x00 }
Subroutine snmp_nosuchobject: not called CC=1 SCAR=6.9
Pod undocumented
176 0 ▶sub snmp_nosuchinstance { context_flag () | 0x01 }
Subroutine snmp_nosuchinstance: not called CC=1 SCAR=6.9
Pod undocumented
177 0 ▶sub snmp_endofmibview { context_flag () | 0x02 }
Subroutine snmp_endofmibview: not called CC=1 SCAR=6.9
Pod undocumented
178  
179 ### pretty-printer initialization code. Create a hash with
180 ### the most common types of pretty-printer routines.
181  
182 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
183 1 $default_printer{int_tag()} = \&pretty_intlike;
184 1 $default_printer{snmp_counter32_tag()} = \&pretty_unsignedlike;
185 1 $default_printer{snmp_gauge32_tag()} = \&pretty_unsignedlike;
186 1 $default_printer{snmp_counter64_tag()} = \&pretty_unsignedlike;
187 1 $default_printer{snmp_uinteger32_tag()} = \&pretty_unsignedlike;
188 1 $default_printer{octet_string_tag()} = \&pretty_string;
189 1 $default_printer{object_id_tag()} = \&pretty_oid;
190 1 $default_printer{snmp_ip_address_tag()} = \&pretty_ip_address;
191  
192 1 %pretty_printer = %default_printer;
193 }
194  
195 #### Encoding
196  
197 3 ▶sub encode_header ($$) {
Subroutine encode_header: called CC=4 SCAR=23.2
Pod undocumented
198 3 my ($type,$length) = @_;
199 3 ▶ return pack ("CC", $type, $length) if $length < 128;
Branch: 1 branch
BranchTrueFalseTotal
if $length < 128 3 0 3
200 0 ▶ return pack ("CCC", $type, long_length | 1, $length) if $length < 256;
Branch: 1 branch
BranchTrueFalseTotal
if $length < 256 0 0 0
201 0 ▶ return pack ("CCn", $type, long_length | 2, $length) if $length < 65536;
Branch: 1 branch
BranchTrueFalseTotal
if $length < 65536 0 0 0
202 0 return error ("Cannot encode length $length yet");
203 }
204  
205 =head2 encode_int_0() - encode the integer 0.
206  
207 This is functionally identical to C<encode_int(0)>.
208  
209 =cut
210  
211 0 ▶sub encode_int_0 () {
Subroutine encode_int_0: not called CC=1 SCAR=6.9
Pod documented
212 0 return pack ("CCC", 2, 1, 0);
213 }
214  
215 =head2 encode_int() - encode an integer using the generic
216 "integer" type tag.
217  
218 =cut
219  
220 1 ▶sub encode_int ($) {
Subroutine encode_int: called CC=1 SCAR=0.0
Pod documented
221 1 return encode_intlike ($_[0], int_tag);
222 }
223  
224 =head2 encode_uinteger32() - encode an integer using the SNMP
225 UInteger32 tag.
226  
227 =cut
228  
229 0 ▶sub encode_uinteger32 ($) {
Subroutine encode_uinteger32: not called CC=1 SCAR=6.9
Pod documented
230 0 return encode_intlike ($_[0], snmp_uinteger32_tag);
231 }
232  
233 =head2 encode_counter32() - encode an integer using the SNMP
234 Counter32 tag.
235  
236 =cut
237  
238 0 ▶sub encode_counter32 ($) {
Subroutine encode_counter32: not called CC=1 SCAR=6.9
Pod documented
239 0 return encode_intlike ($_[0], snmp_counter32_tag);
240 }
241  
242 =head2 encode_counter64() - encode an integer using the SNMP
243 Counter64 tag.
244  
245 =cut
246  
247 0 ▶sub encode_counter64 ($) {
Subroutine encode_counter64: not called CC=1 SCAR=6.9
Pod documented
248 0 return encode_intlike ($_[0], snmp_counter64_tag);
249 }
250  
251 =head2 encode_gauge32() - encode an integer using the SNMP Gauge32
252 tag.
253  
254 =cut
255  
256 0 ▶sub encode_gauge32 ($) {
Subroutine encode_gauge32: not called CC=1 SCAR=6.9
Pod documented
257 0 return encode_intlike ($_[0], snmp_gauge32_tag);
258 }
259  
260 ### encode_intlike ($int, $tag)
261 ###
262 ### Generic function to BER-encode an arbitrary integer using a given
263 ### tag. This function can handle large integers. It doesn't check
264 ### whether the integer is in a suitable range for the given type tag
265 ### - that is expected to be done by the caller.
266 ###
267 1 ▶sub encode_intlike ($$) {
Subroutine encode_intlike: called CC=8 SCAR=30.2
Pod undocumented
268 1 my ($int, $tag)=@_;
269 1 my ($sign, $val, @vals);
270 1 ▶ $sign = ($int >= 0) ? 0 : 0xff;
Branch: 1 branch
BranchTrueFalseTotal
$int >= 0 ? : 1 0 1
271 1 ▶ if (ref $int && $int->isa ("Math::BigInt")) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $int and $int->isa('Math::BigInt')) { } 0 1 1
Condition33%1/3
ref $int and $int->isa("Math::BigInt")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $int and $int->isa("Math::BigInt")
ref $int $int->isa("Math::BigInt")
Truth table33%1/3
A and B
A= ref $intB= $int->isa("Math::BigInt")
ABresult
0X0
100
111
272 0 for(;;) {
273 0 $val = $int->copy()->bmod (256);
274 0 unshift(@vals, $val);
275 0 ▶ return encode_header ($tag, $#vals + 1).pack ("C*", @vals)
Branch: 1 branch
BranchTrueFalseTotal
if $int >= -128 and $int < 128 0 0 0
Condition0%0/3
$int >= -128 and $int < 128
!ll&&!rl&&r
000
MC/DC0%0/2
$int >= -128 and $int < 128
$int >= -128 $int < 128
Truth table0%0/3
A and B
A= $int >= -128B= $int < 128
ABresult
0X0
100
111
276 if ($int >= -128 && $int < 128);
277 0 $int->bsub ($sign)->bdiv (256);
278 }
279 } else {
280 1 for(;;) {
281 1 $val = $int & 0xff;
282 1 unshift(@vals, $val);
283 1 ▶ return encode_header ($tag, $#vals + 1).pack ("C*", @vals)
Branch: 1 branch
BranchTrueFalseTotal
if $int >= -128 and $int < 128 1 0 1
Condition33%1/3
$int >= -128 and $int < 128
!ll&&!rl&&r
001
MC/DC0%0/2
$int >= -128 and $int < 128
$int >= -128 $int < 128
Truth table33%1/3
A and B
A= $int >= -128B= $int < 128
ABresult
0X0
100
111
284 if ($int >= -128 && $int < 128);
285 0 $int -= $sign, $int = int($int / 256);
286 }
287 }
288 }
289  
290 =head2 encode_oid() - encode an object ID, passed as a list of
291 sub-IDs.
292  
293 $encoded = encode_oid (1,3,6,1,...);
294 =cut
295  
296 1 ▶sub encode_oid (@) {
Subroutine encode_oid: called CC=16 SCAR=43.3
Pod documented
297 1 my @oid = @_;
298 1 my ($result,$subid);
299  
300 1 $result = '';
301 ## Ignore leading empty sub-ID. The favourite reason for
302 ## those to occur is that people cut&paste numeric OIDs from
303 ## CMU/UCD SNMP including the leading dot.
304 1 ▶ shift @oid if $oid[0] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $oid[0] eq "" 0 1 1
305  
306 1 ▶ return error ("Object ID too short: ", join('.',@oid))
Branch: 1 branch
BranchTrueFalseTotal
if $#oid < 1 0 1 1
307 if $#oid < 1;
308 ## The first two subids in an Object ID are encoded as a single
309 ## byte in BER, according to a funny convention. This poses
310 ## restrictions on the ranges of those subids. In the past, I
311 ## didn't check for those. But since so many people try to use
312 ## OIDs in CMU/UCD SNMP's format and leave out the mib-2 or
313 ## enterprises prefix, I introduced this check to catch those
314 ## errors.
315 ##
316 1 ▶ return error ("first subid too big in Object ID ", join('.',@oid))
Branch: 1 branch
BranchTrueFalseTotal
if $oid[0] > 2 0 1 1
317 if $oid[0] > 2;
318 1 $result = shift (@oid) * 40;
319 1 $result += shift @oid;
320 1 ▶ return error ("second subid too big in Object ID ", join('.',@oid))
Branch: 1 branch
BranchTrueFalseTotal
if $result > 255 0 1 1
321 if $result > 255;
322 1 $result = pack ("C", $result);
323 1 foreach $subid (@oid) {
324 2 ▶ if ( ($subid>=0) && ($subid<128) ){ #7 bits long subid
Branch: 5 branches
BranchTrueFalseTotal
if ($subid >= 0 and $subid < 128) { } 2 0 2
elsif ($subid >= 128 and $subid < 16384) { } 0 0 0
elsif ($subid >= 16384 and $subid < 2097152) { } 0 0 0
elsif ($subid >= 2097152 and $subid < 268435456) { } 0 0 0
elsif ($subid >= 268435456 and $subid < 4294967296) { } 0 0 0
Condition33%1/3
$subid >= 0 and $subid < 128
!ll&&!rl&&r
002
MC/DC0%0/2
$subid >= 0 and $subid < 128
$subid >= 0 $subid < 128
Truth table33%1/3
A and B
A= $subid >= 0B= $subid < 128
ABresult
0X0
100
111
325 2 $result .= pack ("C", $subid);
326 ▶ } elsif ( ($subid>=128) && ($subid<16384) ){ #14 bits long subid
Condition0%0/3
$subid >= 128 and $subid < 16384
!ll&&!rl&&r
000
MC/DC0%0/2
$subid >= 128 and $subid < 16384
$subid >= 128 $subid < 16384
Truth table0%0/3
A and B
A= $subid >= 128B= $subid < 16384
ABresult
0X0
100
111
327 0 $result .= pack ("CC", 0x80 | $subid >> 7, $subid & 0x7f);
328 }
329 ▶ elsif ( ($subid>=16384) && ($subid<2097152) ) {#21 bits long subid
Condition0%0/3
$subid >= 16384 and $subid < 2097152
!ll&&!rl&&r
000
MC/DC0%0/2
$subid >= 16384 and $subid < 2097152
$subid >= 16384 $subid < 2097152
Truth table0%0/3
A and B
A= $subid >= 16384B= $subid < 2097152
ABresult
0X0
100
111
330 0 $result .= pack ("CCC",
331 0x80 | (($subid>>14) & 0x7f),
332 0x80 | (($subid>>7) & 0x7f),
333 $subid & 0x7f);
334 ▶ } elsif ( ($subid>=2097152) && ($subid<268435456) ){ #28 bits long subid
Condition0%0/3
$subid >= 2097152 and $subid < 268435456
!ll&&!rl&&r
000
MC/DC0%0/2
$subid >= 2097152 and $subid < 268435456
$subid >= 2097152 $subid < 268435456
Truth table0%0/3
A and B
A= $subid >= 2097152B= $subid < 268435456
ABresult
0X0
100
111
335 0 $result .= pack ("CCCC",
336 0x80 | (($subid>>21) & 0x7f),
337 0x80 | (($subid>>14) & 0x7f),
338 0x80 | (($subid>>7) & 0x7f),
339 $subid & 0x7f);
340 ▶ } elsif ( ($subid>=268435456) && ($subid<4294967296) ){ #32 bits long subid
Condition0%0/3
$subid >= 268435456 and $subid < 4294967296
!ll&&!rl&&r
000
MC/DC0%0/2
$subid >= 268435456 and $subid < 4294967296
$subid >= 268435456 $subid < 4294967296
Truth table0%0/3
A and B
A= $subid >= 268435456B= $subid < 4294967296
ABresult
0X0
100
111
341 0 $result .= pack ("CCCCC",
342 0x80 | (($subid>>28) & 0x0f), #mask the bits beyond 32
343 0x80 | (($subid>>21) & 0x7f),
344 0x80 | (($subid>>14) & 0x7f),
345 0x80 | (($subid>>7) & 0x7f),
346 $subid & 0x7f);
347 } else {
348 0 return error ("Cannot encode subid $subid");
349 }
350 }
351 1 encode_header (object_id_tag, length $result).$result;
352 }
353  
354 =head2 encode_null() - encode a null object.
355  
356 This is used e.g. in binding lists for variables that don't have a
357 value (yet)
358  
359 =cut
360  
361 0 ▶sub encode_null () { encode_header (null_tag, 0); }
Subroutine encode_null: not called CC=1 SCAR=6.9
Pod documented
362  
363 =head2 encode_sequence()
364  
365 =head2 encode_tagged_sequence()
366  
367 $encoded = encode_sequence (encoded1, encoded2, ...);
368 $encoded = encode_tagged_sequence (tag, encoded1, encoded2, ...);
369  
370 Take already encoded values, and extend them to an encoded sequence.
371 C<encoded_sequence> uses the generic sequence tag, while with
372 C<encode_tagged_sequence> you can specify your own tag.
373 =cut
374  
375 0 ▶sub encode_sequence (@) { encode_tagged_sequence (sequence_tag, @_); }
Subroutine encode_sequence: not called CC=1 SCAR=6.9
Pod documented
376  
377 0 ▶sub encode_tagged_sequence ($@) {
Subroutine encode_tagged_sequence: not called CC=1 SCAR=6.9
Pod documented
378 0 my ($tag,$result);
379  
380 0 $tag = shift @_;
381 0 $result = join '',@_;
382 0 return encode_header ($tag | constructor_flag, length $result).$result;
383 }
384  
385 =head2 encode_string() - encode a Perl string as an OCTET STRING.
386 =cut
387  
388 1 ▶sub encode_string ($) {
Subroutine encode_string: called CC=1 SCAR=0.0
Pod documented
389 1 my ($string)=@_;
390 1 return encode_header (octet_string_tag, length $string).$string;
391 }
392  
393 =head2 encode_ip_address() - encode an IPv4 address.
394  
395 This can either be passed as a four-octet sequence in B<network byte
396 order>, or as a text string in dotted-quad notation,
397 e.g. "192.0.2.234".
398  
399 =cut
400  
401 0 ▶sub encode_ip_address ($) {
Subroutine encode_ip_address: not called CC=3 SCAR=24.8
Pod documented
402 0 my ($addr)=@_;
403 0 my @octets;
404  
405 0 ▶ if (length $addr == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $addr == 4) { } 0 0 0
elsif (@octets = $addr =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) { } 0 0 0
406 ## Four bytes... let's suppose that this is a binary IP address
407 ## in network byte order.
408 0 return encode_header (snmp_ip_address_tag, length $addr).$addr;
409 } elsif (@octets = ($addr =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/)) {
410 0 return encode_ip_address (pack ("CCCC", @octets));
411 } else {
412 0 return error ("IP address must be four bytes long or a dotted-quad");
413 }
414 }
415  
416 =head2 encode_timeticks() - encode an integer as a C<TimeTicks>
417 object.
418  
419 The integer should count hundredths of a second since the epoch
420 defined by C<sysUpTime.0>.
421  
422 =cut
423  
424 0 ▶sub encode_timeticks ($) {
Subroutine encode_timeticks: not called CC=1 SCAR=6.9
Pod documented
425 0 my ($tt) = @_;
426 0 return encode_intlike ($tt, snmp_timeticks_tag);
427 }
428  
429 #### Decoding
430  
431 =head2 pretty_print() - convert an encoded byte sequence into
432 human-readable form.
433  
434 This function can be extended by registering pretty-printing methods
435 for specific type codes. Most BER type codes used in SNMP already
436 have such methods pre-registered by default. See
437 C<register_pretty_printer> for how new methods can be added.
438  
439 =cut
440  
441 0 ▶sub pretty_print ($) {
Subroutine pretty_print: not called CC=18 SCAR=58.3
Pod documented
442 0 my ($packet) = @_;
443 0 ▶ return undef unless defined $packet;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packet 0 0 0
444 0 my $result = ord (substr ($packet, 0, 1));
445 0 ▶ if (exists ($pretty_printer{$result})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $BER::pretty_printer{$result}) 0 0 0
446 0 return &{$pretty_printer{$result}} ($packet);
447 }
448 0 ▶ return ($pretty_print_timeticks
Branch: 2 branches
BranchTrueFalseTotal
if $result == uptime_tag() 0 0 0
$BER::pretty_print_timeticks ? : 0 0 0
449 ? pretty_uptime ($packet)
450 : pretty_unsignedlike ($packet))
451 if $result == uptime_tag;
452 0 ▶ return "(null)" if $result == null_tag;
Branch: 1 branch
BranchTrueFalseTotal
if $result == null_tag() 0 0 0
453 0 ▶ return error ("Exception code: noSuchObject") if $result == snmp_nosuchobject;
Branch: 1 branch
BranchTrueFalseTotal
if $result == snmp_nosuchobject() 0 0 0
454 0 ▶ return error ("Exception code: noSuchInstance") if $result == snmp_nosuchinstance;
Branch: 1 branch
BranchTrueFalseTotal
if $result == snmp_nosuchinstance() 0 0 0
455 0 ▶ return error ("Exception code: endOfMibView") if $result == snmp_endofmibview;
Branch: 1 branch
BranchTrueFalseTotal
if $result == snmp_endofmibview() 0 0 0
456  
457 # IlvJa
458 # pretty print sequences and their contents.
459  
460 0 my $ctx_cons_flags = context_flag | constructor_flag;
461  
462 0 ▶ if($result == (&constructor_flag | &sequence_tag) # sequence
Branch: 1 branch
BranchTrueFalseTotal
if ($result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags) or $result == (4 | $ctx_cons_flags) or $result == (5 | $ctx_cons_flags) or $result == (6 | $ctx_cons_flags) or $result == (7 | $ctx_cons_flags)) 0 0 0
Condition0%0/24
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags) or $result == (4 | $ctx_cons_flags) or $result == (5 | $ctx_cons_flags) or $result == (6 | $ctx_cons_flags) or $result == (7 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags) or $result == (4 | $ctx_cons_flags) or $result == (5 | $ctx_cons_flags) or $result == (6 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags) or $result == (4 | $ctx_cons_flags) or $result == (5 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags) or $result == (4 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags)
l!l&&r!l&&!r
000
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags)
l!l&&r!l&&!r
000
MC/DC0%0/9
$result == (&constructor_flag | &sequence_tag) or $result == (0 | $ctx_cons_flags) or $result == (1 | $ctx_cons_flags) or $result == (2 | $ctx_cons_flags) or $result == (3 | $ctx_cons_flags) or $result == (4 | $ctx_cons_flags) or $result == (5 | $ctx_cons_flags) or $result == (6 | $ctx_cons_flags) or $result == (7 | $ctx_cons_flags)
$result == (&constructor_flag | &sequence_tag) $result == (0 | $ctx_cons_flags) $result == (1 | $ctx_cons_flags) $result == (2 | $ctx_cons_flags) $result == (3 | $ctx_cons_flags) $result == (4 | $ctx_cons_flags) $result == (5 | $ctx_cons_flags) $result == (6 | $ctx_cons_flags) $result == (7 | $ctx_cons_flags)
Truth table0%0/10
A or B or C or D or E or F or G or H or I
A= $result == (&constructor_flag | &sequence_tag)B= $result == (0 | $ctx_cons_flags)C= $result == (1 | $ctx_cons_flags)D= $result == (2 | $ctx_cons_flags)E= $result == (3 | $ctx_cons_flags)F= $result == (4 | $ctx_cons_flags)G= $result == (5 | $ctx_cons_flags)H= $result == (6 | $ctx_cons_flags)I= $result == (7 | $ctx_cons_flags)
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
463 || $result == (0 | $ctx_cons_flags) #get_request
464 || $result == (1 | $ctx_cons_flags) #getnext_request
465 || $result == (2 | $ctx_cons_flags) #response
466 || $result == (3 | $ctx_cons_flags) #set_request
467 || $result == (4 | $ctx_cons_flags) #trap_request
468 || $result == (5 | $ctx_cons_flags) #getbulk_request
469 || $result == (6 | $ctx_cons_flags) #inform_request
470 || $result == (7 | $ctx_cons_flags) #trap2_request
471 )
472 {
473 0 my $pretty_result = pretty_generic_sequence($packet);
474 0 $pretty_result =~ s/^/ /gm; #Indent.
475  
476 my $seq_type_desc =
477 {
478 (constructor_flag | sequence_tag) => "Sequence",
479 (0 | $ctx_cons_flags) => "GetRequest",
480 (1 | $ctx_cons_flags) => "GetNextRequest",
481 (2 | $ctx_cons_flags) => "Response",
482 (3 | $ctx_cons_flags) => "SetRequest",
483 (4 | $ctx_cons_flags) => "Trap",
484 (5 | $ctx_cons_flags) => "GetBulkRequest",
485 (6 | $ctx_cons_flags) => "InformRequest",
486 (7 | $ctx_cons_flags) => "SNMPv2-Trap",
487 (8 | $ctx_cons_flags) => "Report",
488 0 }->{($result)};
489  
490 0 return $seq_type_desc . "{\n" . $pretty_result . "\n}";
491 }
492  
493 0 return sprintf ("#<unprintable BER type 0x%x>", $result);
494 }
495  
496 0 ▶sub pretty_using_decoder ($$) {
Subroutine pretty_using_decoder: not called CC=2 SCAR=17.9
Pod undocumented
497 0 my ($decoder, $packet) = @_;
498 0 my ($decoded,$rest);
499 0 ($decoded,$rest) = &$decoder ($packet);
500 0 ▶ return error ("Junk after object") unless $rest eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $rest eq "" 0 0 0
501 0 return $decoded;
502 }
503  
504 0 ▶sub pretty_string ($) {
Subroutine pretty_string: not called CC=1 SCAR=6.9
Pod undocumented
505 0 pretty_using_decoder (\&decode_string, $_[0]);
506 }
507  
508 0 ▶sub pretty_intlike ($) {
Subroutine pretty_intlike: not called CC=1 SCAR=6.9
Pod undocumented
509 0 my $decoded = pretty_using_decoder (\&decode_intlike, $_[0]);
510 0 $decoded;
511 }
512  
513 0 ▶sub pretty_unsignedlike ($) {
Subroutine pretty_unsignedlike: not called CC=1 SCAR=6.9
Pod undocumented
514 0 return pretty_using_decoder (\&decode_unsignedlike, $_[0]);
515 }
516  
517 0 ▶sub pretty_oid ($) {
Subroutine pretty_oid: not called CC=6 SCAR=37.4
Pod undocumented
518 0 my ($oid) = shift;
519 0 my ($result,$subid,$next);
520 0 my (@oid);
521 0 $result = ord (substr ($oid, 0, 1));
522 0 ▶ return error ("Object ID expected") unless $result == object_id_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $result == object_id_tag() 0 0 0
523 0 ($result, $oid) = decode_length ($oid, 1);
524 0 ▶ return error ("inconsistent length in OID") unless $result == length $oid;
Branch: 1 branch
BranchTrueFalseTotal
unless $result == length $oid 0 0 0
525 0 @oid = ();
526 0 $subid = ord (substr ($oid, 0, 1));
527 0 push @oid, int ($subid / 40);
528 0 push @oid, $subid % 40;
529 0 $oid = substr ($oid, 1);
530 0 ▶ while ($oid ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($oid ne "") 0 0 0
531 0 $subid = ord (substr ($oid, 0, 1));
532 0 ▶ if ($subid < 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subid < 128) { } 0 0 0
533 0 $oid = substr ($oid, 1);
534 0 push @oid, $subid;
535 } else {
536 0 $next = $subid;
537 0 $subid = 0;
538 0 ▶ while ($next >= 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next >= 128) 0 0 0
539 0 $subid = ($subid << 7) + ($next & 0x7f);
540 0 $oid = substr ($oid, 1);
541 0 $next = ord (substr ($oid, 0, 1));
542 }
543 0 $subid = ($subid << 7) + $next;
544 0 $oid = substr ($oid, 1);
545 0 push @oid, $subid;
546 }
547 }
548 0 join ('.', @oid);
549 }
550  
551 0 ▶sub pretty_uptime ($) {
Subroutine pretty_uptime: not called CC=1 SCAR=6.9
Pod undocumented
552 0 my ($packet,$uptime);
553  
554 0 ($uptime,$packet) = &decode_unsignedlike (@_);
555 0 pretty_uptime_value ($uptime);
556 }
557  
558 0 ▶sub pretty_uptime_value ($) {
Subroutine pretty_uptime_value: not called CC=3 SCAR=24.8
Pod undocumented
559 0 my ($uptime) = @_;
560 0 my ($seconds,$minutes,$hours,$days,$result);
561 ## We divide the uptime by hundred since we're not interested in
562 ## sub-second precision.
563 0 $uptime = int ($uptime / 100);
564  
565 0 $days = int ($uptime / (60 * 60 * 24));
566 0 $uptime %= (60 * 60 * 24);
567  
568 0 $hours = int ($uptime / (60 * 60));
569 0 $uptime %= (60 * 60);
570  
571 0 $minutes = int ($uptime / 60);
572 0 $seconds = $uptime % 60;
573  
574 0 ▶ if ($days == 0){
Branch: 2 branches
BranchTrueFalseTotal
if ($days == 0) { } 0 0 0
elsif ($days == 1) { } 0 0 0
575 0 $result = sprintf ("%d:%02d:%02d", $hours, $minutes, $seconds);
576 } elsif ($days == 1) {
577 0 $result = sprintf ("%d day, %d:%02d:%02d",
578 $days, $hours, $minutes, $seconds);
579 } else {
580 0 $result = sprintf ("%d days, %d:%02d:%02d",
581 $days, $hours, $minutes, $seconds);
582 }
583 0 return $result;
584 }
585  
586  
587 0 ▶sub pretty_ip_address ($) {
Subroutine pretty_ip_address: not called CC=3 SCAR=24.8
Pod undocumented
588 0 my $pdu = shift;
589 0 my ($length, $rest);
590 0 ▶ return error ("IP Address tag (".snmp_ip_address_tag.") expected")
Branch: 1 branch
BranchTrueFalseTotal
unless ord substr($pdu, 0, 1) == snmp_ip_address_tag() 0 0 0
591 unless ord (substr ($pdu, 0, 1)) == snmp_ip_address_tag;
592 0 ($length,$pdu) = decode_length ($pdu, 1);
593 0 ▶ return error ("Length of IP address should be four")
Branch: 1 branch
BranchTrueFalseTotal
unless $length == 4 0 0 0
594 unless $length == 4;
595 0 sprintf "%d.%d.%d.%d", unpack ("CCCC", $pdu);
596 }
597  
598 # IlvJa
599 # Returns a string with the pretty prints of all
600 # the elements in the sequence.
601 0 ▶sub pretty_generic_sequence ($) {
Subroutine pretty_generic_sequence: not called CC=13 SCAR=52.0
Pod undocumented
602 0 my ($pdu) = shift;
603  
604 0 my $rest;
605  
606 0 my $type = ord substr ($pdu, 0 ,1);
607 0 my $flags = context_flag | constructor_flag;
608
609 0 ▶ return error (sprintf ("Tag 0x%x is not a valid sequence tag",$type))
Branch: 1 branch
BranchTrueFalseTotal
unless $type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags) or $type == (4 | $flags) or $type == (5 | $flags) or $type == (6 | $flags) or $type == (7 | $flags) 0 0 0
Condition0%0/24
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags) or $type == (4 | $flags) or $type == (5 | $flags) or $type == (6 | $flags) or $type == (7 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags) or $type == (4 | $flags) or $type == (5 | $flags) or $type == (6 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags) or $type == (4 | $flags) or $type == (5 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags) or $type == (4 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags)
l!l&&r!l&&!r
000
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags)
l!l&&r!l&&!r
000
MC/DC0%0/9
$type == (&constructor_flag | &sequence_tag) or $type == (0 | $flags) or $type == (1 | $flags) or $type == (2 | $flags) or $type == (3 | $flags) or $type == (4 | $flags) or $type == (5 | $flags) or $type == (6 | $flags) or $type == (7 | $flags)
$type == (&constructor_flag | &sequence_tag) $type == (0 | $flags) $type == (1 | $flags) $type == (2 | $flags) $type == (3 | $flags) $type == (4 | $flags) $type == (5 | $flags) $type == (6 | $flags) $type == (7 | $flags)
Truth table0%0/10
A or B or C or D or E or F or G or H or I
A= $type == (&constructor_flag | &sequence_tag)B= $type == (0 | $flags)C= $type == (1 | $flags)D= $type == (2 | $flags)E= $type == (3 | $flags)F= $type == (4 | $flags)G= $type == (5 | $flags)H= $type == (6 | $flags)I= $type == (7 | $flags)
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
610 unless ($type == (&constructor_flag | &sequence_tag) # sequence
611 || $type == (0 | $flags) #get_request
612 || $type == (1 | $flags) #getnext_request
613 || $type == (2 | $flags) #response
614 || $type == (3 | $flags) #set_request
615 || $type == (4 | $flags) #trap_request
616 || $type == (5 | $flags) #getbulk_request
617 || $type == (6 | $flags) #inform_request
618 || $type == (7 | $flags) #trap2_request
619 );
620
621 0 my $curelem;
622 my $pretty_result; # Holds the pretty printed sequence.
623 0 my $pretty_elem; # Holds the pretty printed current elem.
624 0 my $first_elem = 'true';
625
626 # Cut away the first Tag and Length from $packet and then
627 # init $rest with that.
628 0 (undef, $rest) = decode_length ($pdu, 1);
629 0 ▶ while($rest)
Branch: 1 branch
BranchTrueFalseTotal
if ($rest) 0 0 0
630 {
631 0 ($curelem,$rest) = decode_generic_tlv($rest);
632 0 $pretty_elem = pretty_print($curelem);
633
634 0 ▶ $pretty_result .= "\n" if not $first_elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $first_elem 0 0 0
635 0 $pretty_result .= $pretty_elem;
636
637 # The rest of the iterations are not related to the
638 # first element of the sequence so..
639 0 ▶ $first_elem = '' if $first_elem;
Branch: 1 branch
BranchTrueFalseTotal
if $first_elem 0 0 0
640 }
641 0 return $pretty_result;
642 }
643  
644 =head2 hex_string() - convert OCTET STRING to hexadecimal notation.
645  
646 =cut
647  
648 0 ▶sub hex_string ($) {
Subroutine hex_string: not called CC=1 SCAR=6.9
Pod documented
649 0 hex_string_of_type ($_[0], octet_string_tag);
650 }
651  
652 =head2 hex_string_of_type() - convert octet string to hex, and check
653 type against given tag.
654  
655 =cut
656  
657 0 ▶sub hex_string_of_type ($$) {
Subroutine hex_string_of_type: not called CC=2 SCAR=17.9
Pod documented
658 0 my ($pdu, $wanted_type) = @_;
659 0 my ($length);
660 0 ▶ return error ("BER tag ".$wanted_type." expected")
Branch: 1 branch
BranchTrueFalseTotal
unless ord substr($pdu, 0, 1) == $wanted_type 0 0 0
661 unless ord (substr ($pdu, 0, 1)) == $wanted_type;
662 0 ($length,$pdu) = decode_length ($pdu, 1);
663 0 hex_string_aux ($pdu);
664 }
665  
666 0 ▶sub hex_string_aux ($) {
Subroutine hex_string_aux: not called CC=2 SCAR=17.9
Pod undocumented
667 0 my ($binary_string) = @_;
668 0 my ($c, $result);
669 0 $result = '';
670 0 for $c (unpack "C*", $binary_string) {
671 0 $result .= sprintf "%02x", $c;
672 }
673 0 $result;
674 }
675  
676 0 ▶sub decode_oid ($) {
Subroutine decode_oid: not called CC=3 SCAR=24.8
Pod undocumented
677 0 my ($pdu) = @_;
678 0 my ($result,$pdu_rest);
679 0 my (@result);
680 0 $result = ord (substr ($pdu, 0, 1));
681 0 ▶ return error ("Object ID expected") unless $result == object_id_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $result == object_id_tag() 0 0 0
682 0 ($result, $pdu_rest) = decode_length ($pdu, 1);
683 0 ▶ return error ("Short PDU")
Branch: 1 branch
BranchTrueFalseTotal
if $result > length $pdu_rest 0 0 0
684 if $result > length $pdu_rest;
685 0 @result = (substr ($pdu, 0, $result + (length ($pdu) - length ($pdu_rest))),
686 substr ($pdu_rest, $result));
687 0 @result;
688 }
689  
690 # IlvJa
691 # This takes a PDU and returns a two element list consisting of
692 # the first element found in the PDU (whatever it is) and the
693 # rest of the PDU
694 0 ▶sub decode_generic_tlv ($) {
Subroutine decode_generic_tlv: not called CC=1 SCAR=6.9
Pod undocumented
695 0 my ($pdu) = @_;
696 0 my (@result);
697 0 my ($elemlength,$pdu_rest) = decode_length ($pdu, 1);
698 0 @result = (# Extract the first element.
699 substr ($pdu, 0, $elemlength + (length ($pdu)
700 - length ($pdu_rest)
701 )
702 ),
703 #Extract the rest of the PDU.
704 substr ($pdu_rest, $elemlength)
705 );
706 0 @result;
707 }
708  
709 =head2 decode_by_template() - decode complex object according to a
710 template.
711  
712 ($var1, ...) = decode_by_template ($pdu, $template, ...);
713  
714 The template can contain various %X directives. Some directives
715 consume additional arguments following the template itself. Most
716 directives will cause values to be returned. The values are returned
717 as a sequence in the order of the directives that generated them.
718  
719 =over 4
720  
721 =item %{ - decode sequence.
722  
723 This doesn't assign any return value, just checks and skips the
724 tag/length fields of the sequence. By default, the tag should be the
725 generic sequence tag, but a tag can also be specified in the
726 directive. The directive can either specify the tag as a prefix,
727 e.g. C<%99{> will require a sequence tag of 99, or if the directive is
728 given as C<%*{>, the tag will be taken from the next argument.
729  
730 =item %s - decode string
731  
732 =item %i - decode integer
733  
734 =item %u - decode unsigned integer
735  
736 =item %O - decode Object ID (OID)
737  
738 =item %A - decode IPv4 address
739  
740 =item %@ - assigns the remaining undecoded part of the PDU to the next
741 return value.
742  
743 =back
744  
745 =cut
746  
747 11 ▶sub decode_by_template {
Subroutine decode_by_template: called CC=1 SCAR=0.0
Pod documented
748 11 my ($pdu) = shift;
749 11 local ($_) = shift;
750 11 return decode_by_template_2 ($pdu, $_, 0, 0, @_);
751 }
752  
753 1 my $template_debug = 0;
754  
755 11 ▶sub decode_by_template_2 {
Subroutine decode_by_template_2: called CC=42 SCAR=52.6
Pod undocumented
756 11 my ($pdu, $template, $pdu_index, $template_index);
757 11 local ($_);
758 11 $pdu = shift;
759 11 $template = $_ = shift;
760 11 $pdu_index = shift;
761 11 $template_index = shift;
762 11 my (@results);
763 11 my ($length,$expected,$read,$rest);
764 11 ▶ return undef unless defined $pdu;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pdu 0 11 11
765 11 ▶ while (0 < length ($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < length $_) 22 11 33
766 22 ▶ if (substr ($_, 0, 1) eq '%') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_, 0, 1) eq '%') { } 22 0 22
767 22 ▶ print STDERR "template $_ ", length $pdu," bytes remaining\n"
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 22 22
768 if $template_debug;
769 22 $_ = substr ($_,1);
770 22 ++$template_index;
771 22 ▶ if (($expected) = /^(\d+|\*|)\{(.*)/) {
Branch: 7 branches
BranchTrueFalseTotal
if (($expected) = /^(\d+|\*|)\{(.*)/) { } 5 17 22
elsif (($expected, $rest) = /^(\*|)s(.*)/) { } 5 12 17
elsif (($rest) = /^A(.*)/) { } 0 12 12
elsif (/^O(.*)/) { } 0 12 12
elsif (($expected, $rest) = /^(\d+|\*|)i(.*)/) { } 11 1 12
elsif (($rest) = /^u(.*)/) { } 1 0 1
elsif (/^\@(.*)/) { } 0 0 0
772 ## %{
773 5 $template_index += length ($expected) + 1;
774 5 ▶ print STDERR "%{\n" if $template_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 5 5
775 5 $_ = $2;
776 5 ▶ $expected = shift | constructor_flag if ($expected eq '*');
Branch: 1 branch
BranchTrueFalseTotal
if $expected eq "*" 1 4 5
777 5 ▶ $expected = sequence_tag | constructor_flag
Branch: 1 branch
BranchTrueFalseTotal
if $expected eq "" 4 1 5
778 if $expected eq '';
779 5 ▶ return template_error ("Unexpected end of PDU",
Branch: 1 branch
BranchTrueFalseTotal
if not defined $pdu or $pdu eq "" 0 5 5
Condition33%1/3
not defined $pdu or $pdu eq ""
l!l&&r!l&&!r
005
MC/DC0%0/2
not defined $pdu or $pdu eq ""
not defined $pdu $pdu eq ""
Truth table33%1/3
not(A) or B
A= not defined $pduB= $pdu eq ""
ABresult
1X1
011
000
780 $template, $template_index)
781 if !defined $pdu or $pdu eq '';
782 5 ▶ return template_error ("Expected sequence tag $expected, got ".
Branch: 1 branch
BranchTrueFalseTotal
unless ord substr($pdu, 0, 1) == $expected 0 5 5
783 ord (substr ($pdu, 0, 1)),
784 $template,
785 $template_index)
786 unless (ord (substr ($pdu, 0, 1)) == $expected);
787 5 ▶ ($length,$pdu) = decode_length ($pdu, 1)
Branch: 1 branch
BranchTrueFalseTotal
($length, $pdu) = &decode_length($pdu, 1) or return &template_error("cannot read length", $template, $template_index) 5 0 5
788 or return template_error ("cannot read length",
789 $template, $template_index);
790 5 ▶ return template_error ("Expected length $length, got ".length $pdu ,
Branch: 1 branch
BranchTrueFalseTotal
unless length $pdu == $length 0 5 5
791 $template, $template_index)
792 unless length $pdu == $length;
793 } elsif (($expected,$rest) = /^(\*|)s(.*)/) {
794 ## %s
795 5 $template_index += length ($expected) + 1;
796 5 ▶ ($expected = shift) if $expected eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $expected eq "*" 1 4 5
797 5 ▶ ($read, $pdu) = decode_string ($pdu)
Branch: 1 branch
BranchTrueFalseTotal
($read, $pdu) = &decode_string($pdu) or return &template_error("cannot read string", $template, $template_index) 5 0 5
798 or return template_error ("cannot read string",
799 $template, $template_index);
800 5 ▶ print STDERR "%s => $read\n" if $template_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 5 5
801 5 ▶ if ($expected eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected eq '') { } 4 1 5
802 4 push @results, $read;
803 } else {
804 1 ▶ return template_error ("Expected $expected, read $read",
Branch: 1 branch
BranchTrueFalseTotal
unless $expected eq $read 0 1 1
805 $template, $template_index)
806 unless $expected eq $read;
807 }
808 5 $_ = $rest;
809 } elsif (($rest) = /^A(.*)/) {
810 ## %A
811 0 $template_index += 1;
812 {
813 0 my ($tag, $length, $value);
814 0 $tag = ord (substr ($pdu, 0, 1));
815 0 ▶ return error ("Expected IP address, got tag ".$tag)
Branch: 1 branch
BranchTrueFalseTotal
unless $tag == snmp_ip_address_tag() 0 0 0
816 unless $tag == snmp_ip_address_tag;
817 0 ($length, $pdu) = decode_length ($pdu, 1);
818 0 ▶ return error ("Inconsistent length of InetAddress encoding")
Branch: 1 branch
BranchTrueFalseTotal
if $length > length $pdu 0 0 0
819 if $length > length $pdu;
820 0 ▶ return template_error ("IP address must be four bytes long",
Branch: 1 branch
BranchTrueFalseTotal
unless $length == 4 0 0 0
821 $template, $template_index)
822 unless $length == 4;
823 0 $read = substr ($pdu, 0, $length);
824 0 $pdu = substr ($pdu, $length);
825 }
826 0 ▶ print STDERR "%A => $read\n" if $template_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 0 0
827 0 push @results, $read;
828 0 $_ = $rest;
829 } elsif (/^O(.*)/) {
830 ## %O
831 0 $template_index += 1;
832 0 $_ = $1;
833 0 ▶ ($read,$pdu) = decode_oid ($pdu)
Branch: 1 branch
BranchTrueFalseTotal
($read, $pdu) = &decode_oid($pdu) or return &template_error("cannot read OID", $template, $template_index) 0 0 0
834 or return template_error ("cannot read OID",
835 $template, $template_index);
836 0 ▶ print STDERR "%O => ".pretty_oid ($read)."\n"
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 0 0
837 if $template_debug;
838 0 push @results, $read;
839 } elsif (($expected,$rest) = /^(\d+|\*|)i(.*)/) {
840 ## %i
841 11 $template_index += length ($expected) + 1;
842 11 ▶ print STDERR "%i\n" if $template_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 11 11
843 11 $_ = $rest;
844 11 ▶ ($read, $pdu) = decode_int ($pdu)
Branch: 1 branch
BranchTrueFalseTotal
($read, $pdu) = &decode_int($pdu) or return &template_error("cannot read int", $template, $template_index) 11 0 11
845 or return template_error ("cannot read int",
846 $template, $template_index);
847 11 ▶ if ($expected eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected eq '') { } 9 2 11
848 9 push @results, $read;
849 } else {
850 2 ▶ $expected = int (shift) if $expected eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $expected eq "*" 0 2 2
851 2 ▶ return template_error (sprintf ("Expected %d (0x%x), got %d (0x%x)",
Branch: 1 branch
BranchTrueFalseTotal
unless $expected == $read 0 2 2
852 $expected, $expected, $read, $read),
853 $template, $template_index)
854 unless ($expected == $read)
855 }
856 } elsif (($rest) = /^u(.*)/) {
857 ## %u
858 1 $template_index += 1;
859 1 ▶ print STDERR "%u\n" if $template_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 1 1
860 1 $_ = $rest;
861 1 ▶ ($read, $pdu) = decode_unsignedlike ($pdu)
Branch: 1 branch
BranchTrueFalseTotal
($read, $pdu) = &decode_unsignedlike($pdu) or return &template_error("cannot read uptime", $template, $template_index) 1 0 1
862 or return template_error ("cannot read uptime",
863 $template, $template_index);
864 1 push @results, $read;
865 } elsif (/^\@(.*)/) {
866 ## %@
867 0 $template_index += 1;
868 0 ▶ print STDERR "%@\n" if $template_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $template_debug 0 0 0
869 0 $_ = $1;
870 0 push @results, $pdu;
871 0 $pdu = '';
872 } else {
873 0 return template_error ("Unknown decoding directive in template: $_",
874 $template, $template_index);
875 }
876 } else {
877 0 ▶ if (substr ($_, 0, 1) ne substr ($pdu, 0, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_, 0, 1) ne substr($pdu, 0, 1)) 0 0 0
878 0 return template_error ("Expected ".substr ($_, 0, 1).", got ".substr ($pdu, 0, 1),
879 $template, $template_index);
880 }
881 0 $_ = substr ($_,1);
882 0 $pdu = substr ($pdu,1);
883 }
884 }
885 11 ▶ return template_error ("PDU too long", $template, $template_index)
Branch: 1 branch
BranchTrueFalseTotal
if length $pdu > 0 0 11 11
886 if length ($pdu) > 0;
887 11 ▶ return template_error ("PDU too short", $template, $template_index)
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > 0 0 11 11
888 if length ($_) > 0;
889 11 @results;
890 }
891  
892 =head2 decode_sequence() - Split sequence into components.
893  
894 ($first, $rest) = decode_sequence ($pdu);
895  
896 Checks whether the PDU has a sequence type tag and a plausible length
897 field. Splits the initial element off the list, and returns both this
898 and the remainder of the PDU.
899  
900 =cut
901  
902 1 ▶sub decode_sequence ($) {
Subroutine decode_sequence: called CC=3 SCAR=11.1
Pod documented
903 1 my ($pdu) = @_;
904 1 my ($result);
905 my (@result);
906 1 $result = ord (substr ($pdu, 0, 1));
907 1 ▶ return error ("Sequence expected")
Branch: 1 branch
BranchTrueFalseTotal
unless $result == (sequence_tag() | constructor_flag()) 0 1 1
908 unless $result == (sequence_tag | constructor_flag);
909 1 ($result, $pdu) = decode_length ($pdu, 1);
910 1 ▶ return error ("Short PDU")
Branch: 1 branch
BranchTrueFalseTotal
if $result > length $pdu 0 1 1
911 if $result > length $pdu;
912 1 @result = (substr ($pdu, 0, $result), substr ($pdu, $result));
913 1 @result;
914 }
915  
916 11 ▶sub decode_int ($) {
Subroutine decode_int: called CC=2 SCAR=7.0
Pod undocumented
917 11 my ($pdu) = @_;
918 11 my $tag = ord (substr ($pdu, 0, 1));
919 11 ▶ return error ("Integer expected, found tag ".$tag)
Branch: 1 branch
BranchTrueFalseTotal
unless $tag == int_tag() 0 11 11
920 unless $tag == int_tag;
921 11 decode_intlike ($pdu);
922 }
923  
924 11 ▶sub decode_intlike ($) {
Subroutine decode_intlike: called CC=1 SCAR=0.0
Pod undocumented
925 11 decode_intlike_s ($_[0], 1);
926 }
927  
928 1 ▶sub decode_unsignedlike ($) {
Subroutine decode_unsignedlike: called CC=1 SCAR=0.0
Pod undocumented
929 1 decode_intlike_s ($_[0], 0);
930 }
931  
932 1 my $have_math_bigint_p = 0;
933  
934 12 ▶sub decode_intlike_s ($$) {
Subroutine decode_intlike_s: called CC=7 SCAR=24.7
Pod undocumented
935 12 my ($pdu, $signedp) = @_;
936 12 my ($length,$result);
937 12 ($length,$pdu) = decode_length ($pdu, 1);
938 12 my $ptr = 0;
939 12 ▶ $result = unpack ($signedp ? "c" : "C", substr ($pdu, $ptr++, 1));
Branch: 1 branch
BranchTrueFalseTotal
$signedp ? : 11 1 12
940 12 ▶ if ($length > 5 || ($length == 5 && $result > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5 or $length == 5 and $result > 0) 0 12 12
Condition33%2/6
$length > 5 or $length == 5 and $result > 0
l!l&&r!l&&!r
0012
$length == 5 and $result > 0
!ll&&!rl&&r
1200
MC/DC0%0/3
$length > 5 or $length == 5 and $result > 0
$length > 5 $length == 5 $result > 0
Truth table25%1/4
A or B and C
A= $length > 5B= $length == 5C= $result > 0
ABCresult
1XX1
0111
00X0
0100
941 0 ▶ require 'Math/BigInt.pm' unless $have_math_bigint_p++;
Branch: 1 branch
BranchTrueFalseTotal
unless $have_math_bigint_p++ 0 0 0
942 0 $result = new Math::BigInt ($result);
943 }
944 12 ▶ while (--$length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$length > 0) 0 12 12
945 0 $result *= 256;
946 0 $result += unpack ("C", substr ($pdu, $ptr++, 1));
947 }
948 12 ($result, substr ($pdu, $ptr));
949 }
950  
951 5 ▶sub decode_string ($) {
Subroutine decode_string: called CC=3 SCAR=11.2
Pod undocumented
952 5 my ($pdu) = shift;
953 5 my ($result);
954 5 $result = ord (substr ($pdu, 0, 1));
955 5 ▶ return error ("Expected octet string, got tag ".$result)
Branch: 1 branch
BranchTrueFalseTotal
unless $result == octet_string_tag() 0 5 5
956 unless $result == octet_string_tag;
957 5 ($result, $pdu) = decode_length ($pdu, 1);
958 5 ▶ return error ("Short PDU")
Branch: 1 branch
BranchTrueFalseTotal
if $result > length $pdu 0 5 5
959 if $result > length $pdu;
960 5 return (substr ($pdu, 0, $result), substr ($pdu, $result));
961 }
962  
963 23 ▶sub decode_length ($@) {
Subroutine decode_length: called CC=5 SCAR=21.6
Pod undocumented
964 23 my ($pdu) = shift;
965 23 ▶ my $index = shift || 0;
Condition50%1/2
shift() || 0
l!l
230
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
966 23 my ($result);
967 my (@result);
968 23 $result = ord (substr ($pdu, $index, 1));
969 23 ▶ if ($result & long_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result & long_length()) { } 0 23 23
970 0 ▶ if ($result == (long_length | 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result == (long_length() | 1)) { } 0 0 0
elsif ($result == (long_length() | 2)) { } 0 0 0
971 0 @result = (ord (substr ($pdu, $index+1, 1)), substr ($pdu, $index+2));
972 } elsif ($result == (long_length | 2)) {
973 0 @result = ((ord (substr ($pdu, $index+1, 1)) << 8)
974 + ord (substr ($pdu, $index+2, 1)), substr ($pdu, $index+3));
975 } else {
976 0 return error ("Unsupported length");
977 }
978 } else {
979 23 @result = ($result, substr ($pdu, $index+1));
980 }
981 23 @result;
982 }
983  
984 =head2 register_pretty_printer() - register pretty-printing methods for
985 typecodes.
986  
987 This function takes a hashref that specifies functions to call when
988 the specified value type is being printed. It returns the number of
989 functions that were registered.
990 =cut
991 sub register_pretty_printer($)
992 0 ▶{
Subroutine register_pretty_printer: not called CC=3 SCAR=24.8
Pod documented
993 0 my ($h_ref) = shift;
994 0 my ($type, $val, $cnt);
995  
996 0 $cnt = 0;
997 0 ▶ while(($type, $val) = each %$h_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$h_ref) 0 0 0
998 0 ▶ if (ref $val eq "CODE") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "CODE") 0 0 0
999 0 $pretty_printer{$type} = $val;
1000 0 $cnt++;
1001 }
1002 }
1003 0 return($cnt);
1004 }
1005  
1006 # This takes a hashref that specifies functions to call when
1007 # the specified value type is being printed. It removes the
1008 # functions from the list for the types specified.
1009 # It returns the number of functions that were unregistered.
1010 sub unregister_pretty_printer($)
1011 0 ▶{
Subroutine unregister_pretty_printer: not called CC=5 SCAR=34.0
Pod undocumented
1012 0 my ($h_ref) = shift;
1013 0 my ($type, $val, $cnt);
1014  
1015 0 $cnt = 0;
1016 0 ▶ while(($type, $val) = each %$h_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$h_ref) 0 0 0
1017 0 ▶ if ((exists ($pretty_printer{$type}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $BER::pretty_printer{$type} and $BER::pretty_printer{$type} == $val) 0 0 0
Condition0%0/3
exists $BER::pretty_printer{$type} and $BER::pretty_printer{$type} == $val
!ll&&!rl&&r
000
MC/DC0%0/2
exists $BER::pretty_printer{$type} and $BER::pretty_printer{$type} == $val
exists $BER::pretty_printer{$type} $BER::pretty_printer{$type} == $val
Truth table0%0/3
A and B
A= exists $BER::pretty_printer{$type}B= $BER::pretty_printer{$type} == $val
ABresult
0X0
100
111
1018 && ($pretty_printer{$type} == $val)) {
1019 0 ▶ if (exists($default_printer{$type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $BER::default_printer{$type}) { } 0 0 0
1020 0 $pretty_printer{$type} = $default_printer{$type};
1021 } else {
1022 0 delete $pretty_printer{$type};
1023 }
1024 0 $cnt++;
1025 }
1026 }
1027 0 return($cnt);
1028 }
1029  
1030 #### OID prefix check
1031  
1032 ### encoded_oid_prefix_p OID1 OID2
1033 ###
1034 ### OID1 and OID2 should be BER-encoded OIDs.
1035 ### The function returns non-zero iff OID1 is a prefix of OID2.
1036 ### This can be used in the termination condition of a loop that walks
1037 ### a table using GetNext or GetBulk.
1038 ###
1039 0 ▶sub encoded_oid_prefix_p ($$) {
Subroutine encoded_oid_prefix_p: not called CC=7 SCAR=40.3
Pod undocumented
1040 0 my ($oid1, $oid2) = @_;
1041 0 my ($i1, $i2);
1042 0 my ($l1, $l2);
1043 0 my ($subid1, $subid2);
1044 0 ▶ return error ("OID tag expected") unless ord (substr ($oid1, 0, 1)) == object_id_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless ord substr($oid1, 0, 1) == object_id_tag() 0 0 0
1045 0 ▶ return error ("OID tag expected") unless ord (substr ($oid2, 0, 1)) == object_id_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless ord substr($oid2, 0, 1) == object_id_tag() 0 0 0
1046 0 ($l1,$oid1) = decode_length ($oid1, 1);
1047 0 ($l2,$oid2) = decode_length ($oid2, 1);
1048 0 ▶ for ($i1 = 0, $i2 = 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($i1 < $l1 and $i2 < $l2) 0 0 0
Condition0%0/3
$i1 < $l1 and $i2 < $l2
!ll&&!rl&&r
000
MC/DC0%0/2
$i1 < $l1 and $i2 < $l2
$i1 < $l1 $i2 < $l2
Truth table0%0/3
A and B
A= $i1 < $l1B= $i2 < $l2
ABresult
0X0
100
111
1049 $i1 < $l1 && $i2 < $l2;
1050 ++$i1, ++$i2) {
1051 0 ($subid1,$i1) = &decode_subid ($oid1, $i1, $l1);
1052 0 ($subid2,$i2) = &decode_subid ($oid2, $i2, $l2);
1053 0 ▶ return 0 unless $subid1 == $subid2;
Branch: 1 branch
BranchTrueFalseTotal
unless $subid1 == $subid2 0 0 0
1054 }
1055 0 ▶ return $i2 if $i1 == $l1;
Branch: 1 branch
BranchTrueFalseTotal
if $i1 == $l1 0 0 0
1056 0 return 0;
1057 }
1058  
1059 ### decode_subid OID INDEX
1060 ###
1061 ### Decodes a subid field from a BER-encoded object ID.
1062 ### Returns two values: the field, and the index of the last byte that
1063 ### was actually decoded.
1064 ###
1065 0 ▶sub decode_subid ($$$) {
Subroutine decode_subid: not called CC=3 SCAR=24.8
Pod undocumented
1066 0 my ($oid, $i, $l) = @_;
1067 0 my $subid = 0;
1068 0 my $next;
1069  
1070 0 ▶ while (($next = ord (substr ($oid, $i, 1))) >= 128) {
Branch: 1 branch
BranchTrueFalseTotal
if (($next = ord substr($oid, $i, 1)) >= 128) 0 0 0
1071 0 $subid = ($subid << 7) + ($next & 0x7f);
1072 0 ++$i;
1073 0 ▶ return error ("decoding object ID: short field")
Branch: 1 branch
BranchTrueFalseTotal
unless $i < $l 0 0 0
1074 unless $i < $l;
1075 }
1076 0 return (($subid << 7) + $next, $i);
1077 }
1078  
1079 0 ▶sub error (@) {
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
1080 0 $errmsg = join ("",@_);
1081 0 return undef;
1082 }
1083  
1084 0 ▶sub template_error ($$$) {
Subroutine template_error: not called CC=1 SCAR=6.9
Pod undocumented
1085 0 my ($errmsg, $template, $index) = @_;
1086 0 return error ($errmsg."\n ".$template."\n ".(' ' x $index)."^");
1087 }
1088  
1089 1 1;
1090  
1091 =head1 AUTHORS
1092  
1093 Created by: Simon Leinen E<lt>simon.leinen@switch.chE<gt>
1094  
1095 Contributions and fixes by:
1096  
1097 =over
1098  
1099 =item Andrzej Tobola E<lt>san@iem.pw.edu.plE<gt>: Added long String decode
1100  
1101 =item Tobias Oetiker E<lt>tobi@oetiker.chE<gt>: Added 5 Byte Integer decode ...
1102  
1103 =item Dave Rand E<lt>dlr@Bungi.comE<gt>: Added C<SysUpTime> decode
1104  
1105 =item Philippe Simonet E<lt>sip00@vg.swissptt.chE<gt>: Support larger subids
1106  
1107 =item Yufang HU E<lt>yhu@casc.comE<gt>: Support even larger subids
1108  
1109 =item Mike Mitchell E<lt>Mike.Mitchell@sas.comE<gt>: New generalized C<encode_int()>
1110  
1111 =item Mike Diehn E<lt>mdiehn@mindspring.netE<gt>: C<encode_ip_address()>
1112  
1113 =item Rik Hoorelbeke E<lt>rik.hoorelbeke@pandora.beE<gt>: C<encode_oid()> fix
1114  
1115 =item Brett T Warden E<lt>wardenb@eluminant.comE<gt>: pretty C<UInteger32>
1116  
1117 =item Bert Driehuis E<lt>driehuis@playbeing.orgE<gt>: Handle SNMPv2 exception codes
1118  
1119 =item Jakob Ilves (/IlvJa) E<lt>jakob.ilves@oracle.comE<gt>: PDU decoding
1120  
1121 =item Jan Kasprzak E<lt>kas@informatics.muni.czE<gt>: Fix for PDU syntax check
1122  
1123 =item Milen Pavlov E<lt>milen@batmbg.comE<gt>: Recognize variant length for ints
1124  
1125 =back
1126  
1127 =head1 COPYRIGHT
1128  
1129 Copyright (c) 1995-2009, Simon Leinen.
1130  
1131 This program is free software; you can redistribute it under the
1132 "Artistic License 2.0" included in this distribution (file "Artistic").
1133  
1134 =cut
« SNMP_util.pm ↑ Summary SNMP_Session.pm »