Class: Scriptroute::Timestamp_option

Inherits:
IPv4option show all
Defined in:
lib/scriptroute/packets.rb

Overview

The IPv4 timestamp option, which can determine routers

Constant Summary

Constants inherited from IPv4option

IPv4option::IPOPT_EOL, IPv4option::IPOPT_EOOL, IPv4option::IPOPT_NOOP, IPv4option::IPOPT_RR, IPv4option::IPOPT_TIMESTAMP, IPv4option::IPOPT_TS, IPv4option::IPOPT_TS_PRESPEC, IPv4option::IPOPT_TS_TSANDADDR, IPv4option::IPOPT_TS_TSONLY

Instance Attribute Summary collapse

Attributes inherited from IPv4option

#ipt_code, #ipt_len, #ipt_ptr

Instance Method Summary collapse

Methods inherited from IPv4option

creator, #to_s

Constructor Details

#initialize(flag_or_str) ⇒ Timestamp_option

Returns a new instance of Timestamp_option.



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/scriptroute/packets.rb', line 484

def initialize(flag_or_str)
  if(flag_or_str.is_a?(Fixnum)) then
    @routers = Array.new
    @times = Array.new
    @ts_flag = flag_or_str
    super(IPOPT_TS, 36, 5) # maximum length is 40, but tcpdump whines.
  else
    ipt_code, ipt_len, ipt_ptr, ipt_of_fl = flag_or_str.unpack("CCCC");
    @ts_flag = ipt_of_fl & 0x0f
    @ts_overflow = (ipt_of_fl & 0xf0) >> 4
    @routers, @times = 
      case @ts_flag 
      when IPOPT_TS_TSONLY
        [ nil, flag_or_str.unpack("xxxxN*") ]
      when IPOPT_TS_TSANDADDR,  IPOPT_TS_PRESPEC
        all = flag_or_str.unpack("xxxxN*")
        [ all.even_subscripts[0...ipt_len/8].map { |rtr| IPaddress.new(rtr) }, 
          all.odd_subscripts[0...(ipt_len/8)] ] 
      else
        raise "bad timestamp flag: #{@ts_flag} (code: #{ipt_code}, len: #{ipt_len}, ptr: #{ipt_ptr})"
      end
    super( flag_or_str )
  end
end

Instance Attribute Details

#routersArray<IPaddress>? (readonly)

Returns:



478
479
480
# File 'lib/scriptroute/packets.rb', line 478

def routers
  @routers
end

#timesArray<Fixnum> (readonly)

Returns:



480
481
482
# File 'lib/scriptroute/packets.rb', line 480

def times
  @times
end

#ts_flagFixnum (readonly)

Returns:

  • (Fixnum)


476
477
478
# File 'lib/scriptroute/packets.rb', line 476

def ts_flag
  @ts_flag
end

#ts_overflowFixnum (readonly)

Returns:

  • (Fixnum)


476
477
478
# File 'lib/scriptroute/packets.rb', line 476

def ts_overflow
  @ts_overflow
end

Instance Method Details

#marshalString

Returns the option in string form.

Returns:

  • (String)

    the option in string form



509
510
511
512
# File 'lib/scriptroute/packets.rb', line 509

def marshal
  super + [ @ts_flag ].pack("c") + # oflw will be init'd to zero
    Array.new(@ipt_len - 4, 0).pack("c*")
end