Class: PcapParser::Proto::ICMP

Inherits:
Object
  • Object
show all
Defined in:
lib/pcap_parser/proto/icmp.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(bin_header) ⇒ ICMP

Returns a new instance of ICMP.


6
7
8
# File 'lib/pcap_parser/proto/icmp.rb', line 6

def initialize(bin_header)
  @binhdr = bin_header
end

Instance Method Details

#chsumInteger

Checksum (16 bits)

Returns:

  • (Integer)

    Big-Endian 16bit int


25
26
27
# File 'lib/pcap_parser/proto/icmp.rb', line 25

def chsum
  @binhdr[2, 2].unpack("n").pop
end

#codeInteger

ICMP subtype

Returns:

  • (Integer)

    8bit unsigned int


19
20
21
# File 'lib/pcap_parser/proto/icmp.rb', line 19

def code
  @binhdr[1].unpack("C").pop
end

#typeInteger

Returns:

  • (Integer)

    8bit unsigned int


13
14
15
# File 'lib/pcap_parser/proto/icmp.rb', line 13

def type
  @binhdr[0].unpack("C").pop
end

#valid?true, false

Error checking calculated from the ICMP header and data.

Returns:

  • (true, false)

    true if packet is valid and has no errors


31
32
33
# File 'lib/pcap_parser/proto/icmp.rb', line 31

def valid?
  0xffff == Proto::sum_pack_16int(@binhdr.unpack("n*"))
end