… | |
… | |
23 | =over 4 |
23 | =over 4 |
24 | |
24 | |
25 | =item overriding internal functions might cause the module to |
25 | =item overriding internal functions might cause the module to |
26 | malfunction with future versions of Net::SNMP |
26 | malfunction with future versions of Net::SNMP |
27 | |
27 | |
28 | =item only leading dots for oids are supported |
|
|
29 | |
|
|
30 | =item error messages will be simpler/different |
28 | =item error messages will be simpler/different |
31 | |
|
|
32 | =item oid components are limited to unsigned 32 bit integers |
|
|
33 | |
29 | |
34 | =item translation will be ignored (all values will be delivered "raw") |
30 | =item translation will be ignored (all values will be delivered "raw") |
35 | |
31 | |
36 | =item a 64 bit perl is required |
|
|
37 | |
|
|
38 | =item a moderately modern (>= C99) C compiler is required |
32 | =item a moderately modern (>= C99) C compiler is required |
39 | |
33 | |
40 | =item only tested with 5.10 |
34 | =item only tested with 5.10, no intentions to port to older perls |
41 | |
35 | |
42 | =item duplicate OIDs are not supported |
36 | =item duplicate OIDs are not supported |
43 | |
37 | |
44 | =item REPORT PDUs are not supported |
38 | =item REPORT PDUs are not supported |
45 | |
39 | |
… | |
… | |
52 | use strict qw(vars subs); |
46 | use strict qw(vars subs); |
53 | no warnings; |
47 | no warnings; |
54 | |
48 | |
55 | use Guard; |
49 | use Guard; |
56 | |
50 | |
|
|
51 | use Net::SNMP (); |
57 | use Net::SNMP::PDU (); |
52 | use Net::SNMP::PDU (); |
58 | use Net::SNMP::Message (); |
53 | use Net::SNMP::Message (); |
59 | use Net::SNMP::MessageProcessing (); |
54 | use Net::SNMP::MessageProcessing (); |
60 | |
55 | |
61 | our $VERSION; |
56 | our $VERSION; |
62 | our $old_prepare; |
57 | our $old_prepare; |
63 | |
58 | |
64 | BEGIN { |
59 | BEGIN { |
65 | $VERSION = '0.01'; |
60 | $VERSION = '0.03'; |
66 | |
61 | |
67 | $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements; |
62 | $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements; |
68 | |
63 | |
69 | # this overrides many methods inside |
64 | # this overrides many methods inside |
70 | require XSLoader; |
65 | require XSLoader; |
… | |
… | |
77 | set_msg $msg, $msg->{_buffer}; |
72 | set_msg $msg, $msg->{_buffer}; |
78 | scope_guard \&clr_msg; |
73 | scope_guard \&clr_msg; |
79 | &$old_prepare |
74 | &$old_prepare |
80 | } |
75 | } |
81 | |
76 | |
|
|
77 | package Net::SNMP::Message; |
|
|
78 | |
|
|
79 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
|
|
80 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
|
|
81 | Net::SNMP::XS::set_type NULL , \&_process_null; |
|
|
82 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
|
|
83 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
|
|
84 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
|
|
85 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
|
|
86 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
|
|
87 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
|
|
88 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
|
|
89 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
|
|
90 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
|
|
91 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
|
|
92 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
|
|
93 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
|
|
94 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
|
|
95 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
|
|
96 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
|
|
97 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
|
|
98 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
|
|
99 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
|
|
100 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
|
|
101 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
|
|
102 | |
|
|
103 | package Net::SNMP::PDU; |
|
|
104 | |
|
|
105 | # var_bind_list hardcodes oid_lext_sort. *sigh* |
|
|
106 | # we copy it 1:1, except for using oid_lex_sort. |
|
|
107 | |
|
|
108 | sub var_bind_list |
82 | { |
109 | { |
83 | package Net::SNMP::Message; |
110 | my ($this, $vbl, $types) = @_; |
84 | |
111 | |
85 | Net::SNMP::XS::set_type INTEGER , \&_process_integer32; |
112 | return if defined($this->{_error}); |
86 | Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string; |
113 | |
87 | Net::SNMP::XS::set_type NULL , \&_process_null; |
114 | if (@_ > 1) { |
88 | Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier; |
115 | # The VarBindList HASH is being updated from an external |
89 | Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence; |
116 | # source. We need to update the VarBind names ARRAY to |
90 | Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress; |
117 | # correspond to the new keys of the HASH. If the updated |
91 | Net::SNMP::XS::set_type COUNTER , \&_process_counter; |
118 | # information is valid, we will use lexicographical ordering |
92 | Net::SNMP::XS::set_type GAUGE , \&_process_gauge; |
119 | # for the ARRAY entries since we do not have a PDU to use |
93 | Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks; |
120 | # to determine the ordering. The ASN.1 types HASH is also |
94 | Net::SNMP::XS::set_type OPAQUE , \&_process_opaque; |
121 | # updated here if a cooresponding HASH is passed. We double |
95 | Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64; |
122 | # check the mapping by populating the hash with the keys of |
96 | Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject; |
123 | # the VarBindList HASH. |
97 | Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance; |
124 | |
98 | Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview; |
125 | if (!defined($vbl) || (ref($vbl) ne 'HASH')) { |
99 | Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request; |
126 | |
100 | Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request; |
127 | $this->{_var_bind_list} = undef; |
101 | Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response; |
128 | $this->{_var_bind_names} = []; |
102 | Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request; |
129 | $this->{_var_bind_types} = undef; |
103 | Net::SNMP::XS::set_type TRAP , \&_process_trap; |
130 | |
104 | Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request; |
131 | } else { |
105 | Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request; |
132 | |
106 | Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap; |
133 | $this->{_var_bind_list} = $vbl; |
107 | Net::SNMP::XS::set_type REPORT , \&_process_report; |
134 | |
|
|
135 | @{$this->{_var_bind_names}} = Net::SNMP::oid_lex_sort keys %$vbl; |
|
|
136 | |
|
|
137 | if (!defined($types) || (ref($types) ne 'HASH')) { |
|
|
138 | $types = {}; |
|
|
139 | } |
|
|
140 | |
|
|
141 | map { |
|
|
142 | $this->{_var_bind_types}->{$_} = |
|
|
143 | exists($types->{$_}) ? $types->{$_} : undef; |
|
|
144 | } keys(%{$vbl}); |
|
|
145 | |
|
|
146 | } |
|
|
147 | |
|
|
148 | } |
|
|
149 | |
|
|
150 | $this->{_var_bind_list}; |
108 | } |
151 | } |
109 | |
152 | |
110 | 1; |
153 | 1; |
111 | |
154 | |
112 | =head1 AUTHOR |
155 | =head1 AUTHOR |