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, IPv4::IPPROTO_TCP, IPv4::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

Constructor Details

#initialize(paylen_or_str = 0) ⇒ TCP

Returns a new instance of TCP.



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

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



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

def flag_ack
  @flag_ack
end

#flag_finObject

flags don’t work



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

def flag_fin
  @flag_fin
end

#flag_pushObject

flags don’t work



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

def flag_push
  @flag_push
end

#flag_rstObject

flags don’t work



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

def flag_rst
  @flag_rst
end

#flag_synObject

flags don’t work



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

def flag_syn
  @flag_syn
end

#flag_urgObject

flags don’t work



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

def flag_urg
  @flag_urg
end

#ip_pFixnum (readonly)

Returns:

  • (Fixnum)


483
484
485
# File 'lib/scriptroute/packets.rb', line 483

def ip_p
  @ip_p
end

#ip_payload_lenFixnum (readonly)

Returns:

  • (Fixnum)


483
484
485
# File 'lib/scriptroute/packets.rb', line 483

def ip_payload_len
  @ip_payload_len
end

#th_ackObject

Returns the value of attribute th_ack.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_ack
  @th_ack
end

#th_dportObject

Returns the value of attribute th_dport.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_dport
  @th_dport
end

#th_flagsObject

Returns the value of attribute th_flags.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_flags
  @th_flags
end

#th_seqObject

Returns the value of attribute th_seq.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_seq
  @th_seq
end

#th_sportObject (readonly)

Returns the value of attribute th_sport.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_sport
  @th_sport
end

#th_sumObject

Returns the value of attribute th_sum.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_sum
  @th_sum
end

#th_urpObject (readonly)

Returns the value of attribute th_urp.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_urp
  @th_urp
end

#th_winObject

Returns the value of attribute th_win.



472
473
474
# File 'lib/scriptroute/packets.rb', line 472

def th_win
  @th_win
end

Instance Method Details

#marshalString

Returns The packet in string form.

Returns:

  • (String)

    The packet in string form



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

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