ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-BER-XS/XS.pm
(Generate patch)

Comparing Convert-BER-XS/XS.pm (file contents):
Revision 1.28 by root, Sat Apr 20 15:37:27 2019 UTC vs.
Revision 1.30 by root, Sat Apr 20 15:46:57 2019 UTC

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?
303a ease-of-use exception, they usually also accept C<undef> instead of a 303a ease-of-use exception, they usually also accept C<undef> instead of a
304tuple reference, in which case they silently fail to match. 304tuple 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
310This takes a BER C<$tuple> and matches its elements against the provided 310This takes a BER C<$tuple> and matches its elements against the provided
311values, all of which are optional - values that are either missing or 311values, all of which are optional - values that are either missing or
312C<undef> will be ignored, the others will be matched exactly (e.g. as if 312C<undef> will be ignored, the others will be matched exactly (e.g. as if
313you used C<==> or C<eq> (for C<$data>)). 313you used C<==> or C<eq> (for C<$data>)).
582C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard 582C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard
583error for some types, then C<BER_TYPE_CROAK> is for you. 583error for some types, then C<BER_TYPE_CROAK> is for you.
584 584
585=back 585=back
586 586
587=head2 Example Profile
588
589The following creates a profile suitable for SNMP - it's exactly identical
590to 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
589our $DEFAULT_PROFILE = new Convert::BER::XS::Profile; 603our $DEFAULT_PROFILE = new Convert::BER::XS::Profile;
590our $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
608our $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
6021; 6161;
603 617
604=head2 LIMITATIONS/NOTES 618=head2 LIMITATIONS/NOTES
605 619
606This module can only en-/decode 64 bit signed and unsigned integers, and 620This module can only en-/decode 64 bit signed and unsigned integers, and

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines