Class: Xlat::Protocols::Icmp::Base

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/xlat/protocols/icmp/base.rb

Direct Known Subclasses

Echo, Error

Constant Summary collapse

V4_PROTOCOL_ID =
1
V6_PROTOCOL_ID =
58

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

sum16be

Constructor Details

#initialize(packet) ⇒ Base

Returns a new instance of Base.



38
39
40
# File 'lib/xlat/protocols/icmp/base.rb', line 38

def initialize(packet)
  @packet = packet
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



36
37
38
# File 'lib/xlat/protocols/icmp/base.rb', line 36

def code
  @code
end

#typeObject (readonly)

Returns the value of attribute type.



36
37
38
# File 'lib/xlat/protocols/icmp/base.rb', line 36

def type
  @type
end

Class Method Details

.parse(packet) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/xlat/protocols/icmp/base.rb', line 52

def self.parse(packet)
  bytes = packet.l4_bytes
  offset = packet.l4_bytes_offset

  return nil if packet.l4_bytes_length < 8

  type = bytes.get_value(:U8, offset)
  icmp = packet.version.new_icmp(packet, type)
  icmp._parse
end

.recalculate_checksum(packet) ⇒ Object



67
68
69
70
71
72
# File 'lib/xlat/protocols/icmp/base.rb', line 67

def self.recalculate_checksum(packet)
  packet.bytes.set_value(:U16, packet.l4_start + 2, 0)
  checksum = Ip.checksum(packet.bytes, packet.l4_start)
  checksum = Ip.checksum_adjust(checksum, packet.version.icmp_cs_delta(packet)) # pseudo header
  packet.bytes.set_value(:U16, packet.l4_start + 2, checksum)
end

Instance Method Details

#_parseObject



42
43
44
45
46
47
48
49
50
# File 'lib/xlat/protocols/icmp/base.rb', line 42

def _parse
  bytes = @packet.l4_bytes
  offset = @packet.l4_bytes_offset

  @type = bytes.get_value(:U8, offset)
  @code = bytes.get_value(:U8, offset + 1)

  self
end

#apply(cs_delta) ⇒ Object



63
64
65
# File 'lib/xlat/protocols/icmp/base.rb', line 63

def apply(cs_delta)
  # ICMP does not use pseudo headers
end