Sha256: 5d77d42cabfd72dd19976ebdb8d14f82372cc6087ce84520337e9ae41f6934b6

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

require 'bindata'
require 'forwardable'
require 'pio/type/mac_address'

module Pio
  # An action to modify the source/destination Ethernet address of a packet.
  class SetEthAddr
    # rubocop:disable MethodLength
    def self.def_format(action_type)
      str = %(
        class Format < BinData::Record
          endian :big

          uint16 :type, value: #{action_type}
          uint16 :message_length, value: 16
          mac_address :mac_address
          uint48 :padding
          hide :padding
        end
      )
      module_eval str
    end
    # rubocop:enable MethodLength

    def self.read(raw_data)
      set_eth_addr = allocate
      set_eth_addr.instance_variable_set(:@format,
                                         const_get(:Format).read(raw_data))
      set_eth_addr
    end

    extend Forwardable

    def_delegators :@format, :message_length
    def_delegators :@format, :mac_address
    def_delegator :@format, :to_binary_s, :to_binary

    def initialize(mac_address)
      @format = self.class.const_get(:Format).new(mac_address: mac_address)
    end
  end

  # An action to modify the source Ethernet address of a packet.
  class SetEthSrcAddr < SetEthAddr
    def_format 4
  end

  # An action to modify the destination Ethernet address of a packet.
  class SetEthDstAddr < SetEthAddr
    def_format 5
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pio-0.19.0 lib/pio/set_eth_addr.rb
pio-0.18.2 lib/pio/set_eth_addr.rb
pio-0.18.1 lib/pio/set_eth_addr.rb
pio-0.18.0 lib/pio/set_eth_addr.rb
pio-0.17.0 lib/pio/set_eth_addr.rb
pio-0.16.0 lib/pio/set_eth_addr.rb
pio-0.15.2 lib/pio/set_eth_addr.rb
pio-0.15.1 lib/pio/set_eth_addr.rb
pio-0.15.0 lib/pio/set_eth_addr.rb
pio-0.14.0 lib/pio/set_eth_addr.rb
pio-0.13.0 lib/pio/set_eth_addr.rb
pio-0.12.0 lib/pio/set_eth_addr.rb
pio-0.11.2 lib/pio/set_eth_addr.rb
pio-0.11.1 lib/pio/set_eth_addr.rb
pio-0.11.0 lib/pio/set_eth_addr.rb
pio-0.10.1 lib/pio/set_eth_addr.rb
pio-0.10.0 lib/pio/set_eth_addr.rb