Class: PacketFu::EthOui

Inherits:
Struct
  • Object
show all
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

Fixnum   :b0
Fixnum   :b1
Fixnum   :b2
Fixnum   :b3
Fixnum   :b4
Fixnum   :b5
Fixnum   :local
Fixnum   :multicast
Int16    :oui,       Default: 0x1ac5 :)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#force_binary

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

#b0Object

Returns the value of attribute b0

Returns:

  • (Object)

    the current value of b0


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def b0
  @b0
end

#b1Object

Returns the value of attribute b1

Returns:

  • (Object)

    the current value of b1


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def b1
  @b1
end

#b2Object

Returns the value of attribute b2

Returns:

  • (Object)

    the current value of b2


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def b2
  @b2
end

#b3Object

Returns the value of attribute b3

Returns:

  • (Object)

    the current value of b3


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def b3
  @b3
end

#b4Object

Returns the value of attribute b4

Returns:

  • (Object)

    the current value of b4


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def b4
  @b4
end

#b5Object

Returns the value of attribute b5

Returns:

  • (Object)

    the current value of b5


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def b5
  @b5
end

#localObject

Returns the value of attribute local

Returns:

  • (Object)

    the current value of local


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def local
  @local
end

#multicastObject

Returns the value of attribute multicast

Returns:

  • (Object)

    the current value of multicast


18
19
20
# File 'lib/packetfu/protos/eth/header.rb', line 18

def multicast
  @multicast
end

#ouiObject

Returns the value of attribute oui

Returns:

  • (Object)

    the current value of 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_sObject

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