Class: PacketGen::Header::IPv6::Addr
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::IPv6::Addr
- Defined in:
- lib/packetgen/header/ipv6/addr.rb
Overview
IPv6 address, as a group of 8 2-byte words
Instance Attribute Summary collapse
-
#a1 ⇒ Integer
1st 2-byte word of IPv6 address.
-
#a2 ⇒ Integer
2nd 2-byte word of IPv6 address.
-
#a3 ⇒ Integer
3rd 2-byte word of IPv6 address.
-
#a4 ⇒ Integer
4th 2-byte word of IPv6 address.
-
#a5 ⇒ Integer
5th 2-byte word of IPv6 address.
-
#a6 ⇒ Integer
6th 2-byte word of IPv6 address.
-
#a7 ⇒ Integer
7th 2-byte word of IPv6 address.
-
#a8 ⇒ Integer
8th 2-byte word of IPv6 address.
Instance Method Summary collapse
-
#from_human(str) ⇒ self
Read a colon-delimited address.
-
#mcast? ⇒ Boolean
Return true if this address is a multicast one.
-
#to_a ⇒ Array<Integer>
Return an array of address 16-bit words.
-
#to_human ⇒ String
Addr6 in human readable form (colon-delimited hex string).
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
This class inherits a constructor from PacketGen::Types::Fields
Instance Attribute Details
#a1 ⇒ Integer
1st 2-byte word of IPv6 address
20 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 20 define_field :a1, Types::Int16 |
#a2 ⇒ Integer
2nd 2-byte word of IPv6 address
24 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 24 define_field :a2, Types::Int16 |
#a3 ⇒ Integer
3rd 2-byte word of IPv6 address
28 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 28 define_field :a3, Types::Int16 |
#a4 ⇒ Integer
4th 2-byte word of IPv6 address
32 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 32 define_field :a4, Types::Int16 |
#a5 ⇒ Integer
5th 2-byte word of IPv6 address
36 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 36 define_field :a5, Types::Int16 |
#a6 ⇒ Integer
6th 2-byte word of IPv6 address
40 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 40 define_field :a6, Types::Int16 |
#a7 ⇒ Integer
7th 2-byte word of IPv6 address
44 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 44 define_field :a7, Types::Int16 |
#a8 ⇒ Integer
8th 2-byte word of IPv6 address
48 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 48 define_field :a8, Types::Int16 |
Instance Method Details
#from_human(str) ⇒ self
Read a colon-delimited address
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 53 def from_human(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 |
#mcast? ⇒ Boolean
Return true if this address is a multicast one
85 86 87 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 85 def mcast? self.a1 & 0xff00 == 0xff00 end |
#to_a ⇒ Array<Integer>
Return an array of address 16-bit words
79 80 81 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 79 def to_a @fields.values end |
#to_human ⇒ String
Addr6 in human readable form (colon-delimited hex string)
73 74 75 |
# File 'lib/packetgen/header/ipv6/addr.rb', line 73 def to_human IPAddr.new(to_a.map { |a| a.to_i.to_s(16) }.join(':')).to_s end |