### Home Classes Methods

### In Files

- lib/packetfu.rb
- lib/packetfu/inject.rb
- lib/packetfu/packet.rb
- lib/packetfu/capture.rb
- lib/packetfu/protos/ip/header.rb
- lib/packetfu/protos/ip/mixin.rb
- lib/packetfu/protos/tcp.rb
- lib/packetfu/protos/hsrp/header.rb
- lib/packetfu/protos/hsrp/mixin.rb
- lib/packetfu/protos/icmp.rb
- lib/packetfu/protos/ipv6.rb
- lib/packetfu/protos/lldp.rb
- lib/packetfu/protos/ip.rb
- lib/packetfu/protos/eth.rb
- lib/packetfu/protos/lldp/header.rb
- lib/packetfu/protos/lldp/mixin.rb
- lib/packetfu/protos/udp/header.rb
- lib/packetfu/protos/udp/mixin.rb
- lib/packetfu/protos/tcp/flags.rb
- lib/packetfu/protos/tcp/options.rb
- lib/packetfu/protos/tcp/mixin.rb
- lib/packetfu/protos/tcp/header.rb
- lib/packetfu/protos/tcp/option.rb
- lib/packetfu/protos/tcp/reserved.rb
- lib/packetfu/protos/tcp/hlen.rb
- lib/packetfu/protos/tcp/ecn.rb
- lib/packetfu/protos/eth/mixin.rb
- lib/packetfu/protos/eth/header.rb
- lib/packetfu/protos/arp/header.rb
- lib/packetfu/protos/arp/mixin.rb
- lib/packetfu/protos/udp.rb
- lib/packetfu/protos/invalid.rb
- lib/packetfu/protos/ipv6/header.rb
- lib/packetfu/protos/ipv6/mixin.rb
- lib/packetfu/protos/hsrp.rb
- lib/packetfu/protos/icmp/mixin.rb
- lib/packetfu/protos/icmp/header.rb
- lib/packetfu/protos/arp.rb
- lib/packetfu/pcap.rb
- lib/packetfu/version.rb
- lib/packetfu/config.rb
- lib/packetfu/utils.rb

### Namespace

- MODULE PacketFu::ARPHeaderMixin
- MODULE PacketFu::EthHeaderMixin
- MODULE PacketFu::HSRPHeaderMixin
- MODULE PacketFu::ICMPHeaderMixin
- MODULE PacketFu::IPHeaderMixin
- MODULE PacketFu::IPv6HeaderMixin
- MODULE PacketFu::LLDPHeaderMixin
- MODULE PacketFu::TCPHeaderMixin
- MODULE PacketFu::UDPHeaderMixin
- CLASS PacketFu::ARPHeader
- CLASS PacketFu::ARPPacket
- CLASS PacketFu::AddrIpv6
- CLASS PacketFu::Capture
- CLASS PacketFu::Config
- CLASS PacketFu::EthHeader
- CLASS PacketFu::EthMac
- CLASS PacketFu::EthNic
- CLASS PacketFu::EthOui
- CLASS PacketFu::EthPacket
- CLASS PacketFu::HSRPHeader
- CLASS PacketFu::HSRPPacket
- CLASS PacketFu::ICMPHeader
- CLASS PacketFu::ICMPPacket
- CLASS PacketFu::IPHeader
- CLASS PacketFu::IPPacket
- CLASS PacketFu::IPv6Header
- CLASS PacketFu::IPv6Packet
- CLASS PacketFu::Inject
- CLASS PacketFu::InvalidHeader
- CLASS PacketFu::InvalidPacket
- CLASS PacketFu::LLDPHeader
- CLASS PacketFu::LLDPPacket
- CLASS PacketFu::Octets
- CLASS PacketFu::Packet
- CLASS PacketFu::PcapFile
- CLASS PacketFu::PcapHeader
- CLASS PacketFu::PcapPacket
- CLASS PacketFu::PcapPackets
- CLASS PacketFu::Read
- CLASS PacketFu::TCPHeader
- CLASS PacketFu::TCPPacket
- CLASS PacketFu::TcpEcn
- CLASS PacketFu::TcpFlags
- CLASS PacketFu::TcpHlen
- CLASS PacketFu::TcpOption
- CLASS PacketFu::TcpOptions
- CLASS PacketFu::TcpReserved
- CLASS PacketFu::Timestamp
- CLASS PacketFu::UDPHeader
- CLASS PacketFu::UDPPacket
- CLASS PacketFu::Utils
- CLASS PacketFu::Write

### Methods

- ::add_packet_class
- ::at_least?
- ::binarize_version
- ::classes
- ::force_binary
- ::inspect_style
- ::inspect_style=
- ::newer_than?
- ::older_than?
- ::packet_classes
- ::packet_prefixes
- ::pcaprub_loaded?
- ::pcaprub_platform_require
- ::remove_packet_class
- ::require_protos
- ::version
- #toggle_inspect

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

### Constants

VERSION

  Check the repo's for version release histories

### Public Class Methods

add_packet_class(klass) click to toggle source

Adds the class to PacketFu's list of packet classes -- used in packet parsing.

    # File lib/packetfu.rb, line 73
    def self.add_packet_class(klass)
            raise "Need a class" unless klass.kind_of? Class
            if klass.name !~ /[A-Za-z0-9]Packet/
                    raise "Packet classes should be named 'ProtoPacket'"
            end
            @packet_classes ||= []
            @packet_classes << klass
            @packet_classes_dirty = true
            @packet_classes.sort! {|x,y| x.name <=> y.name}
    end

at_least?(str) click to toggle source

