4-bit protocol version (IP#version). Attended value is 4 for IPv4,
4-bit IP header length (`IP#ihl). Size of IP header in 32-bit words. As a IP header
is 20 bytes long, this value should be 5. It may be greater if header has options,
but options are not supported by PacketGen,
8-bit type of service (IP#tos),
16-bit total length (IP#length), size of IP packet, including the header,
16-bit ID (IP#id),
16-bit fragment word (IP#frag), used for IP fragmentation, composed of:
3 1-bit flags:
a reserved bit (IP#flag_rsv),
don't fragment flag (IP#flag_df) to forbid fragmentation of this packet,
more fragment flag (IP#flag_mf) to indicate a fragment, which is not the last
one, of a IP packt,
a 13-bit fragment offset (IP#fragment_offset),
8-bit time to live (IP#ttl),
8-bit protocol (IP#protocol) to indicate upper protocol (6 for TCP, and 17 for UDP
by example),
16-bit checksum (IP#checksum) of all IP packet,
32-bit source IP address (IP#src),
32-bit destination IP address (IP#dst),
a body (IP#body) containing data conveyed by IP.
A IP header may be built this way:
If not specified, id is a random number.
A IP packet may be created this way:
As you can see, checksum and length are not automatically set to correct values. But they may be set easily with IP#calc_sum, which computes checksum, and IP#calc_length which set correct length (taking care of body length). Packet#calc may be used too: it automatically call #calc_sum and #calc_length on all headers responding to them:
pkt.tcp.options.each do |opt|
# opt class is a subclass from Header::TCP::Option
p opt
puts "kind: #{opt.kind}"
puts "length: #{opt.length}"
puts "value: #{opt.value.inspect}"
end