### Home Classes Methods

### In Files

- lib/packetfu/protos/icmp.rb

### Parent

PacketFu::Packet

### Methods

- ::can_parse?
- ::new
- #peek_format
- #read

### Included Modules

- PacketFu::EthHeaderMixin
- PacketFu::IPHeaderMixin
- PacketFu::ICMPHeaderMixin

### Files

- .document
- README.rdoc

### Class/Module Index

Quicksearch

- PacketFu
- PacketFu::ARPHeader
- PacketFu::ARPHeaderMixin
- PacketFu::ARPPacket
- PacketFu::AddrIpv6
- PacketFu::Capture
- PacketFu::Config
- PacketFu::EthHeader
- PacketFu::EthHeaderMixin
- PacketFu::EthMac
- PacketFu::EthNic
- PacketFu::EthOui
- PacketFu::EthPacket
- PacketFu::HSRPHeader
- PacketFu::HSRPHeaderMixin
- PacketFu::HSRPPacket
- PacketFu::ICMPHeader
- PacketFu::ICMPHeaderMixin
- PacketFu::ICMPPacket
- PacketFu::IPHeader
- PacketFu::IPHeaderMixin
- PacketFu::IPPacket
- PacketFu::IPv6Header
- PacketFu::IPv6HeaderMixin
- PacketFu::IPv6Packet
- PacketFu::Inject
- PacketFu::InvalidHeader
- PacketFu::InvalidPacket
- PacketFu::LLDPHeader
- PacketFu::LLDPHeaderMixin
- PacketFu::LLDPPacket
- PacketFu::Octets
- PacketFu::Packet
- PacketFu::PcapFile
- PacketFu::PcapHeader
- PacketFu::PcapPacket
- PacketFu::PcapPackets
- PacketFu::Read
- PacketFu::TCPHeader
- PacketFu::TCPHeaderMixin
- PacketFu::TCPPacket
- PacketFu::TcpEcn
- PacketFu::TcpFlags
- PacketFu::TcpHlen
- PacketFu::TcpOption
- PacketFu::TcpOption::ECHO
- PacketFu::TcpOption::ECHOREPLY
- PacketFu::TcpOption::EOL
- PacketFu::TcpOption::MSS
- PacketFu::TcpOption::NOP
- PacketFu::TcpOption::SACK
- PacketFu::TcpOption::SACKOK
- PacketFu::TcpOption::TS
- PacketFu::TcpOption::WS
- PacketFu::TcpOptions
- PacketFu::TcpReserved
- PacketFu::Timestamp
- PacketFu::UDPHeader
- PacketFu::UDPHeaderMixin
- PacketFu::UDPPacket
- PacketFu::Utils
- PacketFu::Write
- StructFu
- StructFu::Int
- StructFu::Int16
- StructFu::Int16be
- StructFu::Int16le
- StructFu::Int32
- StructFu::Int32be
- StructFu::Int32le
- StructFu::Int8
- StructFu::IntString
- StructFu::String
- Struct

No matching classes.

# PacketFu::ICMPPacket

ICMPPacket is used to construct ICMP Packets. They contain an EthHeader, an IPHeader, and a ICMPHeader.

## Example

    icmp_pkt.new
    icmp_pkt.icmp_type = 8
    icmp_pkt.icmp_code = 0
    icmp_pkt.payload = "ABC, easy as 123. As simple as do-re-mi. ABC, 123, baby, you and me!"

    icmp_pkt.ip_saddr="1.2.3.4"
    icmp_pkt.ip_daddr="5.6.7.8"

    icmp_pkt.recalc
    icmp_pkt.to_f('/tmp/icmp.pcap')

## Parameters

    :eth
     A pre-generated EthHeader object.
    :ip
     A pre-generated IPHeader object.
    :flavor
     TODO: Sets the "flavor" of the ICMP packet. Pings, in particular, often betray their true
     OS.
    :config
     A hash of return address details, often the output of Utils.whoami?

### Attributes

eth_header[RW]
icmp_header[RW]
ip_header[RW]

### Public Class Methods

can_parse?(str) click to toggle source

    # File lib/packetfu/protos/icmp.rb, line 44
    def self.can_parse?(str)
            return false unless str.size >= 38
            return false unless EthPacket.can_parse? str
            return false unless IPPacket.can_parse? str
            return false unless str[23,1] == "\x01"
            return true
    end

new(args={}) click to toggle source

    # File lib/packetfu/protos/icmp.rb, line 59
    def initialize(args={})
            @eth_header = EthHeader.new(args).read(args[:eth])
            @ip_header = IPHeader.new(args).read(args[:ip])
            @ip_header.ip_proto = 1
            @icmp_header = ICMPHeader.new(args).read(args[:icmp])

            @ip_header.body = @icmp_header
            @eth_header.body = @ip_header

            @headers = [@eth_header, @ip_header, @icmp_header]
            super
    end

### Public Instance Methods

peek_format() click to toggle source

Peek provides summary data on packet contents.

    # File lib/packetfu/protos/icmp.rb, line 73
    def peek_format
            peek_data = ["IC "] # I is taken by IP
            peek_data << "%-5d" % self.to_s.size
            type = case self.icmp_type.to_i
                                     when 8
                                             "ping"
                                     when 0
                                             "pong"
                                     else
                                             "%02x-%02x" % [self.icmp_type, self.icmp_code]
                                     end
            peek_data << "%-21s" % "#{self.ip_saddr}:#{type}"
            peek_data << "->"
            peek_data << "%21s" % "#{self.ip_daddr}"
            peek_data << "%23s" % "I:"
            peek_data << "%04x" % self.ip_id
            peek_data.join
    end

read(str=nil, args={}) click to toggle source

    # File lib/packetfu/protos/icmp.rb, line 52
    def read(str=nil, args={})
            raise "Cannot parse `#{str}'" unless self.class.can_parse?(str)
            @eth_header.read(str)
            super(args)
            self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.