ICMP
A ICMP header consists of:
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 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 |
+---------------+---------------+-------------------------------+8-bit type (
ICMP#type),8-bit code (
ICMP#code),16-bit checksum (
ICMP#checksum),and a body (
ICMP#body).
A ICMP header may be built this way:
pg> PacketGen::Header::ICMP.new(type: 8, code: 0, body: 'PING!')
=> ---- PacketGen::Header::ICMP -----------------------------------------
Int8 type: 8 (0x08)
Int8 code: 0 (0x00)
Int16 checksum: 0 (0x0000)A ICMP packet may be created this way:
pkt = PacketGen.gen('IP', src: '127.0.0.1', dst: '127.0.0.1').
add('ICMP', type: 8, code: 0, body: 'PING!')
pkt.is?('IP') # => true
pkt.is?('ICMP') # => true
pkt.icmp # => PacketGen::Header::ICMP
pkt.icmp.type # => Integer
pkt.icmp.code # => Integer
pkt.icmp.body # => "PING!"
pkt.body # => "PING!"
pkt.udp.type = 0 # This is now a pong!As usual, checksum field may be computed by Header::ICMP#calc_sum. All checksum and length fields from a packet may by computed at once using pkt.calc:
See also http://rubydoc.info/gems/packetgen/PacketGen/Header/ICMP.
Last updated