Class: HiddenHippo::Packets::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/hidden_hippo/packets/packet.rb

Direct Known Subclasses

Dhcp, Dns, Http, Wps

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.field(name, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/hidden_hippo/packets/packet.rb', line 23

def self.field(name, options={})
  fields << Field.new(name, options[:tshark], options[:conv])
  attr_accessor name
  name
end

.fieldsObject



6
7
8
9
10
11
12
# File 'lib/hidden_hippo/packets/packet.rb', line 6

def self.fields
  unless @fields
    super_fields = self == Packet ? [] : superclass.fields.dup
    @fields = super_fields
  end
  @fields
end

.filter(filter = nil) ⇒ Object



18
19
20
21
# File 'lib/hidden_hippo/packets/packet.rb', line 18

def self.filter(filter=nil)
  @filter = filter if filter
  @filter
end

.parse(hash) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hidden_hippo/packets/packet.rb', line 29

def self.parse(hash)
  instance = new

  reverse_names = Hash[*fields.map{|f| [f.tshark_field, f]}.flatten]

  hash.each do |k, v|
    field = reverse_names[k]

    next unless field

    conv = converter field
    instance.public_send "#{field.name}=", conv.(v)
  end

  instance
end

.tshark_fieldsObject



14
15
16
# File 'lib/hidden_hippo/packets/packet.rb', line 14

def self.tshark_fields
  fields.map &:tshark_field
end

Instance Method Details

#mac_destObject



61
62
63
# File 'lib/hidden_hippo/packets/packet.rb', line 61

def mac_dest
  eth_mac_dest || wlan_mac_dest
end

#mac_srcObject



57
58
59
# File 'lib/hidden_hippo/packets/packet.rb', line 57

def mac_src
  eth_mac_src || wlan_mac_src
end