Sha256: a1502883a9801f4043e26f669a8206df62e5d51b3e4ea55a88f89d48efc22281

Contents?: true

Size: 1.81 KB

Versions: 13

Compression:

Stored size: 1.81 KB

Contents

require 'pio/icmp/message'
require 'pio/icmp/options'
require 'pio/mac'

module Pio
  class Icmp
    # ICMP Request packet generator
    class Request < Message
      TYPE = 8
      public_class_method :new

      # User options for creating an ICMP Request.
      class Options < Pio::Icmp::Options
        DEFAULT_IDENTIFIER = 0x0100
        DEFAULT_SEQUENCE_NUMBER = 0

        mandatory_option :source_mac
        mandatory_option :destination_mac
        mandatory_option :ip_source_address
        mandatory_option :ip_destination_address
        option :identifier
        option :sequence_number
        option :echo_data

        def initialize(user_options)
          @type = TYPE

          @options = user_options.dup
          validate @options
          set_mac_and_ip_address_options
          set_identifier_option
          set_sequence_number_option
          set_echo_data_option
        end

        private

        def set_mac_and_ip_address_options
          @source_mac = Mac.new(@options[:source_mac]).freeze
          @destination_mac = Mac.new(@options[:destination_mac]).freeze
          @ip_source_address =
            IPv4Address.new(@options[:ip_source_address]).freeze
          @ip_destination_address =
            IPv4Address.new(@options[:ip_destination_address]).freeze
        end

        def set_identifier_option
          @identifier =
            @options[:icmp_identifier] ||
            @options[:identifier] ||
            DEFAULT_IDENTIFIER
        end

        def set_sequence_number_option
          @sequence_number =
            @options[:icmp_sequence_number] ||
            @options[:sequence_number] ||
            DEFAULT_SEQUENCE_NUMBER
        end

        def set_echo_data_option
          @echo_data = (@options[:echo_data] || DEFAULT_ECHO_DATA).freeze
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pio-0.15.2 lib/pio/icmp/request.rb
pio-0.15.1 lib/pio/icmp/request.rb
pio-0.15.0 lib/pio/icmp/request.rb
pio-0.14.0 lib/pio/icmp/request.rb
pio-0.13.0 lib/pio/icmp/request.rb
pio-0.12.0 lib/pio/icmp/request.rb
pio-0.11.2 lib/pio/icmp/request.rb
pio-0.11.1 lib/pio/icmp/request.rb
pio-0.11.0 lib/pio/icmp/request.rb
pio-0.10.1 lib/pio/icmp/request.rb
pio-0.10.0 lib/pio/icmp/request.rb
pio-0.9.0 lib/pio/icmp/request.rb
pio-0.8.2 lib/pio/icmp/request.rb