Sha256: 793a9935d31f642a4d5d2361c20a155f8e8078a9e24f6b5d5c138d56dc7e0004

Contents?: true

Size: 947 Bytes

Versions: 7

Compression:

Stored size: 947 Bytes

Contents

# This file is part of PacketGen
# See https://github.com/sdaubert/packetgen for more informations
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
# This program is published under MIT license.

# frozen_string_literal: true

module PacketGen
  module Header
    class IP
      # Class to handle IP options
      # @author Sylvain Daubert
      class Options < Types::Array
        set_of Option

        HUMAN_SEPARATOR = ';'

        # Get binary string
        # @return [String]
        def to_s
          str = super
          if str.length % 4 != 0
            str += ([0] * (4 - (str.length % 4))).pack('C*')
          end
          str
        end

        private

        def record_from_hash(hsh)
          Option.build(hsh)
        end

        def real_type(opt)
          types = Option.types
          types.value?(opt.type) ? IP.const_get(types.key(opt.type)) : opt.class
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
packetgen-3.1.3 lib/packetgen/header/ip/options.rb
packetgen-3.1.2 lib/packetgen/header/ip/options.rb
packetgen-3.1.1 lib/packetgen/header/ip/options.rb
packetgen-3.1.0 lib/packetgen/header/ip/options.rb
packetgen-3.0.2 lib/packetgen/header/ip/options.rb
packetgen-3.0.1 lib/packetgen/header/ip/options.rb
packetgen-3.0.0 lib/packetgen/header/ip/options.rb