class Scriptroute::TCP

Constants

TH_ACK
TH_FIN
TH_PUSH
TH_RST
TH_SYN
TH_URG

Attributes

flag_ack[RW]

flags don’t work

flag_fin[RW]

flags don’t work

flag_push[RW]

flags don’t work

flag_rst[RW]

flags don’t work

flag_syn[RW]

flags don’t work

flag_urg[RW]

flags don’t work

ip_p[R]

@return [Fixnum]

ip_payload_len[R]

@return [Fixnum]

th_ack[RW]
th_dport[RW]
th_flags[RW]
th_seq[RW]
th_sport[R]
th_sum[RW]
th_urp[R]
th_win[RW]

Public Class Methods

new(paylen_or_str = 0) click to toggle source
Calls superclass method Scriptroute::IPv4::new
# File lib/scriptroute/packets.rb, line 639
def initialize(paylen_or_str = 0)
  if(paylen_or_str.is_a?(Fixnum)) then
    @ip_payload_len = paylen_or_str + 20 # tcp header
    @ip_p = IPPROTO_TCP
    @th_dport = 80
    @th_sport = 0 # should be set by the daemon
    @th_seq = 0 # should be set by the user, rand likely
    @th_ack = 0 # should be set by the user, rand likely
    @th_flags = TH_ACK # should be left alone, but could be set.
    @th_win   = 5180 # linux default.
    @th_urp   = 0 # not supported
    @th_sum   = 0 # should be set by the daemon
    super(IPPROTO_TCP)
  else
    @th_sport, @th_dport, @th_seq, @th_ack, reserved, @th_flags, @th_win, @th_sum, @th_urp = paylen_or_str.unpack("nnNNCCnnn")
  end
end

Public Instance Methods

marshal() click to toggle source

@return [String] The packet in string form

Calls superclass method Scriptroute::IPv4#marshal
# File lib/scriptroute/packets.rb, line 657
def marshal
  array_of_elements = [ @th_sport, @th_dport, @th_seq, @th_ack, 0x50, @th_flags, @th_win, @th_sum, @th_urp ]
  raise "a TCP header field #{array_of_elements.index(nil)} was unset" if array_of_elements.include?(nil)
  super + array_of_elements.pack("nnNNCCnnn")
  # TODO plus payload length
end