Class: PacketGen::Header::Eth::MacAddr
- Includes:
- StructFu
- Defined in:
- lib/packetgen/header/eth.rb
Overview
Ethernet MAC address, as a group of 6 bytes
Instance Attribute Summary collapse
-
#a0 ⇒ Object
Returns the value of attribute a0.
-
#a1 ⇒ Object
Returns the value of attribute a1.
-
#a2 ⇒ Object
Returns the value of attribute a2.
-
#a3 ⇒ Object
Returns the value of attribute a3.
-
#a4 ⇒ Object
Returns the value of attribute a4.
-
#a5 ⇒ Object
Returns the value of attribute a5.
Instance Method Summary collapse
-
#from_human(str) ⇒ self
Read a human-readable string to populate
MacAddr. -
#initialize(options = {}) ⇒ MacAddr
constructor
A new instance of MacAddr.
-
#read(str) ⇒ self
Read a
MacAddrfrom a binary string. -
#to_human ⇒ String
MacAddrin human readable form (colon format).
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #to_s, #typecast
Methods inherited from Struct
Constructor Details
Instance Attribute Details
#a0 ⇒ Object
Returns the value of attribute a0
38 39 40 |
# File 'lib/packetgen/header/eth.rb', line 38 def a0 @a0 end |
#a1 ⇒ Object
Returns the value of attribute a1
38 39 40 |
# File 'lib/packetgen/header/eth.rb', line 38 def a1 @a1 end |
#a2 ⇒ Object
Returns the value of attribute a2
38 39 40 |
# File 'lib/packetgen/header/eth.rb', line 38 def a2 @a2 end |
#a3 ⇒ Object
Returns the value of attribute a3
38 39 40 |
# File 'lib/packetgen/header/eth.rb', line 38 def a3 @a3 end |
#a4 ⇒ Object
Returns the value of attribute a4
38 39 40 |
# File 'lib/packetgen/header/eth.rb', line 38 def a4 @a4 end |
#a5 ⇒ Object
Returns the value of attribute a5
38 39 40 |
# File 'lib/packetgen/header/eth.rb', line 38 def a5 @a5 end |
Instance Method Details
#from_human(str) ⇒ self
Read a human-readable string to populate MacAddr
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/packetgen/header/eth.rb', line 61 def from_human(str) return self if str.nil? bytes = str.split(/:/) unless bytes.size == 6 raise ArgumentError, 'not a MAC address' end self[:a0].read(bytes[0].to_i(16)) self[:a1].read(bytes[1].to_i(16)) self[:a2].read(bytes[2].to_i(16)) self[:a3].read(bytes[3].to_i(16)) self[:a4].read(bytes[4].to_i(16)) self[:a5].read(bytes[5].to_i(16)) self end |
#read(str) ⇒ self
Read a MacAddr from a binary string
79 80 81 82 83 84 85 86 |
# File 'lib/packetgen/header/eth.rb', line 79 def read(str) return self if str.nil? raise ParseError, 'string too short for Eth' if str.size < self.sz force_binary str [:a0, :a1, :a2, :a3, :a4, :a5].each_with_index do |byte, i| self[byte].read str[i, 1] end end |
#to_human ⇒ String
MacAddr in human readable form (colon format)
95 96 97 |
# File 'lib/packetgen/header/eth.rb', line 95 def to_human members.map { |m| "#{'%02x' % self[m]}" }.join(':') end |