Class: Racket::L4::UDP

Inherits:
RacketPart show all
Defined in:
lib/racket/l4/udp.rb

Overview

Instance Attribute Summary

Attributes inherited from RacketPart

#autofix

Instance Method Summary collapse

Methods inherited from RacketPart

#autofix?, #pretty

Constructor Details

#initialize(*args) ⇒ UDP

Returns a new instance of UDP.



64
65
66
67
# File 'lib/racket/l4/udp.rb', line 64

def initialize(*args)
  super
  @autofix = false
end

Instance Method Details

#checksum!(src_ip, dst_ip) ⇒ Object

Compute and set the checksum for this UDP datagram



51
52
53
54
55
# File 'lib/racket/l4/udp.rb', line 51

def checksum!(src_ip, dst_ip)
  # set the checksum to 0 for usage in the pseudo header...
  self.checksum = 0
  self.checksum = compute_checksum(src_ip, dst_ip)
end

#checksum?(src_ip, dst_ip) ⇒ Boolean

Check the checksum for this UDP datagram

Returns:

  • (Boolean)


46
47
48
# File 'lib/racket/l4/udp.rb', line 46

def checksum?(src_ip, dst_ip)
  self.checksum == 0 || (self.checksum == compute_checksum(src_ip, dst_ip))
end

#fix!(src_ip, dst_ip) ⇒ Object

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



59
60
61
62
# File 'lib/racket/l4/udp.rb', line 59

def fix!(src_ip, dst_ip)
  self.len = self.class.bit_length/8 + self.payload.length
  self.checksum!(src_ip, dst_ip)
end