Class: Racket::L4::TCP
- Inherits:
-
RacketPart
- Object
- BitStruct
- RacketPart
- Racket::L4::TCP
- Defined in:
- lib/racket/l4/tcp.rb
Overview
RFC793 (www.faqs.org/rfcs/rfc793.html)
Instance Attribute Summary
Attributes inherited from RacketPart
Instance Method Summary collapse
-
#add_option(number, value) ⇒ Object
Add an TCP option to this TCP object.
-
#add_raw_option(value) ⇒ Object
Add a raw TCP option to this packet.
-
#checksum!(ip_src, ip_dst) ⇒ Object
Compute and set the checksum for this TCP packet.
-
#checksum?(ip_src, ip_dst) ⇒ Boolean
Check the checksum for this TCP packet.
-
#fix!(ip_src, ip_dst, next_payload) ⇒ Object
Fix this packet up for proper sending.
-
#initialize(*args) ⇒ TCP
constructor
A new instance of TCP.
Methods inherited from RacketPart
Constructor Details
#initialize(*args) ⇒ TCP
Returns a new instance of TCP.
122 123 124 125 126 |
# File 'lib/racket/l4/tcp.rb', line 122 def initialize(*args) @options = [] super @autofix = false end |
Instance Method Details
#add_option(number, value) ⇒ Object
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.
75 76 77 78 79 80 81 82 83 |
# 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_raw_option(value) ⇒ Object
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
88 89 90 |
# File 'lib/racket/l4/tcp.rb', line 88 def add_raw_option(value) @options << value end |
#checksum!(ip_src, ip_dst) ⇒ Object
Compute and set the checksum for this TCP packet
98 99 100 |
# File 'lib/racket/l4/tcp.rb', line 98 def checksum!(ip_src, ip_dst) self.checksum = compute_checksum(ip_src, ip_dst) end |
#checksum?(ip_src, ip_dst) ⇒ Boolean
Check the checksum for this TCP packet
93 94 95 |
# File 'lib/racket/l4/tcp.rb', line 93 def checksum?(ip_src, ip_dst) self.checksum == compute_checksum(ip_src, ip_dst) end |
#fix!(ip_src, ip_dst, next_payload) ⇒ Object
Fix this packet up for proper sending. Sets the length and checksum properly.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# 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 |