class PacketGen::Header::SNMP
Simple Network Management Protocol (SNMP
)
See github.com/sdaubert/packetgen/wiki/SNMP @author Sylvain Daubert @since 2.0.0
Constants
- ERRORS
rubocop:enable Naming/ConstantName
- PDU_BULK
- PDU_GET
rubocop:disable Naming/ConstantName
- PDU_INFORM
- PDU_NEXT
- PDU_REPORT
- PDU_RESPONSE
- PDU_SET
- PDU_TRAPv1
- PDU_TRAPv2
- UDP_PORT1
Agents listen to this port
- UDP_PORT2
Configuration sinks listen to this port
Public Class Methods
new(options={})
click to toggle source
@param [Hash] options @option options [Integer,String] :version @option options [String] :community @option options [Integer] :chosen_pdu Set PDU type @option options [Hash] :pdu Set PDU content
Calls superclass method
# File lib/packetgen/header/snmp.rb, line 262 def initialize(options={}) super data.chosen = options[:chosen_pdu] if options[:chosen_pdu] return unless options[:pdu] data.root.value[data.chosen] = data.root.chosen_value.class.new(options[:pdu]) end
Public Instance Methods
added_to_packet(packet)
click to toggle source
@api private @note This method is used internally by PacketGen
and should not be
directly called
@param [Packet] packet @return [void] @since 2.7.0 Set UDP
sport according to bindings, only if sport is 0.
Needed by new bind API.
# File lib/packetgen/header/snmp.rb, line 312 def added_to_packet(packet) return unless packet.is? 'UDP' return unless packet.udp.sport.zero? packet.udp.sport = packet.udp.dport end
data()
click to toggle source
accessor to data payload @return [GetRequest]
# File lib/packetgen/header/snmp.rb, line 272 def data @elements[:data] end
inspect()
click to toggle source
Calls superclass method
PacketGen::Header::ASN1Base#inspect
# File lib/packetgen/header/snmp.rb, line 286 def inspect str = super str << Inspect.shift_level if self[:data].chosen.nil? str << Inspect::FMT_ATTR % [self[:data].type, :data, ''] else data = self[:data] str << Inspect::FMT_ATTR % [data.type, :data, data.chosen_value.type] str << Inspect.dashed_line('ASN.1 content') str << data.chosen_value.inspect(1) begin str << Inspect.inspect_body(self[:message].to_der, 'ASN.1 DER') rescue StandardError => e raise unless e.message.match?(/TAG.*not handled/) end str end end