Class: Pio::Icmp::Format
- Inherits:
-
BinData::Record
- Object
- BinData::Record
- Pio::Icmp::Format
- 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
- #echo_data_length ⇒ Object
- #icmp_sum ⇒ Object
- #ip_packet_length ⇒ Object
- #ip_sum ⇒ Object
- #message_type ⇒ Object
- #to_binary ⇒ Object
Methods included from Type::EthernetHeader
Methods included from Type::IPv4Header
Instance Method Details
#echo_data_length ⇒ Object
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_sum ⇒ Object
49 50 51 |
# File 'lib/pio/icmp/format.rb', line 49 def icmp_sum ~((icmp_csum & 0xffff) + (icmp_csum >> 16)) & 0xffff end |
#ip_packet_length ⇒ Object
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_sum ⇒ Object
53 54 55 |
# File 'lib/pio/icmp/format.rb', line 53 def ip_sum ~((ip_csum & 0xffff) + (ip_csum >> 16)) & 0xffff end |
#message_type ⇒ Object
32 33 34 |
# File 'lib/pio/icmp/format.rb', line 32 def icmp_type end |
#to_binary ⇒ Object
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 |