… | |
… | |
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, # constructed, 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? |
… | |
… | |
303 | a ease-of-use exception, they usually also accept C<undef> instead of a |
303 | a ease-of-use exception, they usually also accept C<undef> instead of a |
304 | tuple reference, in which case they silently fail to match. |
304 | tuple reference, in which case they silently fail to match. |
305 | |
305 | |
306 | =over |
306 | =over |
307 | |
307 | |
308 | =item $bool = ber_is $tuple, $class, $tag, $constructed, $data |
308 | =item $bool = ber_is $tuple, $class, $tag, $flags, $data |
309 | |
309 | |
310 | This takes a BER C<$tuple> and matches its elements against the provided |
310 | This takes a BER C<$tuple> and matches its elements against the provided |
311 | values, all of which are optional - values that are either missing or |
311 | values, all of which are optional - values that are either missing or |
312 | C<undef> will be ignored, the others will be matched exactly (e.g. as if |
312 | C<undef> will be ignored, the others will be matched exactly (e.g. as if |
313 | you used C<==> or C<eq> (for C<$data>)). |
313 | you used C<==> or C<eq> (for C<$data>)). |
… | |
… | |
582 | C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard |
582 | C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard |
583 | error for some types, then C<BER_TYPE_CROAK> is for you. |
583 | error for some types, then C<BER_TYPE_CROAK> is for you. |
584 | |
584 | |
585 | =back |
585 | =back |
586 | |
586 | |
|
|
587 | =head2 Example Profile |
|
|
588 | |
|
|
589 | The following creates a profile suitable for SNMP - it's exactly identical |
|
|
590 | to the C<$Convert::BER::XS::SNMP_PROFILE> profile. |
|
|
591 | |
|
|
592 | our $SNMP_PROFILE = new Convert::BER::XS::Profile; |
|
|
593 | |
|
|
594 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
|
|
595 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
|
|
596 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
|
|
597 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
|
|
598 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
|
|
599 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
|
|
600 | |
587 | =cut |
601 | =cut |
588 | |
602 | |
589 | our $DEFAULT_PROFILE = new Convert::BER::XS::Profile; |
603 | our $DEFAULT_PROFILE = new Convert::BER::XS::Profile; |
590 | our $SNMP_PROFILE = new Convert::BER::XS::Profile; |
604 | |
|
|
605 | $DEFAULT_PROFILE->_set_default; |
591 | |
606 | |
592 | # additional SNMP application types |
607 | # additional SNMP application types |
|
|
608 | our $SNMP_PROFILE = new Convert::BER::XS::Profile; |
593 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
609 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
594 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
610 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
595 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
611 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
596 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
612 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
597 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
613 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
598 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
614 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
599 | |
615 | |
600 | $DEFAULT_PROFILE->_set_default; |
|
|
601 | |
|
|
602 | 1; |
616 | 1; |
603 | |
617 | |
604 | =head2 LIMITATIONS/NOTES |
618 | =head2 LIMITATIONS/NOTES |
605 | |
619 | |
606 | This module can only en-/decode 64 bit signed and unsigned integers, and |
620 | This module can only en-/decode 64 bit signed and unsigned integers, and |