Class: PacketFu::TcpOption::TS
- Inherits:
-
PacketFu::TcpOption
- Object
- Struct
- PacketFu::TcpOption
- PacketFu::TcpOption::TS
- Defined in:
- lib/packetfu/protos/tcp/option.rb
Overview
Timestamp option
Instance Attribute Summary
Attributes inherited from PacketFu::TcpOption
Instance Method Summary collapse
-
#decode ⇒ Object
TS options with lengths other than 10 are malformed.
-
#encode(str) ⇒ Object
TS options are in the format of “TS:[timestamp value];[timestamp secret]” Both should be written as decimal numbers.
-
#initialize(args = {}) ⇒ TS
constructor
A new instance of TS.
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
Constructor Details
Instance Method Details
#decode ⇒ Object
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 |