Class: PacketGen::Types::OUI
- Includes:
- Fieldable
- 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 included from Fieldable
#format_inspect, #read, #sz, #to_s, #type_name
Methods inherited from Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
This class inherits a constructor from PacketGen::Types::Fields
Instance Attribute Details
#b0 ⇒ Integer
Returns right-most byte.
28 |
# File 'lib/packetgen/types/oui.rb', line 28 define_field :b0, Types::Int8 |
Instance Method Details
#from_human(str) ⇒ OUI
Read a human-readable string to populate object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/packetgen/types/oui.rb', line 33 def from_human(str) return self if str.nil? bytes = str.split(':') raise ArgumentError, 'not a OUI' unless bytes.size == 3 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)
47 48 49 |
# File 'lib/packetgen/types/oui.rb', line 47 def to_human fields.map { |m| '%02x' % self[m] }.join(':') end |