1- class SNMP::V1Trap < SNMP::Trap
1+ # An RFC 1157 Trap-PDU. It is its own variant of the protocol's PDU CHOICE —
2+ # not an SNMPv2 trap — so it derives from PDU directly and carries the v1
3+ # fields (enterprise, agent address, generic/specific trap, timestamp) itself.
4+ # The v2-style request-id / error fields inherited from PDU have no meaning in
5+ # a v1 trap and stay at their defaults.
6+ class SNMP::V1Trap < SNMP::PDU
27 def initialize (ber : ASN1 ::BER )
38 pdu = SNMP .ber_fields(ber, 6 , " v1 trap" )
4- @oid = pdu[0 ].get_object_id
9+ @enterprise = pdu[0 ].get_object_id
510 @agent_address = pdu[1 ].payload.join(" ." )
611 @generic_trap = SNMP .decode_enum(GenericTrap , pdu[2 ].get_integer, " generic-trap" )
712 @specific_trap = pdu[3 ].get_integer.to_i32
@@ -10,25 +15,26 @@ class SNMP::V1Trap < SNMP::Trap
1015 VarBind .new(varbind)
1116 end
1217
13- # Compatibility with regular PDUs
14- # V1 traps are very different: https://tools.ietf.org/html/rfc1157#page-27
18+ # The v2-style PDU fields do not exist on the v1 wire
1519 @request_id = 0
1620 @error_status = ErrorStatus ::NoError
1721 @error_index = 0
1822 end
1923
24+ property enterprise : String
2025 property agent_address : String
2126 property generic_trap : GenericTrap
2227 property specific_trap : Int32
28+ property time_ticks : UInt32
2329
24- def initialize (@agent_address , @generic_trap , @specific_trap , ** args )
25- super (** args )
30+ def initialize (@agent_address , @generic_trap , @specific_trap = 0 , @enterprise = " " , @time_ticks = 0 _ u32 , varbinds : Array ( VarBind ) = [] of VarBind , request_id = 0 )
31+ super (request_id, varbinds )
2632 end
2733
2834 # RFC 1157 Trap-PDU wire structure — distinct from the standard PDU layout, so
29- # this overrides `PDU#to_ber`. `@oid` holds the enterprise OID.
35+ # this overrides `PDU#to_ber`.
3036 def to_ber (tag_number )
31- enterprise = ASN1 ::BER .new.set_object_id(@oid )
37+ enterprise = ASN1 ::BER .new.set_object_id(@enterprise )
3238 agent = IpAddress .new(@agent_address ).to_ber
3339 generic = ASN1 ::BER .new.set_integer(@generic_trap .to_i)
3440 specific = ASN1 ::BER .new.set_integer(@specific_trap )
0 commit comments