Class: Scriptroute::TCP

Inherits:
IPv4
  • Object
show all
Defined in:
lib/scriptroute/packets.rb,
lib/scriptroute/packets.rb

Constant Summary collapse

TH_FIN =
0x01
TH_SYN =
0x02
TH_RST =
0x04
TH_PUSH =
0x08
TH_ACK =
0x10
TH_URG =
0x20

Constants inherited from IPv4

IPv4::IPPROTO_ICMP

Constants inherited from IP

IP::IPPROTO_TCP, IP::IPPROTO_UDP

Instance Attribute Summary collapse

Attributes inherited from IPv4

#ip_dst, #ip_hl, #ip_id, #ip_len, #ip_off, #ip_options, #ip_src, #ip_sum, #ip_tos, #ip_ttl, #ip_v

Instance Method Summary collapse

Methods inherited from IPv4

#add_option, #calculate_header_len, #calculate_packet_len, creator, #ipv4_unmarshal, #to_s

Methods inherited from IP

creator, #to_bytes

Constructor Details

#initialize(paylen_or_str = 0) ⇒ TCP

Returns a new instance of TCP.



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
# 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

Instance Attribute Details

#flag_ackObject

flags don’t work



625
626
627
# File 'lib/scriptroute/packets.rb', line 625

def flag_ack
  @flag_ack
end

#flag_finObject

flags don’t work



625
626
627
# File 'lib/scriptroute/packets.rb', line 625

def flag_fin
  @flag_fin
end

#flag_pushObject

flags don’t work



625
626
627
# File 'lib/scriptroute/packets.rb', line 625

def flag_push
  @flag_push
end

#flag_rstObject

flags don’t work



625
626
627
# File 'lib/scriptroute/packets.rb', line 625

def flag_rst
  @flag_rst
end

#flag_synObject

flags don’t work



625
626
627
# File 'lib/scriptroute/packets.rb', line 625

def flag_syn
  @flag_syn
end

#flag_urgObject

flags don’t work



625
626
627
# File 'lib/scriptroute/packets.rb', line 625

def flag_urg
  @flag_urg
end

#ip_pFixnum (readonly)

Returns:

  • (Fixnum)


633
634
635
# File 'lib/scriptroute/packets.rb', line 633

def ip_p
  @ip_p
end

#ip_payload_lenFixnum (readonly)

Returns:

  • (Fixnum)


633
634
635
# File 'lib/scriptroute/packets.rb', line 633

def ip_payload_len
  @ip_payload_len
end

#th_ackObject

Returns the value of attribute th_ack.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_ack
  @th_ack
end

#th_dportObject

Returns the value of attribute th_dport.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_dport
  @th_dport
end

#th_flagsObject

Returns the value of attribute th_flags.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_flags
  @th_flags
end

#th_seqObject

Returns the value of attribute th_seq.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_seq
  @th_seq
end

#th_sportObject (readonly)

Returns the value of attribute th_sport.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_sport
  @th_sport
end

#th_sumObject

Returns the value of attribute th_sum.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_sum
  @th_sum
end

#th_urpObject (readonly)

Returns the value of attribute th_urp.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_urp
  @th_urp
end

#th_winObject

Returns the value of attribute th_win.



622
623
624
# File 'lib/scriptroute/packets.rb', line 622

def th_win
  @th_win
end

Instance Method Details

#marshalString

Returns The packet in string form.

Returns:

  • (String)

    The packet in string form



657
658
659
660
661
662
# 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