Class: Unified2::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/unified2/protocol.rb

Overview

Protocol

Instance Method Summary collapse

Constructor Details

#initialize(protocol, packet = nil) ⇒ Protocol

Initialize protocol object

Parameters:

  • protocol (String)

    Event protocol

  • packet (Event#packet) (defaults to: nil)

    PacketFu object



17
18
19
20
# File 'lib/unified2/protocol.rb', line 17

def initialize(protocol, packet=nil)
  @protocol = protocol
  @packet = packet
end

Instance Method Details

#icmp?true, false

ICMP?

Returns:

  • (true, false)

    Check is protocol is icmp



27
28
29
# File 'lib/unified2/protocol.rb', line 27

def icmp?
  @protocol == :ICMP
end

#tcp?true, false

TCP?

Returns:

  • (true, false)

    Check is protocol is tcp



36
37
38
# File 'lib/unified2/protocol.rb', line 36

def tcp?
  @protocol == :TCP
end

#to_hHash Also known as: header

Convert To Hash

Examples:

event.protocol.to_h #=> {:length=>379, :seq=>3934511163, :ack=>1584708129 ... }

Returns:

  • (Hash)

    Protocol header hash object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/unified2/protocol.rb', line 69

def to_h
  hash = {
    :type => @protocol.to_s
  }

  if send(:"#{@protocol.downcase}?")
    hash.merge!(self.send(:"#{@protocol.downcase}"))
  end

  hash
end

#to_sString

Convert To String

Examples:

event.protocol #=> 'TCP'

Returns:



57
58
59
# File 'lib/unified2/protocol.rb', line 57

def to_s
  @protocol.to_s
end

#udp?true, false

UDP?

Returns:

  • (true, false)

    Check is protocol is udp



45
46
47
# File 'lib/unified2/protocol.rb', line 45

def udp?
  @protocol == :UDP
end