Class: PacketGen::Header::IPv6::Addr

Inherits:
BinStruct::Struct
  • Object
show all
Includes:
BinStruct::Structable
Defined in:
lib/packetgen/header/ipv6/addr.rb

Overview

IPv6 address, as a group of 8 2-byte words

Author:

  • Sylvain Daubert

  • LemonTree55

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#a1Integer

1st 2-byte word of IPv6 address

Returns:

  • (Integer)


24
# File 'lib/packetgen/header/ipv6/addr.rb', line 24

define_attr :a1, BinStruct::Int16

#a2Integer

2nd 2-byte word of IPv6 address

Returns:

  • (Integer)


28
# File 'lib/packetgen/header/ipv6/addr.rb', line 28

define_attr :a2, BinStruct::Int16

#a3Integer

3rd 2-byte word of IPv6 address

Returns:

  • (Integer)


32
# File 'lib/packetgen/header/ipv6/addr.rb', line 32

define_attr :a3, BinStruct::Int16

#a4Integer

4th 2-byte word of IPv6 address

Returns:

  • (Integer)


36
# File 'lib/packetgen/header/ipv6/addr.rb', line 36

define_attr :a4, BinStruct::Int16

#a5Integer

5th 2-byte word of IPv6 address

Returns:

  • (Integer)


40
# File 'lib/packetgen/header/ipv6/addr.rb', line 40

define_attr :a5, BinStruct::Int16

#a6Integer

6th 2-byte word of IPv6 address

Returns:

  • (Integer)


44
# File 'lib/packetgen/header/ipv6/addr.rb', line 44

define_attr :a6, BinStruct::Int16

#a7Integer

7th 2-byte word of IPv6 address

Returns:

  • (Integer)


48
# File 'lib/packetgen/header/ipv6/addr.rb', line 48

define_attr :a7, BinStruct::Int16

#a8Integer

8th 2-byte word of IPv6 address

Returns:

  • (Integer)


52
# File 'lib/packetgen/header/ipv6/addr.rb', line 52

define_attr :a8, BinStruct::Int16

Instance Method Details

#==(other) ⇒ Boolean

Check equaliy to other. Equal if other has the same class, and all attributes are equal

Returns:

  • (Boolean)


92
93
94
95
# File 'lib/packetgen/header/ipv6/addr.rb', line 92

def ==(other)
  other.is_a?(self.class) &&
    attributes.all? { |attr| self[attr].value == other[attr].value }
end

#from_human(str) ⇒ self

Read a colon-delimited address

Parameters:

  • str (String)

Returns:

  • (self)

Raises:

  • (ArgumentError)

    not a colon-delimited IPv6 address



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/packetgen/header/ipv6/addr.rb', line 58

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
  8.times do |i|
    self.send(:"a#{i + 1}=", addri >> (16 * (7 - i)) & 0xffff)
  end
  self
end

#mcast?Boolean

Return true if this address is a multicast one

Returns:

  • (Boolean)


85
86
87
# File 'lib/packetgen/header/ipv6/addr.rb', line 85

def mcast?
  self.a1 & 0xff00 == 0xff00
end

#to_aArray<Integer>

Return an array of address 16-bit words

Returns:

  • (Array<Integer>)


79
80
81
# File 'lib/packetgen/header/ipv6/addr.rb', line 79

def to_a
  @attributes.values
end

#to_humanString

Return IPv6 address in human readable form (colon-delimited hex string)

Returns:

  • (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