Class: PacketGen::Header::IPv6::Addr
- Includes:
- StructFu
- Defined in:
- lib/packetgen/header/ipv6.rb
Overview
IPv6 address, as a group of 8 2-byte words
Instance Attribute Summary collapse
-
#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.
-
#a6 ⇒ Object
Returns the value of attribute a6.
-
#a7 ⇒ Object
Returns the value of attribute a7.
-
#a8 ⇒ Object
Returns the value of attribute a8.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Addr
constructor
A new instance of Addr.
-
#parse(str) ⇒ self
Parse a colon-delimited address.
-
#read(str) ⇒ self
Read a Addr6 from a binary string.
-
#to_x ⇒ String
Addr6 in human readable form (colon-delimited hex string).
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #to_s, #typecast
Methods inherited from Struct
Constructor Details
#initialize(options = {}) ⇒ Addr
Returns a new instance of Addr.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/packetgen/header/ipv6.rb', line 29 def initialize(={}) super Int16.new([:a1]), Int16.new([:a2]), Int16.new([:a3]), Int16.new([:a4]), Int16.new([:a5]), Int16.new([:a6]), Int16.new([:a7]), Int16.new([:a8]) end |
Instance Attribute Details
#a1 ⇒ Object
Returns the value of attribute a1
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a1 @a1 end |
#a2 ⇒ Object
Returns the value of attribute a2
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a2 @a2 end |
#a3 ⇒ Object
Returns the value of attribute a3
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a3 @a3 end |
#a4 ⇒ Object
Returns the value of attribute a4
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a4 @a4 end |
#a5 ⇒ Object
Returns the value of attribute a5
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a5 @a5 end |
#a6 ⇒ Object
Returns the value of attribute a6
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a6 @a6 end |
#a7 ⇒ Object
Returns the value of attribute a7
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a7 @a7 end |
#a8 ⇒ Object
Returns the value of attribute a8
17 18 19 |
# File 'lib/packetgen/header/ipv6.rb', line 17 def a8 @a8 end |
Instance Method Details
#parse(str) ⇒ self
Parse a colon-delimited address
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/packetgen/header/ipv6.rb', line 43 def parse(str) return self if str.nil? addr = IPAddr.new(str) raise ArgumentError, 'string is not a IPv6 address' unless addr.ipv6? addri = addr.to_i self.a1 = addri >> 112 self.a2 = addri >> 96 & 0xffff self.a3 = addri >> 80 & 0xffff self.a4 = addri >> 64 & 0xffff self.a5 = addri >> 48 & 0xffff self.a6 = addri >> 32 & 0xffff self.a7 = addri >> 16 & 0xffff self.a8 = addri & 0xffff self end |
#read(str) ⇒ self
Read a Addr6 from a binary string
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/packetgen/header/ipv6.rb', line 62 def read(str) force_binary str self[:a1].read str[0, 2] self[:a2].read str[2, 2] self[:a3].read str[4, 2] self[:a4].read str[6, 2] self[:a5].read str[8, 2] self[:a6].read str[10, 2] self[:a7].read str[12, 2] self[:a8].read str[14, 2] self end |
#to_x ⇒ String
Addr6 in human readable form (colon-delimited hex string)
82 83 84 |
# File 'lib/packetgen/header/ipv6.rb', line 82 def to_x IPAddr.new(to_a.map { |a| a.to_i.to_s(16) }.join(':')).to_s end |