Class: Spcap::IPPacket

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

Direct Known Subclasses

TCPPacket

Instance Attribute Summary

Attributes inherited from Packet

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

Instance Method Summary collapse

Methods inherited from Packet

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

Constructor Details

This class inherits a constructor from Spcap::Packet

Instance Method Details

#ip_dataObject

Return data part as String.



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

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

#ip_df?Boolean

Return true if Don’t Fragment bit is set.

Returns:

  • (Boolean)


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

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

#ip_dstObject

Return destination IP address as IPAddress.



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

def ip_dst
  @dst
end

#ip_flagsObject

Return the value of 3-bits IP flag field.



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

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

#ip_hlenObject

Return header length. (Unit: 4 octets)



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

def ip_hlen
  @raw_data.getbyte(0) & 0x0F
end

#ip_idObject

Return identification.



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

def ip_id
  @raw_data[4,4]
end

#ip_mf?Boolean

Return true if More Fragment bit is set.

Returns:

  • (Boolean)


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

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

#ip_offObject

Return fragment offset.



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

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

#ip_protoObject

Return the value of protocol field.



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

def ip_proto
  @raw_data.getbyte(9)
end

#ip_srcObject

Return source IP address as IPAddress.



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

def ip_src
  @src
end

#ip_sumObject

Return the value of checksum field.



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

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

#ip_tosObject

Return the value of TOS field.



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

def ip_tos
  # TODO
end

#ip_ttlObject

Return TTL.



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

def ip_ttl
  @raw_data.getbyte(8)
end

#ip_verObject

Return IP version.



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

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

#to_sObject

Return string representation.



89
90
91
# File 'lib/spcap/ippacket.rb', line 89

def to_s
  "TODO" # TODO
end