class PacketGen::Header::Eth::MacAddr

Ethernet MAC address, as a group of 6 bytes @author Sylvain Daubert

Public Instance Methods

==(other) click to toggle source
# File lib/packetgen/header/eth.rb, line 78
def ==(other)
  other.is_a?(self.class) &&
    fields.all? { |attr| self[attr].value == other[attr].value }
end
from_human(str) click to toggle source

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

# File lib/packetgen/header/eth.rb, line 60
def from_human(str)
  return self if str.nil?

  bytes = str.split(/:/)
  raise ArgumentError, 'not a MAC address' unless bytes.size == 6

  6.times do |i|
    self["a#{i}".to_sym].read(bytes[i].to_i(16))
  end
  self
end
to_human() click to toggle source

MacAddr in human readable form (colon format) @return [String]

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