… | |
… | |
8 | |
8 | |
9 | my $ber = ber_decode $buf, $Convert::BER::XS::SNMP_PROFILE |
9 | my $ber = ber_decode $buf, $Convert::BER::XS::SNMP_PROFILE |
10 | or die "unable to decode SNMP message"; |
10 | or die "unable to decode SNMP message"; |
11 | |
11 | |
12 | # The above results in a data structure consisting of |
12 | # The above results in a data structure consisting of |
13 | # (class, tag, flags, data) |
13 | # (class, tag, flags, data) |
14 | # tuples. Below is such a message, SNMPv1 trap |
14 | # tuples. Below is such a message, SNMPv1 trap |
15 | # with a Cisco mac change notification. |
15 | # with a Cisco mac change notification. |
16 | # Did you know that Cisco is in the news almost |
16 | # Did you know that Cisco is in the news almost |
17 | # every week because of some backdoor password |
17 | # every week because of some backdoor password |
18 | # or other extremely stupid security bug? |
18 | # or other extremely stupid security bug? |
… | |
… | |
412 | use Exporter qw(import); |
412 | use Exporter qw(import); |
413 | |
413 | |
414 | our $VERSION; |
414 | our $VERSION; |
415 | |
415 | |
416 | BEGIN { |
416 | BEGIN { |
417 | $VERSION = '1.0'; |
417 | $VERSION = 1.1; |
418 | XSLoader::load __PACKAGE__, $VERSION; |
418 | XSLoader::load __PACKAGE__, $VERSION; |
419 | } |
419 | } |
420 | |
420 | |
421 | our %EXPORT_TAGS = ( |
421 | our %EXPORT_TAGS = ( |
422 | const_index => [qw( |
422 | const_index => [qw( |
… | |
… | |
496 | Example output: |
496 | Example output: |
497 | |
497 | |
498 | SEQUENCE |
498 | SEQUENCE |
499 | | OCTET_STRING bytes 800063784300454045045400000001 |
499 | | OCTET_STRING bytes 800063784300454045045400000001 |
500 | | OCTET_STRING bytes |
500 | | OCTET_STRING bytes |
501 | | CONTEXT (7) bytes CONSTRUCTED |
501 | | CONTEXT (7) CONSTRUCTED |
502 | | | INTEGER int 1058588941 |
502 | | | INTEGER int 1058588941 |
503 | | | INTEGER int 0 |
503 | | | INTEGER int 0 |
504 | | | INTEGER int 0 |
504 | | | INTEGER int 0 |
505 | | | SEQUENCE |
505 | | | SEQUENCE |
506 | | | | SEQUENCE |
506 | | | | SEQUENCE |
… | |
… | |
549 | $class =~ s/^ASN_//; |
549 | $class =~ s/^ASN_//; |
550 | $tag =~ s/^(ASN_|SNMP_)//; |
550 | $tag =~ s/^(ASN_|SNMP_)//; |
551 | $type =~ s/^BER_TYPE_//; |
551 | $type =~ s/^BER_TYPE_//; |
552 | |
552 | |
553 | if ($ber->[BER_FLAGS]) { |
553 | if ($ber->[BER_FLAGS]) { |
554 | printf "$indent%-16.16s %-6.6s CONSTRUCTED\n", $tag, lc $type; |
554 | printf "$indent%-16.16s CONSTRUCTED\n", $tag; |
555 | &_ber_dump ($_, $profile, "$indent| ") |
555 | &_ber_dump ($_, $profile, "$indent| ") |
556 | for @$data; |
556 | for @$data; |
557 | } else { |
557 | } else { |
558 | if ($data =~ y/\x20-\x7e//c / (length $data || 1) > 0.2 or $data =~ /\x00./s) { |
558 | if ($data =~ y/\x20-\x7e//c / (length $data || 1) > 0.2 or $data =~ /\x00./s) { |
559 | # assume binary |
559 | # assume binary |
… | |
… | |
739 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
739 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
740 | |
740 | |
741 | =head2 LIMITATIONS/NOTES |
741 | =head2 LIMITATIONS/NOTES |
742 | |
742 | |
743 | This module can only en-/decode 64 bit signed and unsigned integers, and |
743 | This module can only en-/decode 64 bit signed and unsigned integers, and |
744 | only when your perl supports those. So no UUID OIDs for now. |
744 | only when your perl supports those. So no UUID OIDs for now (unless you |
|
|
745 | map the C<OBJECT IDENTIFIER> tag to something other than C<BER_TYPE_OID>). |
745 | |
746 | |
746 | This module does not generally care about ranges, i.e. it will happily |
747 | This module does not generally care about ranges, i.e. it will happily |
747 | de-/encode 64 bit integers into an C<ASN_INTEGER> value, or a negative |
748 | de-/encode 64 bit integers into an C<ASN_INTEGER> value, or a negative |
748 | number into an C<SNMP_COUNTER64>. |
749 | number into an C<SNMP_COUNTER64>. |
749 | |
750 | |
750 | OBJECT IDENTIFIEERs cannot have unlimited length, although the limit is |
751 | OBJECT IDENTIFIEERs cannot have unlimited length, although the limit is |
751 | much larger than e.g. the one imposed by SNMP or other protocols,a nd is |
752 | much larger than e.g. the one imposed by SNMP or other protocols, and is |
752 | about 4kB. |
753 | about 4kB. |
753 | |
754 | |
754 | Indefinite length encoding is not supported. |
755 | Indefinite length encoding is not supported. |
755 | |
756 | |
756 | Constructed strings are decoded just fine, but there should be a way to |
757 | Constructed strings are decoded just fine, but there should be a way to |
757 | join them for convenience. |
758 | join them for convenience. |
758 | |
759 | |
759 | REAL values are not supported and will currently croak. |
760 | REAL values are not supported and will currently croak. |
760 | |
761 | |
761 | The encoder and decoder tend to accept more formats than should be |
762 | The encoder and decoder tend to accept more formats than should be |
762 | strictly supported. |
763 | strictly supported - security sensitive applications are strongly advised |
|
|
764 | to review the code first. |
763 | |
765 | |
764 | This module has undergone little to no testing so far. |
766 | This module has undergone little to no testing so far. |
765 | |
767 | |
766 | =head2 ITHREADS SUPPORT |
768 | =head2 ITHREADS SUPPORT |
767 | |
769 | |