class Pio::Icmp::Format

ICMP format

Private Instance Methods

calculate_icmp_checksum() click to toggle source
# File lib/pio/icmp/format.rb, line 33
def calculate_icmp_checksum
  sum = [icmp_type * 0x100 + icmp_code,
         icmp_identifier,
         icmp_sequence_number,
         *echo_data.unpack('n*')].inject(:+)
  ~((sum & 0xffff) + (sum >> 16)) & 0xffff
end
echo_data_length() click to toggle source
# File lib/pio/icmp/format.rb, line 41
def echo_data_length
  ip_total_length - ip_header_length_in_bytes - icmp_header_length
end
icmp_header_length() click to toggle source
# File lib/pio/icmp/format.rb, line 29
def icmp_header_length
  8
end
padding_length() click to toggle source
# File lib/pio/icmp/format.rb, line 45
def padding_length
  tmp = Ethernet::MINIMUM_FRAME_SIZE -
        ethernet_header_length - ip_header_length_in_bytes -
        icmp_header_length - echo_data.length
  tmp > 0 ? tmp : 0
end