Class: Pio::Icmp::Format

Inherits:
BinData::Record
  • Object
show all
Extended by:
Type::EthernetHeader, Type::IPv4Header
Defined in:
lib/pio/icmp/format.rb

Overview

Icmp parser.

Constant Summary collapse

PADDED_PACKET_LENGTH =
50
MINIMUM_PACKET_LENGTH =
36
MINIMUM_FRAME_LENGTH =
64

Instance Method Summary collapse

Methods included from Type::EthernetHeader

ethernet_header

Methods included from Type::IPv4Header

ipv4_header

Instance Method Details

#echo_data_lengthObject



34
35
36
# File 'lib/pio/icmp/format.rb', line 34

def echo_data_length
  ip_total_length - (ip_header_length * 4 + 8)
end

#icmp_sumObject



47
48
49
# File 'lib/pio/icmp/format.rb', line 47

def icmp_sum
  ~((icmp_csum & 0xffff) + (icmp_csum >> 16)) & 0xffff
end

#ip_packet_lengthObject



38
39
40
41
42
43
44
45
# File 'lib/pio/icmp/format.rb', line 38

def ip_packet_length
  icmpsize = (ip_header_length * 4) + (8 + echo_data.bytesize)
  if icmpsize < MINIMUM_PACKET_LENGTH
    PADDED_PACKET_LENGTH
  else
    icmpsize
  end
end

#ip_sumObject



51
52
53
# File 'lib/pio/icmp/format.rb', line 51

def ip_sum
  ~((ip_csum & 0xffff) + (ip_csum >> 16)) & 0xffff
end

#message_typeObject



30
31
32
# File 'lib/pio/icmp/format.rb', line 30

def message_type
  icmp_type
end

#to_binaryObject



55
56
57
58
59
60
61
# File 'lib/pio/icmp/format.rb', line 55

def to_binary
  if num_bytes < MINIMUM_FRAME_LENGTH
    to_binary_s + "\000" * (MINIMUM_FRAME_LENGTH - num_bytes)
  else
    to_binary_s
  end
end