Sha256: 03241325635a53c033c75ddc58538b0af317f94976fa89cf0f688ea18e927b58

Contents?: true

Size: 979 Bytes

Versions: 2

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

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

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
          str += ([0] * (4 - (str.length % 4))).pack('C*') if str.length % 4 != 0
          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

2 entries across 2 versions & 1 rubygems

Version Path
packetgen-3.3.3 lib/packetgen/header/ip/options.rb
packetgen-3.3.2 lib/packetgen/header/ip/options.rb