Sha256: 8631cbce3fb01a02d6773649709d544283005610a9cd7e857eb04859a47b7c2f
Contents?: true
Size: 1.39 KB
Versions: 4
Compression:
Stored size: 1.39 KB
Contents
# coding: utf-8 # This file is part of PacketGen # See https://github.com/sdaubert/packetgen for more informations # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net> # This program is published under MIT license. # frozen_string_literal: true module PacketGen module Types # 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 class OUI < Types::Fields # @attribute b2 # @return [Integer] left-most byte define_field :b2, Types::Int8 # @attribute b1 # @return [Integer] center byte define_field :b1, Types::Int8 # @attribute b0 # @return [Integer] right-most byte define_field :b0, Types::Int8 # Read a human-readable string to populate object # @param [String] str # @return [OUI] self 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 # Get OUI in human readable form (colon-separated bytes) # @return [String] def to_human fields.map { |m| "#{'%02x' % self[m]}" }.join(':') end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
packetgen-2.6.0 | lib/packetgen/types/oui.rb |
packetgen-2.5.2 | lib/packetgen/types/oui.rb |
packetgen-2.5.1 | lib/packetgen/types/oui.rb |
packetgen-2.5.0 | lib/packetgen/types/oui.rb |