Class: Xlat::Protocols::Udp

Inherits:
Tcpudp
  • Object
show all
Defined in:
lib/xlat/protocols/udp.rb

Constant Summary collapse

PROTOCOL_ID =
17
CHECKSUM_OFFSET =
6

Instance Method Summary collapse

Methods inherited from Tcpudp

#_adjust_checksum, #initialize, #tuple

Methods included from Common

sum16be

Constructor Details

This class inherits a constructor from Xlat::Protocols::Tcpudp

Instance Method Details

#apply(cs_delta) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xlat/protocols/udp.rb', line 44

def apply(cs_delta)
  return if cs_delta.zero?

  packet = @packet
  return if packet.l4_bytes_length < 8

  bytes = packet.l4_bytes
  offset = packet.l4_bytes_offset

  checksum = bytes.get_value(:U16, offset + 6)
  return if checksum == 0 # TODO: in ipv6 this requires calculation

  checksum = 0 if checksum == 0xFFFF
  checksum = _adjust_checksum(checksum, cs_delta)
  checksum = 0xFFFF if checksum == 0

  bytes.set_value(:U16, offset + 6, checksum)
end

#parseObject



34
35
36
37
38
39
40
41
42
# File 'lib/xlat/protocols/udp.rb', line 34

def parse
  packet = @packet
  return nil if packet.l4_bytes_length < (@icmp_payload ? 4 : 8)

  # bytes = packet.l4_bytes
  # offset = packet.l4_bytes_offset

  super
end