Class: PacketGen::Header::ICMP
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::ICMP
- Defined in:
- lib/packetgen/header/icmp.rb
Overview
ICMP header (RFC 792)
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Code | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A ICMP header consists of:
-
a #type field (Types::Int8 type),
-
a #code field (Types::Int8 type),
-
a #checksum field (Types::Int16 type),
-
and a #body.
Create a ICMP header
# standalone
icmp = PacketGen::Header::ICMP.new
# in a packet
pkt = PacketGen.gen('IP').add('ICMP')
# access to ICMP header
pkt.icmp # => PacketGen::Header::ICMP
ICMP attributes
icmp.code = 0
icmp.type = 200
icmp.checksum = 0x248a
icmp.body.read 'this is a body'
Direct Known Subclasses
Constant Summary collapse
- IP_PROTOCOL =
ICMP internet protocol number
1
Instance Attribute Summary collapse
- #body ⇒ Types::String, Header::Base
-
#checksum ⇒ Integer
16-bit ICMP checksum.
-
#code ⇒ Integer
8-bit ICMP code.
-
#type ⇒ Integer
8-bit ICMP type.
Instance Method Summary collapse
-
#calc_checksum ⇒ Integer
Compute checksum and set
checksum
field.
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header
Methods included from PacketGen::Headerable
#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
This class inherits a constructor from PacketGen::Header::Base
Instance Attribute Details
#body ⇒ Types::String, Header::Base
55 |
# File 'lib/packetgen/header/icmp.rb', line 55 define_field :body, Types::String |
#checksum ⇒ Integer
16-bit ICMP checksum
52 |
# File 'lib/packetgen/header/icmp.rb', line 52 define_field :checksum, Types::Int16 |
Instance Method Details
#calc_checksum ⇒ Integer
Compute checksum and set checksum
field
59 60 61 62 |
# File 'lib/packetgen/header/icmp.rb', line 59 def calc_checksum sum = IP.sum16(self) self.checksum = IP.reduce_checksum(sum) end |