Class: PacketFu::EthOui
- Defined in:
- lib/packetfu/protos/eth/header.rb
Overview
EthOui is the Organizationally Unique Identifier portion of a MAC address, used in EthHeader.
See the OUI list at standards.ieee.org/regauth/oui/oui.txt
Header Definition
Integer :b0
Integer :b1
Integer :b2
Integer :b3
Integer :b4
Integer :b5
Integer :local
Integer :multicast
Int16 :oui, Default: 0x1ac5 :)
Instance Attribute Summary collapse
-
#b0 ⇒ Object
Returns the value of attribute b0.
-
#b1 ⇒ Object
Returns the value of attribute b1.
-
#b2 ⇒ Object
Returns the value of attribute b2.
-
#b3 ⇒ Object
Returns the value of attribute b3.
-
#b4 ⇒ Object
Returns the value of attribute b4.
-
#b5 ⇒ Object
Returns the value of attribute b5.
-
#local ⇒ Object
Returns the value of attribute local.
-
#multicast ⇒ Object
Returns the value of attribute multicast.
-
#oui ⇒ Object
Returns the value of attribute oui.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ EthOui
constructor
EthOui is unusual in that the bit values do not enjoy StructFu typing.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_s ⇒ Object
Returns the object in string form.
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ EthOui
EthOui is unusual in that the bit values do not enjoy StructFu typing.
21 22 23 24 25 26 27 28 |
# File 'lib/packetfu/protos/eth/header.rb', line 21 def initialize(args={}) args[:local] ||= 0 args[:oui] ||= 0x1ac # :) args.each_pair {|k,v| args[k] = 0 unless v} super(args[:b5], args[:b4], args[:b3], args[:b2], args[:b1], args[:b0], args[:local], args[:multicast], args[:oui]) end |
Instance Attribute Details
#b0 ⇒ Object
Returns the value of attribute b0
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def b0 @b0 end |
#b1 ⇒ Object
Returns the value of attribute b1
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def b1 @b1 end |
#b2 ⇒ Object
Returns the value of attribute b2
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def b2 @b2 end |
#b3 ⇒ Object
Returns the value of attribute b3
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def b3 @b3 end |
#b4 ⇒ Object
Returns the value of attribute b4
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def b4 @b4 end |
#b5 ⇒ Object
Returns the value of attribute b5
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def b5 @b5 end |
#local ⇒ Object
Returns the value of attribute local
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def local @local end |
#multicast ⇒ Object
Returns the value of attribute multicast
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def multicast @multicast end |
#oui ⇒ Object
Returns the value of attribute oui
18 19 20 |
# File 'lib/packetfu/protos/eth/header.rb', line 18 def oui @oui end |
Instance Method Details
#read(str) ⇒ Object
Reads a string to populate the object.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/packetfu/protos/eth/header.rb', line 45 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[:b5] = byte & 0b10000000 == 0b10000000 ? 1 : 0 self[:b4] = byte & 0b01000000 == 0b01000000 ? 1 : 0 self[:b3] = byte & 0b00100000 == 0b00100000 ? 1 : 0 self[:b2] = byte & 0b00010000 == 0b00010000 ? 1 : 0 self[:b1] = byte & 0b00001000 == 0b00001000 ? 1 : 0 self[:b0] = byte & 0b00000100 == 0b00000100 ? 1 : 0 self[:local] = byte & 0b00000010 == 0b00000010 ? 1 : 0 self[:multicast] = byte & 0b00000001 == 0b00000001 ? 1 : 0 self[:oui] = str[1,2].unpack("n").first self end |
#to_s ⇒ Object
Returns the object in string form.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/packetfu/protos/eth/header.rb', line 31 def to_s byte = 0 byte += 0b10000000 if b5.to_i == 1 byte += 0b01000000 if b4.to_i == 1 byte += 0b00100000 if b3.to_i == 1 byte += 0b00010000 if b2.to_i == 1 byte += 0b00001000 if b1.to_i == 1 byte += 0b00000100 if b0.to_i == 1 byte += 0b00000010 if local.to_i == 1 byte += 0b00000001 if multicast.to_i == 1 [byte,oui].pack("Cn") end |