Class: PacketFu::IPv6Header
- Includes:
- StructFu
- Defined in:
- lib/packetfu/protos/ipv6/header.rb
Overview
IPv6Header is complete IPv6 struct, used in IPv6Packet.
Header Definition
Integer(4 bits) :ipv6_v Default: 6 # Versiom
Integer(8 bits) :ipv6_class Defualt: 0 # Class
Integer(20 bits) :ipv6_label Defualt: 0 # Label
Int16 :ipv6_len Default: calc # Payload length
Int8 :ipv6_next # Next Header
Int8 :ipv6_hop Default: 0xff # Hop limit
AddrIpv6 :ipv6_src
AddrIpv6 :ipv6_dst
String :body
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#ipv6_class ⇒ Object
Getter for the traffic class.
-
#ipv6_dst ⇒ Object
Getter for the destination address.
-
#ipv6_hop ⇒ Object
Getter for the hop limit.
-
#ipv6_label ⇒ Object
Getter for the flow label.
-
#ipv6_len ⇒ Object
Getter for the payload length.
-
#ipv6_next ⇒ Object
Getter for the next protocol header.
-
#ipv6_src ⇒ Object
Getter for the source address.
-
#ipv6_v ⇒ Object
Getter for the version (usually, 6).
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ IPv6Header
constructor
A new instance of IPv6Header.
-
#ipv6_calc_len ⇒ Object
Calculates the payload length.
-
#ipv6_daddr ⇒ Object
(also: #ipv6_dst_readable)
Get the destination address in a more readable form.
-
#ipv6_daddr=(str) ⇒ Object
Set the destination address in a more readable form.
-
#ipv6_recalc(arg = :all) ⇒ Object
Recalculates the calculatable fields for this object.
-
#ipv6_saddr ⇒ Object
(also: #ipv6_src_readable)
Get the source address in a more readable form.
-
#ipv6_saddr=(str) ⇒ Object
Set the source address in a more readable form.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_s ⇒ Object
Returns the object in string form.
Methods included from StructFu
#clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ IPv6Header
Returns a new instance of IPv6Header.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 81 def initialize(args={}) super( (args[:ipv6_v] || 6), (args[:ipv6_class] || 0), (args[:ipv6_label] || 0), Int16.new(args[:ipv6_len]), Int8.new(args[:ipv6_next]), Int8.new(args[:ipv6_hop] || 0xff), AddrIpv6.new.read(args[:ipv6_src] || ("\x00" * 16)), AddrIpv6.new.read(args[:ipv6_dst] || ("\x00" * 16)), StructFu::String.new.read(args[:body]) ) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def body @body end |
#ipv6_class ⇒ Object
Getter for the traffic class.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_class @ipv6_class end |
#ipv6_dst ⇒ Object
Getter for the destination address.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_dst @ipv6_dst end |
#ipv6_hop ⇒ Object
Getter for the hop limit.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_hop @ipv6_hop end |
#ipv6_label ⇒ Object
Getter for the flow label.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_label @ipv6_label end |
#ipv6_len ⇒ Object
Getter for the payload length.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_len @ipv6_len end |
#ipv6_next ⇒ Object
Getter for the next protocol header.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_next @ipv6_next end |
#ipv6_src ⇒ Object
Getter for the source address.
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_src @ipv6_src end |
#ipv6_v ⇒ Object
Getter for the version (usually, 6).
76 77 78 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 76 def ipv6_v @ipv6_v end |
Instance Method Details
#ipv6_calc_len ⇒ Object
Calculates the payload length.
153 154 155 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 153 def ipv6_calc_len self.ipv6_len = body.to_s.length end |
#ipv6_daddr ⇒ Object Also known as: ipv6_dst_readable
Get the destination address in a more readable form.
178 179 180 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 178 def ipv6_daddr self[:ipv6_dst].to_x end |
#ipv6_daddr=(str) ⇒ Object
Set the destination address in a more readable form.
183 184 185 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 183 def ipv6_daddr=(str) self[:ipv6_dst].read_x(str) end |
#ipv6_recalc(arg = :all) ⇒ Object
Recalculates the calculatable fields for this object.
158 159 160 161 162 163 164 165 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 158 def ipv6_recalc(arg=:all) case arg when :ipv6_len ipv6_calc_len when :all ipv6_recalc(:ipv6_len) end end |
#ipv6_saddr ⇒ Object Also known as: ipv6_src_readable
Get the source address in a more readable form.
168 169 170 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 168 def ipv6_saddr self[:ipv6_src].to_x end |
#ipv6_saddr=(str) ⇒ Object
Set the source address in a more readable form.
173 174 175 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 173 def ipv6_saddr=(str) self[:ipv6_src].read_x(str) end |
#read(str) ⇒ Object
Reads a string to populate the object.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 104 def read(str) force_binary(str) return self if str.nil? self[:ipv6_v] = str[0,1].unpack("C").first >> 4 self[:ipv6_class] = (str[0,2].unpack("n").first & 0x0ff0) >> 4 self[:ipv6_label] = str[0,4].unpack("N").first & 0x000fffff self[:ipv6_len].read(str[4,2]) self[:ipv6_next].read(str[6,1]) self[:ipv6_hop].read(str[7,1]) self[:ipv6_src].read(str[8,16]) self[:ipv6_dst].read(str[24,16]) self[:body].read(str[40,str.size]) if str.size > 40 self end |
#to_s ⇒ Object
Returns the object in string form.
96 97 98 99 100 101 |
# File 'lib/packetfu/protos/ipv6/header.rb', line 96 def to_s bytes_v_class_label = [(self.ipv6_v << 28) + (self.ipv6_class << 20) + self.ipv6_label].pack("N") bytes_v_class_label + (self.to_a[3,6].map {|x| x.to_s}.join) end |