### Home Classes Methods

### In Files

- lib/packetfu/protos/tcp/flags.rb

### Parent

Struct.new(:urg, :ack, :psh, :rst, :syn, :fin)

### Methods

- ::new
- #ack=
- #fin=
- #psh=
- #read
- #rst=
- #syn=
- #to_i
- #urg=
- #zero_or_one

### Included Modules

- StructFu

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

Implements flags for TCPHeader.

#### Header Definition

    Fixnum (1 bit)  :urg
    Fixnum (1 bit)  :ack
    Fixnum (1 bit)  :psh
    Fixnum (1 bit)  :rst
    Fixnum (1 bit)  :syn
    Fixnum (1 bit)  :fin

Flags can typically be set by setting them either to 1 or 0, or to true or false.

### Public Class Methods

new(args={}) click to toggle source

    # File lib/packetfu/protos/tcp/flags.rb, line 18
    def initialize(args={})
      # This technique attemts to ensure that flags are always 0 (off)
      # or 1 (on). Statements like nil and false shouldn't be lurking in here.
      if args.nil? || args.size.zero?
        super( 0, 0, 0, 0, 0, 0)
      else
        super(
          (args[:urg] ? 1 : 0),
          (args[:ack] ? 1 : 0),
          (args[:psh] ? 1 : 0),
          (args[:rst] ? 1 : 0),
          (args[:syn] ? 1 : 0),
          (args[:fin] ? 1 : 0)
        )
      end
    end

### Public Instance Methods

ack=(i) click to toggle source

Setter for the Acknowlege flag.

    # File lib/packetfu/protos/tcp/flags.rb, line 54
    def ack=(i); self[:ack] = zero_or_one(i); end

fin=(i) click to toggle source

Setter for the Finish flag.

    # File lib/packetfu/protos/tcp/flags.rb, line 62
    def fin=(i); self[:fin] = zero_or_one(i); end

psh=(i) click to toggle source

Setter for the Push flag.

    # File lib/packetfu/protos/tcp/flags.rb, line 56
    def psh=(i); self[:psh] = zero_or_one(i); end

read(str) click to toggle source

Reads a string to populate the object.

    # File lib/packetfu/protos/tcp/flags.rb, line 65
    def read(str)
      force_binary(str)
      return self if str.nil?
      if 1.respond_to? :ord
        byte = str[0].ord
      else
        byte = str[0]
      end
      self[:urg] = byte & 0b00100000 == 0b00100000 ? 1 : 0
      self[:ack] = byte & 0b00010000 == 0b00010000 ? 1 : 0
      self[:psh] = byte & 0b00001000 == 0b00001000 ? 1 : 0
      self[:rst] = byte & 0b00000100 == 0b00000100 ? 1 : 0
      self[:syn] = byte & 0b00000010 == 0b00000010 ? 1 : 0
      self[:fin] = byte & 0b00000001 == 0b00000001 ? 1 : 0
      self
    end

rst=(i) click to toggle source

Setter for the Reset flag.

    # File lib/packetfu/protos/tcp/flags.rb, line 58
    def rst=(i); self[:rst] = zero_or_one(i); end

syn=(i) click to toggle source

Setter for the Synchronize flag.

    # File lib/packetfu/protos/tcp/flags.rb, line 60
    def syn=(i); self[:syn] = zero_or_one(i); end

to_i() click to toggle source

Returns the TcpFlags as an integer. Also not a great candidate for to_s due to the short bitspace.

    # File lib/packetfu/protos/tcp/flags.rb, line 37
    def to_i
      (urg.to_i << 5) + (ack.to_i << 4) + (psh.to_i << 3) +
      (rst.to_i << 2) + (syn.to_i << 1) + fin.to_i
    end

urg=(i) click to toggle source

Setter for the Urgent flag.

    # File lib/packetfu/protos/tcp/flags.rb, line 52
    def urg=(i); self[:urg] = zero_or_one(i); end

zero_or_one(i=0) click to toggle source

Helper to determine if this flag is a 1 or a 0.

    # File lib/packetfu/protos/tcp/flags.rb, line 43
    def zero_or_one(i=0)
      if i == 0 || i == false || i == nil
        0
      else
        1
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.