### Home Classes Methods

### In Files

- lib/packetfu/protos/ip.rb

### Parent

PacketFu::Packet

### Methods

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

### Included Modules

- PacketFu::EthHeaderMixin
- PacketFu::IPHeaderMixin

### 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::IPPacket

IPPacket is used to construct IP packets. They contain an EthHeader, an IPHeader, and usually a transport-layer protocol such as UDPHeader, TCPHeader, or ICMPHeader.

## Example

    require 'packetfu'
    ip_pkt = PacketFu::IPPacket.new
    ip_pkt.ip_saddr="10.20.30.40"
    ip_pkt.ip_daddr="192.168.1.1"
    ip_pkt.ip_proto=1
    ip_pkt.ip_ttl=64
    ip_pkt.ip_payload="\x00\x00\x12\x34\x00\x01\x00\x01"+
      "Lovingly hand-crafted echo responses delivered directly to your door."
    ip_pkt.recalc
    ip_pkt.to_f('/tmp/ip.pcap')

## Parameters

    :eth
      A pre-generated EthHeader object.
    :ip
      A pre-generated IPHeader object.
    :flavor
      TODO: Sets the "flavor" of the IP packet. This might include known sets of IP options, and
      certainly known starting TTLs.
    :config
      A hash of return address details, often the output of Utils.whoami?

### Attributes

eth_header[RW]
ip_header[RW]

### Public Class Methods

can_parse?(str) click to toggle source

    # File lib/packetfu/protos/ip.rb, line 42
    def self.can_parse?(str)
            return false unless str.size >= 34
            return false unless EthPacket.can_parse? str
            if str[12,2] == "\x08\x00"
                    if 1.respond_to? :ord
                            ipv = str[14,1][0].ord >> 4
                    else
                            ipv = str[14,1][0] >> 4
                    end
                    return true if ipv == 4
            else
                    return false
            end
    end

new(args={}) click to toggle source

Creates a new IPPacket object.

    # File lib/packetfu/protos/ip.rb, line 65
    def initialize(args={})
            @eth_header = EthHeader.new(args).read(args[:eth])
            @ip_header = IPHeader.new(args).read(args[:ip])
            @eth_header.body=@ip_header

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

### Public Instance Methods

peek_format() click to toggle source

Peek provides summary data on packet contents.

    # File lib/packetfu/protos/ip.rb, line 75
    def peek_format
            peek_data = ["I  "]
            peek_data << "%-5d" % to_s.size
            peek_data << "%-21s" % "#{ip_saddr}"
            peek_data << "->"
            peek_data << "%21s" % "#{ip_daddr}"
            peek_data << "%23s" % "I:"
            peek_data << "%04x" % ip_id.to_i
            peek_data.join
    end

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

    # File lib/packetfu/protos/ip.rb, line 57
    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.