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
-
#initialize(options = {}) ⇒ MacAddr
constructor
A new instance of MacAddr.
-
#parse(str) ⇒ self
Parse a string to populate MacAddr.
-
#read(str) ⇒ self
Read a MacAddr from a string.
-
#to_x ⇒ String
Addr in human readable form (dotted 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
13 14 15 |
# File 'lib/packetgen/header/eth.rb', line 13 def a0 @a0 end |
#a1 ⇒ Object
Returns the value of attribute a1
13 14 15 |
# File 'lib/packetgen/header/eth.rb', line 13 def a1 @a1 end |
#a2 ⇒ Object
Returns the value of attribute a2
13 14 15 |
# File 'lib/packetgen/header/eth.rb', line 13 def a2 @a2 end |
#a3 ⇒ Object
Returns the value of attribute a3
13 14 15 |
# File 'lib/packetgen/header/eth.rb', line 13 def a3 @a3 end |
#a4 ⇒ Object
Returns the value of attribute a4
13 14 15 |
# File 'lib/packetgen/header/eth.rb', line 13 def a4 @a4 end |
#a5 ⇒ Object
Returns the value of attribute a5
13 14 15 |
# File 'lib/packetgen/header/eth.rb', line 13 def a5 @a5 end |
Instance Method Details
#parse(str) ⇒ self
Parse a string to populate MacAddr
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/packetgen/header/eth.rb', line 36 def parse(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 string
54 55 56 57 58 59 60 61 |
# File 'lib/packetgen/header/eth.rb', line 54 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_x ⇒ String
Addr in human readable form (dotted format)
70 71 72 |
# File 'lib/packetgen/header/eth.rb', line 70 def to_x members.map { |m| "#{'%02x' % self[m]}" }.join(':') end |