Skip to content

Instantly share code, notes, and snippets.

@boxofrad
Created November 3, 2016 16:32
Show Gist options
  • Save boxofrad/b1957b6ab3e6a4236d673980a64a99a3 to your computer and use it in GitHub Desktop.
Save boxofrad/b1957b6ab3e6a4236d673980a64a99a3 to your computer and use it in GitHub Desktop.
class EthernetFrame
attr_reader :bytes
def initialize(bytes)
@bytes = bytes
end
def destination_mac
format_mac(bytes[0, 6])
end
def source_mac
format_mac(bytes[6, 6])
end
private
def format_mac(mac_bytes)
mac_bytes.map do |byte|
byte.to_s(16).rjust(2, '0')
end.join(':').upcase
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment