class Packetnom::Packet::IPv4
Attributes
checksum[RW]
dest[RW]
ds[RW]
dst[RW]
flags[RW]
from[RW]
id[RW]
ihl[RW]
len[RW]
length[RW]
offset[RW]
proto[RW]
protocol[RW]
source[RW]
src[RW]
sum[RW]
target[RW]
ttl[RW]
version[RW]
Attributes
Public Class Methods
new( bytes )
click to toggle source
Initialize the packet
# File lib/packet/ipv4.rb, line 22 def initialize( bytes ) offset = Hash[bytes[0..24].map.with_index.to_a]['45'] @version = bytes[offset].split(//)[0] @ihl = bytes[offset].split(//)[1] @ds = bytes[offset+1] @len = bytes[offset+2..offset+3].join().to_i(16) @id = bytes[offset+4..offset+5].join().to_i(16) options = bytes[offset+6..offset+7].join().to_i(16).to_s(2).rjust(16, '0') @flags = options[0..2].to_i(2).to_s(10) @offset = options[3..15].to_i(2).to_s(10) @ttl = bytes[offset+8].to_i(16) @proto = bytes[offset+9].to_i(16) @sum = bytes[offset+10..offset+11].join() @src = bytes[offset+12..offset+15].map{|octet| octet.to_i(16).to_s(10)}.join('.') @dst = bytes[offset+16..offset+19].map{|octet| octet.to_i(16).to_s(10)}.join('.') end
Public Instance Methods
protonum()
click to toggle source
# File lib/packet/ipv4.rb, line 45 def protonum @proto.to_i end