Class Racket::L4::TCP
In: lib/racket/l4/tcp.rb  (CVS)
Parent: RacketPart

Transmission Control Protocol: TCP

RFC793 (www.faqs.org/rfcs/rfc793.html)

Methods

Attributes

ack    Acknowledgement number
checksum    Checksum
dst_port    Destination port
flag_ack    ACK
flag_cwr    CWR
flag_ece    ECE
flag_fin    FIN
flag_psh    PSH
flag_rst    RST
flag_syn    SYN
flag_urg    URG
offset    Data Offset
payload    Payload
reserved    Reserved
seq    Sequence number
src_port    Source port
urg    Urgent pointer
window    Window size

Public Class methods

[Source]

# File lib/racket/l4/tcp.rb, line 122
  def initialize(*args)
    @options = []
    super
    @autofix = false
  end

Public Instance methods

Add an TCP option to this TCP object. All rejiggering will happen when the call to fix! happens automagically. If the result is not on a 32-bit boundry, pad with NOPs.

[Source]

# File lib/racket/l4/tcp.rb, line 75
  def add_option(number, value)
    t = Misc::TLV.new(1,1)
    t.type = number
    t.value = value
    t.length = value.length + 2
    opts = t.encode
    opts += ("\x01" * (4-(opts.size % 4))) if (opts.size % 4) != 0
    @options << opts
  end

Add a raw TCP option to this packet. It is entirely your responsibility (or irresponsibility, as the case may be) to properly pad or otherwise define this

[Source]

# File lib/racket/l4/tcp.rb, line 88
  def add_raw_option(value)
    @options << value
  end

Compute and set the checksum for this TCP packet

[Source]

# File lib/racket/l4/tcp.rb, line 98
  def checksum!(ip_src, ip_dst)
    self.checksum = compute_checksum(ip_src, ip_dst)
  end

Check the checksum for this TCP packet

[Source]

# File lib/racket/l4/tcp.rb, line 93
  def checksum?(ip_src, ip_dst)
    self.checksum == compute_checksum(ip_src, ip_dst)
  end

Fix this packet up for proper sending. Sets the length and checksum properly.

[Source]

# File lib/racket/l4/tcp.rb, line 104
  def fix!(ip_src, ip_dst, next_payload)
    newpayload = @options.join
    
    # pad to a multiple of 32 bits
    if ((self.class.bit_length/8 + newpayload.length) % 4 != 0) 
      # fill the beginning as needed with NOPs
      while ((self.class.bit_length/8 + newpayload.length) % 4 != 4)
        puts (self.class.bit_length/8 + newpayload.length) % 4
        newpayload = "\x01#{newpayload}"
      end
    end

    self.payload = newpayload + self.payload + next_payload
    self.offset = self.class.bit_length/32 + newpayload.length/4
    self.checksum!(ip_src, ip_dst)
    self.payload = newpayload
  end

[Validate]