### Home Classes Methods

### In Files

- lib/packetfu/pcap.rb
- lib/packetfu/structfu.rb

### Namespace

- CLASS StructFu::Int
- CLASS StructFu::Int16
- CLASS StructFu::Int16be
- CLASS StructFu::Int16le
- CLASS StructFu::Int32
- CLASS StructFu::Int32be
- CLASS StructFu::Int32le
- CLASS StructFu::Int8
- CLASS StructFu::IntString
- CLASS StructFu::String

### Methods

- #body=
- #clone
- #len
- #set_endianness
- #sz
- #typecast

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

# StructFu

StructFu, a nifty way to leverage Ruby's built in Struct class to create meaningful binary data.

### Public Instance Methods

body=(i) click to toggle source

Used like typecast(), but specifically for casting Strings to StructFu::Strings.

    # File lib/packetfu/structfu.rb, line 24
    def body=(i)
            if i.kind_of? ::String
                    typecast(i)
            elsif i.kind_of? StructFu
                    self[:body] = i
            elsif i.nil?
                    self[:body] = StructFu::String.new.read("")
            else
                    raise ArgumentError, "Can't cram a #{i.class} into a StructFu :body"
            end
    end

clone() click to toggle source

Handle deep copies correctly. Marshal in 1.9, re-read myself on 1.8

    # File lib/packetfu/structfu.rb, line 37
    def clone
            begin
                    Marshal.load(Marshal.dump(self))
            rescue
                    self.class.new.read(self.to_s)
            end
    end

len() click to toggle source
Alias for: sz
set_endianness(e=nil) click to toggle source

Set the endianness for the various Int classes. Takes either :little or :big.

    # File lib/packetfu/pcap.rb, line 6
    def set_endianness(e=nil)
            unless [:little, :big].include? e
                    raise ArgumentError, "Unknown endianness for #{self.class}"
            end
            @int32 = e == :little ? Int32le : Int32be
            @int16 = e == :little ? Int16le : Int16be
            return e
    end

sz() click to toggle source

Instead of returning the "size" of the object, which is usually the number of elements of the Struct, returns the size of the object after a to_s. Essentially, a short version of self.to_size.size

    # File lib/packetfu/pcap.rb, line 18
    def sz
            self.to_s.size
    end

Also aliased as: len
typecast(i) click to toggle source

Typecast is used mostly by packet header classes, such as IPHeader, TCPHeader, and the like. It takes an argument, and casts it to the expected type for that element.

    # File lib/packetfu/structfu.rb, line 18
    def typecast(i)
            c = caller[0].match(/.*`([^']+)='/)[1]
            self[c.intern].read i
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.