Class: PacketFu::AddrIpv6
- Includes:
- StructFu
- Defined in:
- lib/packetfu/protos/ipv6/header.rb
Overview
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.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ AddrIpv6
constructor
A new instance of AddrIpv6.
-
#read(str) ⇒ Object
Reads in a string and casts it as an IPv6 address.
-
#read_x(str) ⇒ Object
Reads in a colon-delimited hex string and casts it as an IPv6 address.
-
#to_i ⇒ Object
Returns the address as a fairly ginormous integer.
-
#to_s ⇒ Object
Returns the address in string format.
-
#to_x ⇒ Object
Returns the address as a colon-delimited hex string.
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
Instance Attribute Details
#a1 ⇒ Object
Returns the value of attribute a1
13 14 15 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 13 def a1 @a1 end |
#a2 ⇒ Object
Returns the value of attribute a2
13 14 15 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 13 def a2 @a2 end |
#a3 ⇒ Object
Returns the value of attribute a3
13 14 15 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 13 def a3 @a3 end |
#a4 ⇒ Object
Returns the value of attribute a4
13 14 15 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 13 def a4 @a4 end |
Instance Method Details
#read(str) ⇒ Object
Reads in a string and casts it as an IPv6 address
41 42 43 44 45 46 47 48 49 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 41 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) ⇒ Object
Reads in a colon-delimited hex string and casts it as an IPv6 address.
52 53 54 55 56 57 58 59 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 52 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 ⇒ Object
Returns the address as a fairly ginormous integer.
31 32 33 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 31 def to_i (a1.to_i << 96) + (a2.to_i << 64) + (a3.to_i << 32) + a4.to_i end |
#to_s ⇒ Object
Returns the address in string format.
26 27 28 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 26 def to_s self.to_a.map {|x| x.to_s}.join end |
#to_x ⇒ Object
Returns the address as a colon-delimited hex string.
36 37 38 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 36 def to_x IPAddr.new(self.to_i, Socket::AF_INET6).to_s end |