class PacketGen::Types::OUI

OUI type, defined as a set of 3 bytes

oui = OUI.new
oui.from_human('00:01:02')
oui.to_human   # => "00:01:02"

@author Sylvain Daubert

Public Instance Methods

from_human(str) click to toggle source

Read a human-readable string to populate object @param [String] str @return [OUI] self

# File lib/packetgen/types/oui.rb, line 32
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() click to toggle source

Get OUI in human readable form (colon-separated bytes) @return [String]

# File lib/packetgen/types/oui.rb, line 46
def to_human
  fields.map { |m| '%02x' % self[m] }.join(':')
end