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



36
37
38
# File 'lib/pio/icmp/format.rb', line 36

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

#icmp_sumObject



49
50
51
# File 'lib/pio/icmp/format.rb', line 49

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

#ip_packet_lengthObject



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

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



53
54
55
# File 'lib/pio/icmp/format.rb', line 53

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

#message_typeObject



32
33
34
# File 'lib/pio/icmp/format.rb', line 32

def message_type
  icmp_type
end

#to_binaryObject



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

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