Class: HiddenHippo::Packets::Packet
- Inherits:
-
Object
- Object
- HiddenHippo::Packets::Packet
- Defined in:
- lib/hidden_hippo/packets/packet.rb
Class Method Summary collapse
- .field(name, options = {}) ⇒ Object
- .fields ⇒ Object
- .filter(filter = nil) ⇒ Object
- .parse(hash) ⇒ Object
- .tshark_fields ⇒ Object
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, ={}) fields << Field.new(name, [:tshark], [:conv]) attr_accessor name name end |
.fields ⇒ Object
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_fields ⇒ Object
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_dest ⇒ Object
61 62 63 |
# File 'lib/hidden_hippo/packets/packet.rb', line 61 def mac_dest eth_mac_dest || wlan_mac_dest end |
#mac_src ⇒ Object
57 58 59 |
# File 'lib/hidden_hippo/packets/packet.rb', line 57 def mac_src eth_mac_src || wlan_mac_src end |