Class: Packetnom::Packet::IPv4

Inherits:
Object
  • Object
show all
Defined in:
lib/packet/ipv4.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ IPv4

Initialize the packet



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Attribute Details

#dsObject

Returns the value of attribute ds.



10
11
12
# File 'lib/packet/ipv4.rb', line 10

def ds
  @ds
end

#dstObject Also known as: dest, target

Returns the value of attribute dst.



19
20
21
# File 'lib/packet/ipv4.rb', line 19

def dst
  @dst
end

#flagsObject

Returns the value of attribute flags.



13
14
15
# File 'lib/packet/ipv4.rb', line 13

def flags
  @flags
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/packet/ipv4.rb', line 12

def id
  @id
end

#ihlObject

Returns the value of attribute ihl.



9
10
11
# File 'lib/packet/ipv4.rb', line 9

def ihl
  @ihl
end

#lenObject Also known as: length

Returns the value of attribute len.



11
12
13
# File 'lib/packet/ipv4.rb', line 11

def len
  @len
end

#offsetObject

Returns the value of attribute offset.



14
15
16
# File 'lib/packet/ipv4.rb', line 14

def offset
  @offset
end

#protoObject Also known as: protocol

Returns the value of attribute proto.



16
17
18
# File 'lib/packet/ipv4.rb', line 16

def proto
  @proto
end

#srcObject Also known as: source, from

Returns the value of attribute src.



18
19
20
# File 'lib/packet/ipv4.rb', line 18

def src
  @src
end

#sumObject Also known as: checksum

Returns the value of attribute sum.



17
18
19
# File 'lib/packet/ipv4.rb', line 17

def sum
  @sum
end

#ttlObject

Returns the value of attribute ttl.



15
16
17
# File 'lib/packet/ipv4.rb', line 15

def ttl
  @ttl
end

#versionObject

Attributes



8
9
10
# File 'lib/packet/ipv4.rb', line 8

def version
  @version
end

Instance Method Details

#protonumObject



45
46
47
# File 'lib/packet/ipv4.rb', line 45

def protonum
    @proto.to_i
end