Class: Spcap::IPPacket

Inherits:
Packet
  • Object
show all
Defined in:
lib/spcap/ippacket.rb

Direct Known Subclasses

TCPPacket

Instance Attribute Summary collapse

Attributes inherited from Packet

#caplen, #datalink, #len, #raw_data, #time

Instance Method Summary collapse

Methods inherited from Packet

#ip?, #length, #size, #tcp?, #time_i, #udp?

Constructor Details

#initialize(time, data, len, datalink) ⇒ IPPacket

Returns a new instance of IPPacket.



5
6
7
8
9
10
11
12
# File 'lib/spcap/ippacket.rb', line 5

def initialize(time,data,len,datalink)
  super(time,data,len,datalink)
  @src = IPAddress.new(@raw_data[12,4])
  @dst = IPAddress.new(data[16,4])
  @ip_hlen = @raw_data.getbyte(0) & 0x0F
  @ip_len = @raw_data[2,2].unpack("n").first
  
end

Instance Attribute Details

#dstObject (readonly)

Returns the value of attribute dst.



3
4
5
# File 'lib/spcap/ippacket.rb', line 3

def dst
  @dst
end

#ip_hlenObject (readonly)

Returns the value of attribute ip_hlen.



3
4
5
# File 'lib/spcap/ippacket.rb', line 3

def ip_hlen
  @ip_hlen
end

#ip_lenObject (readonly)

Returns the value of attribute ip_len.



3
4
5
# File 'lib/spcap/ippacket.rb', line 3

def ip_len
  @ip_len
end

#srcObject (readonly)

Returns the value of attribute src.



3
4
5
# File 'lib/spcap/ippacket.rb', line 3

def src
  @src
end

Instance Method Details

#ip_dataObject

Return data part as String.



15
16
17
# File 'lib/spcap/ippacket.rb', line 15

def ip_data
  @raw_data[ip_hlen*4,self.caplen-ip_hlen*4]
end

#ip_df?Boolean

Return true if Don’t Fragment bit is set.

Returns:

  • (Boolean)


26
27
28
# File 'lib/spcap/ippacket.rb', line 26

def ip_df?
  (@raw_data.getbyte(6) & 0x40) == 0x40
end

#ip_dstObject

Return destination IP address as IPAddress.



36
37
38
# File 'lib/spcap/ippacket.rb', line 36

def ip_dst
  @dst
end

#ip_flagsObject

Return the value of 3-bits IP flag field.



21
22
23
# File 'lib/spcap/ippacket.rb', line 21

def ip_flags
  @raw_data.getbyte(6) & 0xE0
end

#ip_idObject

Return identification.



45
46
47
# File 'lib/spcap/ippacket.rb', line 45

def ip_id
  @raw_data[4,4]
end

#ip_mf?Boolean

Return true if More Fragment bit is set.

Returns:

  • (Boolean)


31
32
33
# File 'lib/spcap/ippacket.rb', line 31

def ip_mf?
  (self.raw_data.getbyte(6) & 0x20) == 0x20
end

#ip_offObject

Return fragment offset.



50
51
52
# File 'lib/spcap/ippacket.rb', line 50

def ip_off
  @raw_data[4,4].unpack("n").first & 0xFFF
end

#ip_protoObject

Return the value of protocol field.



56
57
58
# File 'lib/spcap/ippacket.rb', line 56

def ip_proto
  @raw_data.getbyte(9)
end

#ip_srcObject

Return source IP address as IPAddress.



40
41
42
# File 'lib/spcap/ippacket.rb', line 40

def ip_src
  @src
end

#ip_sumObject

Return the value of checksum field.



61
62
63
# File 'lib/spcap/ippacket.rb', line 61

def ip_sum
  @raw_data[10,2].unpack("n").fisrt
end

#ip_tosObject

Return the value of TOS field.



67
68
69
# File 'lib/spcap/ippacket.rb', line 67

def ip_tos
  # TODO
end

#ip_ttlObject

Return TTL.



73
74
75
# File 'lib/spcap/ippacket.rb', line 73

def ip_ttl
  @raw_data.getbyte(8)
end

#ip_verObject

Return IP version.



79
80
81
# File 'lib/spcap/ippacket.rb', line 79

def ip_ver
  ( @raw_data.getbyte(0) & 0xF0 ) / 16
end

#to_sObject

Return string representation.



84
85
86
# File 'lib/spcap/ippacket.rb', line 84

def to_s
  "TODO" # TODO
end