Class: PacketGen::Header::Eth::MacAddr
- Inherits:
-
BinStruct::Struct
- Object
- BinStruct::Struct
- PacketGen::Header::Eth::MacAddr
- Includes:
- BinStruct::Structable
- Defined in:
- lib/packetgen/header/eth.rb
Overview
Ethernet MAC address, as a group of 6 bytes
Instance Attribute Summary collapse
-
#a0 ⇒ Integer
First byte from MacAddr.
-
#a1 ⇒ Integer
Second byte from MacAddr.
-
#a2 ⇒ Integer
Third byte from MacAddr.
-
#a3 ⇒ Integer
Fourth byte from MacAddr.
-
#a4 ⇒ Integer
Fifth byte from MacAddr.
-
#a5 ⇒ Integer
Sixth byte from MacAddr.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equality check.
-
#from_human(str) ⇒ self
Read a human-readable string to populate
MacAddr
. -
#to_human ⇒ String
MacAddr
in human readable form (colon format).
Instance Attribute Details
#a0 ⇒ Integer
Returns first byte from MacAddr.
47 |
# File 'lib/packetgen/header/eth.rb', line 47 define_attr :a0, BinStruct::Int8 |
#a1 ⇒ Integer
Returns second byte from MacAddr.
50 |
# File 'lib/packetgen/header/eth.rb', line 50 define_attr :a1, BinStruct::Int8 |
#a2 ⇒ Integer
Returns third byte from MacAddr.
53 |
# File 'lib/packetgen/header/eth.rb', line 53 define_attr :a2, BinStruct::Int8 |
#a3 ⇒ Integer
Returns fourth byte from MacAddr.
56 |
# File 'lib/packetgen/header/eth.rb', line 56 define_attr :a3, BinStruct::Int8 |
#a4 ⇒ Integer
Returns fifth byte from MacAddr.
59 |
# File 'lib/packetgen/header/eth.rb', line 59 define_attr :a4, BinStruct::Int8 |
#a5 ⇒ Integer
Returns sixth byte from MacAddr.
62 |
# File 'lib/packetgen/header/eth.rb', line 62 define_attr :a5, BinStruct::Int8 |
Instance Method Details
#==(other) ⇒ Boolean
Equality check. true
only if other
is a MacAddr, and each address byte is the same.
91 92 93 94 |
# File 'lib/packetgen/header/eth.rb', line 91 def ==(other) other.is_a?(self.class) && attributes.all? { |attr| self[attr].value == other[attr].value } end |
#from_human(str) ⇒ self
Read a human-readable string to populate MacAddr
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/packetgen/header/eth.rb', line 71 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}"].from_human(bytes[i].to_i(16)) end self end |
#to_human ⇒ String
MacAddr
in human readable form (colon format)
85 86 87 |
# File 'lib/packetgen/header/eth.rb', line 85 def to_human attributes.map { |m| '%02x' % self[m] }.join(':') end |