Octets implements the addressing scheme for IP.
Header Definition
Int8 :o1 Int8 :o2 Int8 :o3 Int8 :o4
- PacketFu START:includes
Source: show
# File lib/packetfu/protos/ip.rb, line 15 def initialize(args={}) super( Int8.new(args[:o1]), Int8.new(args[:o2]), Int8.new(args[:o3]), Int8.new(args[:o4])) end
Reads a string to populate the object.
Source: show
# File lib/packetfu/protos/ip.rb, line 29 def read(str) force_binary(str) return self if str.nil? self[:o1].read str[0,1] self[:o2].read str[1,1] self[:o3].read str[2,1] self[:o4].read str[3,1] self end
Set the IP Address by reading a dotted-quad address.
Source: show
# File lib/packetfu/protos/ip.rb, line 52 def read_quad(str) read([IPAddr.new(str).to_i].pack("N")) end
Returns an address in numerical format.
Source: show
# File lib/packetfu/protos/ip.rb, line 46 def to_i ip_str = [o1, o2, o3, o4].map {|x| x.to_i.to_s}.join('.') IPAddr.new(ip_str).to_i end
Returns the object in string form.
Source: show
# File lib/packetfu/protos/ip.rb, line 24 def to_s self.to_a.map {|x| x.to_s}.join end
Returns an address in dotted-quad format.
Source: show
# File lib/packetfu/protos/ip.rb, line 40 def to_x ip_str = [o1, o2, o3, o4].map {|x| x.to_i.to_s}.join('.') IPAddr.new(ip_str).to_s end