class PacketFu::AddrIpv6

AddrIpv6 handles addressing for IPv6Header

Header Definition

Int32 :a1
Int32 :a2
Int32 :a3
Int32 :a4

Public Class Methods

new(args={}) click to toggle source
Calls superclass method
# File lib/packetfu/protos/ipv6/header.rb, line 14
def initialize(args={})
  super(
    Int32.new(args[:a1]),
    Int32.new(args[:a2]),
    Int32.new(args[:a3]),
    Int32.new(args[:a4]))
end

Public Instance Methods

read(str) click to toggle source

Reads in a string and casts it as an IPv6 address

# File lib/packetfu/protos/ipv6/header.rb, line 38
def read(str)
  force_binary(str)
  return self if str.nil?
  self[:a1].read str[0,4]
  self[:a2].read str[4,4]
  self[:a3].read str[8,4]
  self[:a4].read str[12,4]
  self
end
read_x(str) click to toggle source

Reads in a colon-delimited hex string and casts it as an IPv6 address.

# File lib/packetfu/protos/ipv6/header.rb, line 49
def read_x(str)
  addr = IPAddr.new(str).to_i
  self[:a1]=Int32.new(addr >> 96)
  self[:a2]=Int32.new((addr & 0x00000000ffffffff0000000000000000) >> 64)
  self[:a3]=Int32.new((addr & 0x0000000000000000ffffffff00000000) >> 32)
  self[:a4]=Int32.new(addr & 0x000000000000000000000000ffffffff)
  self
end
to_i() click to toggle source

Returns the address as a fairly ginormous integer.

# File lib/packetfu/protos/ipv6/header.rb, line 28
def to_i
  (a1.to_i << 96) + (a2.to_i << 64) + (a3.to_i << 32) + a4.to_i
end
to_s() click to toggle source

Returns the address in string format.

# File lib/packetfu/protos/ipv6/header.rb, line 23
def to_s
  self.to_a.map {|x| x.to_s}.join
end
to_x() click to toggle source

Returns the address as a colon-delimited hex string.

# File lib/packetfu/protos/ipv6/header.rb, line 33
def to_x
  IPAddr.new(self.to_i, Socket::AF_INET6).to_s
end