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') # => truepkt.is?('ICMP') # => truepkt.icmp # => PacketGen::Header::ICMPpkt.icmp.type # => Integerpkt.icmp.code # => Integerpkt.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: