Class: Packetnom::Packet::Ip

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Ip

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/ip.rb', line 22

def initialize( bytes )
    @packet = bytes
    
    @version = bytes[14].split(//)[0]
    @ihl = bytes[14].split(//)[1]
    @ds = bytes[15]
    @len = bytes[16..17].join().to_i(16)
    @id = bytes[18..19].join()

    @flags = bytes[20].split(//)[0].to_i(16) #todo
    @offset = "#{bytes[20].split(//)[1]}#{bytes[21]}".to_i(16) #todo

    @ttl = bytes[22].to_i(16)
    @proto = bytes[23].to_i(16)
    @sum = bytes[24..25].join().to_i(16)
    @src = bytes[26..29].map{|octet| octet.to_i(16).to_s(10)}.join('.')
    @dst = bytes[30..33].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/ip.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/ip.rb', line 19

def dst
  @dst
end

#flagsObject

Returns the value of attribute flags.



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

def flags
  @flags
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#ihlObject

Returns the value of attribute ihl.



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

def ihl
  @ihl
end

#lenObject Also known as: length

Returns the value of attribute len.



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

def len
  @len
end

#offsetObject

Returns the value of attribute offset.



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

def offset
  @offset
end

#protoObject Also known as: protocol

Returns the value of attribute proto.



16
17
18
# File 'lib/packet/ip.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/ip.rb', line 18

def src
  @src
end

#sumObject Also known as: checksum

Returns the value of attribute sum.



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

def sum
  @sum
end

#ttlObject

Returns the value of attribute ttl.



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

def ttl
  @ttl
end

#versionObject

Attributes



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

def version
  @version
end