class PacketGen::Header::TCP::Option

Base class to describe a TCP option @author Sylvain Daubert

Constants

ECHOREPLY_KIND

ECHOREPLY option value

ECHO_KIND

ECHO option value

EOL_KIND

EOL option value

MSS_KIND

MSS option value

NOP_KIND

NOP option value

SACKOK_KIND

SACKOK option value

SACK_KIND

SACK option value

TS_KIND

TS option value

WS_KIND

WS option value

Public Class Methods

new(options={}) click to toggle source

@param [hash] options @option options [Integer] :kind @option options [Integer] :length @option options [Integer,String] :value

Calls superclass method
# File lib/packetgen/header/tcp/option.rb, line 52
def initialize(options={})
  super
  case options[:value]
  when Integer
    klass = case self[:length].to_i
            when 3 then Types::Int8
            when 4 then Types::Int16
            when 6 then Types::Int32
            else
              raise ArgumentError, 'impossible length'
            end
    self[:value] = klass.new(options[:value])
  when NilClass
    # Nothing to do
  else
    self[:value] = Types::String.new.read(options[:value])
    self[:length].read(self[:value].sz + 2) unless options[:length]
  end
end

Public Instance Methods

inspect() click to toggle source

@return [String]

# File lib/packetgen/header/tcp/option.rb, line 123
def inspect
  str = +"#<#{self.class} kind=#{self[:kind].value.inspect} "
  str << "length=#{self[:length].value.inspect} " if self[:length].value
  str << "value=#{self[:value].inspect}>"
end
length?() click to toggle source

Say if given option has a length field. @return [Boolean] @since 2.7.0

# File lib/packetgen/header/tcp/option.rb, line 75
def length?
  kind >= 2
end
old_set_value(val)
Alias for: value=
to_human() click to toggle source

Get option as a human readable string @return [String]

# File lib/packetgen/header/tcp/option.rb, line 116
def to_human
  str = self.instance_of?(Option) ? +"unk-#{kind}" : self.class.to_s.sub(/.*::/, '')
  str << ":#{self[:value].to_s.inspect}" if (length > 2) && !self[:value].to_s.empty?
  str
end
to_s() click to toggle source

Get binary string @return [String]

Calls superclass method PacketGen::Types::Fieldable#to_s
# File lib/packetgen/header/tcp/option.rb, line 109
def to_s
  self.length = 2 + self[:value].sz if length?
  super
end
value() click to toggle source

Getter for value attribute @return [String, Integer]

# File lib/packetgen/header/tcp/option.rb, line 83
def value
  case self[:value]
  when Types::Int
    self[:value].to_i
  else
    self[:value].to_s
  end
end
value=(val) click to toggle source

Setter for value attribute @param @return [String, Integer]

# File lib/packetgen/header/tcp/option.rb, line 96
def value=(val)
  case self[:value]
  when Types::Int
    self.length = 2 + self[:value].sz
  when Types::String
    self.length = 2 + Types::String.new.read(val).sz
  end
  self[:value].read val
  val
end
Also aliased as: old_set_value