… | |
… | |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Convert::BER::XS ':all'; |
7 | use Convert::BER::XS ':all'; |
8 | |
8 | |
9 | my $ber = ber_decode $buf |
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, # constructed, data) |
13 | # (class, tag, # constructed, 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? |
19 | |
19 | |
20 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, |
20 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, |
21 | [ |
21 | [ |
22 | [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 0 ], # snmp version 1 |
22 | [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 0 ], # snmp version 1 |
23 | [ ASN_UNIVERSAL, 4, 0, "public" ], # community |
23 | [ ASN_UNIVERSAL, 4, 0, "public" ], # community |
24 | [ ASN_CONTEXT, 4, 1, # CHOICE, constructed - trap PDU |
24 | [ ASN_CONTEXT, 4, 1, # CHOICE, constructed - trap PDU |
25 | [ |
25 | [ |
26 | [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.2" ], # enterprise oid |
26 | [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.2" ], # enterprise oid |
27 | [ ASN_APPLICATION, 0, 0, "\x0a\x00\x00\x01" ], # SNMP IpAddress, 10.0.0.1 |
27 | [ ASN_APPLICATION, SNMP_IPADDRESS, 0, "10.0.0.1" ], # SNMP IpAddress |
28 | [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 6 ], # generic trap |
28 | [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 6 ], # generic trap |
29 | [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 1 ], # specific trap |
29 | [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 1 ], # specific trap |
30 | [ ASN_APPLICATION, ASN_TIMETICKS, 0, 1817903850 ], # SNMP TimeTicks |
30 | [ ASN_APPLICATION, SNMP_TIMETICKS, 0, 1817903850 ], # SNMP TimeTicks |
31 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # the varbindlist |
31 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # the varbindlist |
32 | [ |
32 | [ |
33 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # a single varbind, "key value" pair |
33 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # a single varbind, "key value" pair |
34 | [ |
34 | [ |
35 | [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.1.1.8.1.2.1" ], |
35 | [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.1.1.8.1.2.1" ], |
… | |
… | |
62 | ) { |
62 | ) { |
63 | ... and so on |
63 | ... and so on |
64 | |
64 | |
65 | # finally, let's encode it again and hope it results in the same bit pattern |
65 | # finally, let's encode it again and hope it results in the same bit pattern |
66 | |
66 | |
67 | my $buf = ber_encode $ber; |
67 | my $buf = ber_encode $ber, $Convert::BER::XS::SNMP_PROFILE; |
68 | |
68 | |
69 | =head1 DESCRIPTION |
69 | =head1 DESCRIPTION |
70 | |
70 | |
71 | WARNING: Before release 1.0, the API is not considered stable in any way. |
71 | WARNING: Before release 1.0, the API is not considered stable in any way. |
72 | |
72 | |
73 | This module implements a I<very> low level BER/DER en-/decoder. |
73 | This module implements a I<very> low level BER/DER en-/decoder. |
74 | |
74 | |
75 | If is tuned for low memory and high speed, while still maintaining some |
75 | It is tuned for low memory and high speed, while still maintaining some |
76 | level of user-friendlyness. |
76 | level of user-friendlyness. |
77 | |
77 | |
78 | =head2 EXPORT TAGS AND CONSTANTS |
78 | =head2 EXPORT TAGS AND CONSTANTS |
79 | |
79 | |
80 | By default this module doesn't export any symbols, but if you don't want |
80 | By default this module doesn't export any symbols, but if you don't want |