ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-BER-XS/XS.pm
Revision: 1.1
Committed: Fri Apr 19 16:19:36 2019 UTC (5 years, 1 month ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Convert::BER::XS - I<very> low level BER decoding
4    
5     =head1 SYNOPSIS
6    
7     use Convert::BER::XS ':all';
8    
9     my $ber = ber_decode $buf
10     or die "unable to decode SNMP v1/v2c Message";
11    
12     my $msg = ber_is_seq $ber
13     or die "SNMP message does not start with a sequence";
14    
15     ber_is $msg->[0], ASN_UNIVERSAL, ASN_INTEGER32, 0
16     or die "SNMP message does not start with snmp version\n";
17    
18     if ($msg->[0][BER_DATA] == 0 || $msg->[0][BER_DATA] == 1) {
19     # message is SNMP v1 or v2c
20    
21     if (ber_is $msg->[2], ASN_CONTEXT, 4, 1) {
22     # message is v1 trap
23     my $trap = $msg->[2][BER_DATA];
24    
25     # check whether trap is a cisco mac notification mac changed message
26     if (
27     (ber_is_oid $trap->[0], "1.3.6.1.4.1.9.9.215.2") # cmnInterfaceObjects
28     and (ber_is_i32 $trap->[2], 6)
29     and (ber_is_i32 $trap->[3], 1) # mac changed msg
30     ) {
31     ... and so on
32    
33     =head1 DESCRIPTION
34    
35     This module implements a I<very> low level BER/DER decoder, and in the
36     future, probably also an encoder (tell me if you want an encoder, this
37     might speed up the process of getting one).
38    
39     If is tuned for low memory and high speed, while still maintaining some
40     level of user-friendlyness.
41    
42     Currently, not much is documented, as this is an initial release to
43     reserve CPAN namespace, stay tuned for a few days.
44    
45     =cut
46    
47     package Convert::BER::XS;
48    
49     use common::sense;
50    
51     use XSLoader ();
52     use Exporter qw(import);
53    
54     our $VERSION = '0.0';
55    
56     XSLoader::load __PACKAGE__, $VERSION;
57    
58     our %EXPORT_TAGS = (
59     all => [qw(
60     ber_decode
61     ber_is ber_is_seq ber_is_i32 ber_is_oid
62     BER_CLASS BER_TAG BER_CONSTRUCTED BER_DATA
63     ASN_BOOLEAN ASN_INTEGER32 ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OBJECT_IDENTIFIER ASN_TAG_BER ASN_TAG_MASK
64     ASN_CONSTRUCTED ASN_UNIVERSAL ASN_APPLICATION ASN_CONTEXT ASN_PRIVATE ASN_CLASS_MASK ASN_CLASS_SHIFT
65     ASN_SEQUENCE ASN_IPADDRESS ASN_COUNTER32 ASN_UNSIGNED32 ASN_TIMETICKS ASN_OPAQUE ASN_COUNTER64
66     )],
67     );
68    
69     our @EXPORT_OK = map @$_, values %EXPORT_TAGS;
70    
71     1;
72    
73     =head1 AUTHOR
74    
75     Marc Lehmann <schmorp@schmorp.de>
76     http://software.schmorp.de/pkg/Convert-BER-XS
77    
78     =cut
79