Class: PacketFu::TcpOption::TS

Inherits:
PacketFu::TcpOption show all
Defined in:
lib/packetfu/protos/tcp/option.rb

Overview

Instance Attribute Summary

Attributes inherited from PacketFu::TcpOption

#kind, #optlen, #value

Instance Method Summary collapse

Methods inherited from PacketFu::TcpOption

#has_optlen?, #has_value?, #read, #to_s

Methods included from StructFu

#body=, #clone, #set_endianness, #sz, #typecast

Methods inherited from Struct

#force_binary

Constructor Details

#initialize(args = {}) ⇒ TS

Returns a new instance of TS


288
289
290
291
292
293
294
295
# File 'lib/packetfu/protos/tcp/option.rb', line 288

def initialize(args={})
  super(
    args.merge(:kind => 8,
               :optlen => 10
              )
  )
  self[:value] = StructFu::String.new.read(args[:value] || "\x00" * 8) 
end

Instance Method Details

#decodeObject

TS options with lengths other than 10 are malformed.


298
299
300
301
302
303
304
305
# File 'lib/packetfu/protos/tcp/option.rb', line 298

def decode
  if self[:optlen].to_i == 10
    val1,val2 = self[:value].unpack("NN")
    "TS:#{val1};#{val2}"
  else
    "TS-bad:#{self[:value]}"
  end
end

#encode(str) ⇒ Object

TS options are in the format of “TS:[timestamp value];[timestamp secret]” Both should be written as decimal numbers.


309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/packetfu/protos/tcp/option.rb', line 309

def encode(str)
  if str =~ /^([0-9]+);([0-9]+)$/
    tsval,tsecr = str.split(";").map {|x| x.to_i}
    if tsval <= 0xffffffff && tsecr <= 0xffffffff
      self[:value] = StructFu::String.new([tsval,tsecr].pack("NN"))
    else
      self[:value] = StructFu::String.new(str)
    end
  else
    self[:value] = StructFu::String.new(str)
  end
end