Sha256: 7478ce9929fb9bb0c5fddb41158011d7fbf7997c96ca259fa55d844801f54bf1
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
# coding: utf-8 # frozen_string_literal: true # This file is part of PacketGen # See https://github.com/lemontree55/packetgen for more informations # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net> # Copyright (C) 2024 LemonTree55 <lenontree@proton.me> # This program is published under MIT license. 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 include Fieldable # @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(':') 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 # 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
packetgen-3.3.3 | lib/packetgen/types/oui.rb |
packetgen-3.3.2 | lib/packetgen/types/oui.rb |