Class PacketFu::IPHeader
In: lib/packetfu/ip.rb
Parent: Struct.new(:ip_v, :ip_hl, :ip_tos, :ip_len, :ip_id, :ip_frag, :ip_ttl, :ip_proto, :ip_sum, :ip_src, :ip_dst, :body)

IPHeader is a complete IP struct, used in IPPacket. Most traffic on most networks today is IP-based.

For more on IP packets, see www.networksorcery.com/enp/protocol/ip.htm

Header Definition

  Fixnum (4 bits)  :ip_v,     Default: 4
  Fixnum (4 bits)  :ip_hl,    Default: 5
  Int8             :ip_tos,   Default: 0           # TODO: Break out the bits
  Int16            :ip_len,   Default: calculated
  Int16            :ip_id,    Default: calculated  # IRL, hardly random.
  Int16            :ip_frag,  Default: 0           # TODO: Break out the bits
  Int8             :ip_ttl,   Default: 0xff        # Changes per flavor
  Int8             :ip_proto, Default: 0x01        # TCP: 0x06, UDP 0x11, ICMP 0x01
  Int16            :ip_sum,   Default: calculated
  Octets           :ip_src
  Octets           :ip_dst
  String           :body

Note that IPPackets will always be somewhat incorrect upon initalization, and want an IPHeader#recalc() to become correct before a Packet#to_f or Packet#to_w.

Methods

ip_calc_id   ip_calc_len   ip_calc_sum   ip_daddr   ip_daddr=   ip_dst   ip_dst=   ip_frag   ip_frag=   ip_hl   ip_hl=   ip_id   ip_id=   ip_len   ip_len=   ip_proto   ip_proto=   ip_recalc   ip_saddr   ip_saddr=   ip_src   ip_src=   ip_sum   ip_sum=   ip_tos   ip_tos=   ip_ttl   ip_ttl=   ip_v   ip_v=   new   octet_array   read   to_s  

Included Modules

StructFu

Public Class methods

Translate various formats of IPv4 Addresses to an array of digits.

Public Instance methods

Retrieve the IP ID

Calulcate the true length of the packet.

Calculate the true checksum of the packet. (Yes, this is the long way to do it, but it‘s e-z-2-read for mathtards like me.)

Returns a more readable IP destination address.

Sets a more readable IP address.

Getter for the destination IP address.

Setter for the destination IP address.

Getter for the fragmentation ID.

Setter for the fragmentation ID.

Getter for the header length (multiply by 4)

Setter for the header length (divide by 4)

Getter for the identication number.

Setter for the identication number.

Getter for total length.

Setter for total length.

Getter for the protocol number.

Setter for the protocol number.

Recalculate the calculated IP fields. Valid arguments are:

  :all
  :ip_len
  :ip_sum
  :ip_id

Returns a more readable IP source address.

Sets a more readable IP address. If you wants to manipulate individual octets, (eg, for host scanning in one network), it would be better use ip_src.o1 through ip_src.o4 instead.

Getter for the source IP address.

Setter for the source IP address.

Getter for the checksum.

Setter for the checksum.

Getter for the differentiated services

Setter for the differentiated services

Getter for the time to live.

Setter for the time to live.

Getter for the version.

Setter for the version.

Reads a string to populate the object.

Returns the object in string form.

[Validate]