Returns true if the version is equal to or greater than the compare version. If the current version of PacketFu is "0.3.1" for example:

    PacketFu.at_least? "0"     # => true
    PacketFu.at_least? "0.2.9" # => true
    PacketFu.at_least? "0.3"   # => true
    PacketFu.at_least? "1"     # => true after 1.0's release
    PacketFu.at_least? "1.12"  # => false
    PacketFu.at_least? "2"     # => false

    # File lib/packetfu/version.rb, line 30
    def self.at_least?(str)
            this_version = binarize_version(self.version)
            ask_version = binarize_version(str)
            this_version >= ask_version
    end

binarize_version(str) click to toggle source

Returns a version string in a binary format for easy comparisons.

    # File lib/packetfu/version.rb, line 12
    def self.binarize_version(str)
            if(str.respond_to?(:split) && str =~ /^[0-9]+(\.([0-9]+)(\.[0-9]+)?)?\..+$/)
                    bin_major,bin_minor,bin_teeny = str.split(/\x2e/).map {|x| x.to_i}
                    bin_version = (bin_major.to_i << 16) + (bin_minor.to_i << 8) + bin_teeny.to_i
            else
                    raise ArgumentError, "Compare version malformed. Should be \x22x.y.z\x22"
            end
    end

classes() click to toggle source

Returns an array of classes defined in PacketFu

    # File lib/packetfu.rb, line 68
    def self.classes
            constants.map { |const| const_get(const) if const_get(const).kind_of? Class}.compact
    end

force_binary(str) click to toggle source

Deal with Ruby's encoding by ignoring it.

    # File lib/packetfu.rb, line 29
    def self.force_binary(str)
            str.force_encoding Encoding::BINARY if str.respond_to? :force_encoding
    end

inspect_style() click to toggle source

The current inspect style. One of :hex, :dissect, or :default Note that :default means Ruby's default, which is usually far too long to be useful.

    # File lib/packetfu.rb, line 110
    def self.inspect_style
            @inspect_style ||= :dissect
    end

inspect_style=(arg) click to toggle source

Setter for PacketFu's @inspect_style

    # File lib/packetfu.rb, line 115
    def self.inspect_style=(arg)
            @inspect_style = case arg
                    when :hex, :pretty
                            :hex
                    when :dissect, :verbose
                            :dissect
                    when :default, :ugly
                            :default
                    else
                            :dissect
                    end
    end

newer_than?(str) click to toggle source

Returns true if the current version is newer than the compare version.

    # File lib/packetfu/version.rb, line 45
    def self.newer_than?(str)
            return false if str == self.version
            !self.older_than?(str)
    end

older_than?(str) click to toggle source

Returns true if the current version is older than the compare version.

    # File lib/packetfu/version.rb, line 37
    def self.older_than?(str)
            return false if str == self.version
            this_version = binarize_version(self.version)
            ask_version = binarize_version(str)
            this_version < ask_version
    end

packet_classes() click to toggle source

Returns an array of packet classes

    # File lib/packetfu.rb, line 94
    def self.packet_classes
            @packet_classes || []
    end

packet_prefixes() click to toggle source

Returns an array of packet types by packet prefix.

    # File lib/packetfu.rb, line 99
    def self.packet_prefixes
            return [] if @packet_classes.nil?
            return @packet_class_prefixes if @packet_classes_dirty == false
            @packet_classes_dirty = false
            @packet_class_prefixes = @packet_classes.map {|p| p.to_s.split("::").last.to_s.downcase.gsub(/packet$/,"")}
            return @packet_class_prefixes
    end

pcaprub_loaded?() click to toggle source

Returns the status of pcaprub

    # File lib/packetfu.rb, line 63
    def self.pcaprub_loaded?
            @pcaprub_loaded
    end

pcaprub_platform_require() click to toggle source

PacketFu works best with Pcaprub version 0.8-dev (at least) The current (Aug 01, 2010) pcaprub gem is 0.9, so should be fine.

    # File lib/packetfu.rb, line 41
    def self.pcaprub_platform_require
            begin
                    require 'pcaprub'
            rescue LoadError
                    return false
            end
            @pcaprub_loaded = true
    end

remove_packet_class(klass) click to toggle source

Presumably, there may be a time where you'd like to remove a packet class.

    # File lib/packetfu.rb, line 85
    def self.remove_packet_class(klass)
            raise "Need a class" unless klass.kind_of? Class
            @packet_classes ||= []
            @packet_classes.delete klass
            @packet_classes_dirty = true
            @packet_classes
    end

require_protos(cwd) click to toggle source

Picks up all the protocols defined in the protos subdirectory

    # File lib/packetfu.rb, line 16
    def self.require_protos(cwd)
            protos_dir = File.join(cwd, "packetfu", "protos")
            Dir.new(protos_dir).each do |fname|
                    next unless fname[/\.rb$/]
                    begin
                            require File.join(protos_dir,fname)
                    rescue
                            warn "Warning: Could not load `#{fname}'. Skipping."
                    end
            end
    end

version() click to toggle source

Returns PacketFu::VERSION

    # File lib/packetfu/version.rb, line 7
    def self.version
            VERSION
    end

### Public Instance Methods

toggle_inspect() click to toggle source

Switches inspect styles in a round-robin fashion between :dissect, :default, and :hex

    # File lib/packetfu.rb, line 130
    def toggle_inspect
            case @inspect_style
            when :hex, :pretty
                    @inspect_style = :dissect
            when :dissect, :verbose
                    @inspect_style = :default
            when :default, :ugly
                    @inspect_style = :hex
            else
                    @inspect_style = :dissect
            end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.