Class: PacketGen::Types::OUI
- Defined in:
- lib/packetgen/types/oui.rb
Overview
OUI type, defined as a set of 3 bytes
oui = OUI.new
oui.from_human('00:01:02')
oui.to_human # => "00:01:02"
Instance Attribute Summary collapse
-
#b0 ⇒ Integer
Right-most byte.
-
#b1 ⇒ Integer
Center byte.
-
#b2 ⇒ Integer
Left-most byte.
Instance Method Summary collapse
-
#from_human(str) ⇒ OUI
Read a human-readable string to populate object.
-
#to_human ⇒ String
Get OUI in human readable form (colon-separated bytes).
Methods inherited from Fields
#[], #[]=, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, #force_binary, inherited, #initialize, #inspect, #read, #sz, #to_h, #to_s
Constructor Details
This class inherits a constructor from PacketGen::Types::Fields
Instance Attribute Details
#b0 ⇒ Integer
Returns right-most byte.
24 |
# File 'lib/packetgen/types/oui.rb', line 24 define_field :b0, Types::Int8 |
Instance Method Details
#from_human(str) ⇒ OUI
Read a human-readable string to populate object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/packetgen/types/oui.rb', line 29 def from_human(str) return self if str.nil? bytes = str.split(/:/) unless bytes.size == 3 raise ArgumentError, 'not a OUI' end self[:b2].read(bytes[0].to_i(16)) self[:b1].read(bytes[1].to_i(16)) self[:b0].read(bytes[2].to_i(16)) self end |
#to_human ⇒ String
Get OUI in human readable form (colon-separated bytes)
43 44 45 |
# File 'lib/packetgen/types/oui.rb', line 43 def to_human fields.map { |m| "#{'%02x' % self[m]}" }.join(':') end |