Class: Spcap::IPPacket
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#ip_hlen ⇒ Object
readonly
Returns the value of attribute ip_hlen.
-
#ip_len ⇒ Object
readonly
Returns the value of attribute ip_len.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Attributes inherited from Packet
#caplen, #datalink, #len, #raw_data, #time
Instance Method Summary collapse
-
#initialize(time, data, len, datalink) ⇒ IPPacket
constructor
A new instance of IPPacket.
-
#ip_data ⇒ Object
Return data part as String.
-
#ip_df? ⇒ Boolean
Return true if Don’t Fragment bit is set.
-
#ip_dst ⇒ Object
Return destination IP address as IPAddress.
-
#ip_flags ⇒ Object
Return the value of 3-bits IP flag field.
-
#ip_id ⇒ Object
Return identification.
-
#ip_mf? ⇒ Boolean
Return true if More Fragment bit is set.
-
#ip_off ⇒ Object
Return fragment offset.
-
#ip_proto ⇒ Object
Return the value of protocol field.
-
#ip_src ⇒ Object
Return source IP address as IPAddress.
-
#ip_sum ⇒ Object
Return the value of checksum field.
-
#ip_tos ⇒ Object
Return the value of TOS field.
-
#ip_ttl ⇒ Object
Return TTL.
-
#ip_ver ⇒ Object
Return IP version.
-
#to_s ⇒ Object
Return string representation.
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
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
3 4 5 |
# File 'lib/spcap/ippacket.rb', line 3 def dst @dst end |
#ip_hlen ⇒ Object (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_len ⇒ Object (readonly)
Returns the value of attribute ip_len.
3 4 5 |
# File 'lib/spcap/ippacket.rb', line 3 def ip_len @ip_len end |
#src ⇒ Object (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_data ⇒ Object
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.
26 27 28 |
# File 'lib/spcap/ippacket.rb', line 26 def ip_df? (@raw_data.getbyte(6) & 0x40) == 0x40 end |
#ip_dst ⇒ Object
Return destination IP address as IPAddress.
36 37 38 |
# File 'lib/spcap/ippacket.rb', line 36 def ip_dst @dst end |
#ip_flags ⇒ Object
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_id ⇒ Object
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.
31 32 33 |
# File 'lib/spcap/ippacket.rb', line 31 def ip_mf? (self.raw_data.getbyte(6) & 0x20) == 0x20 end |
#ip_off ⇒ Object
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_proto ⇒ Object
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_src ⇒ Object
Return source IP address as IPAddress.
40 41 42 |
# File 'lib/spcap/ippacket.rb', line 40 def ip_src @src end |
#ip_sum ⇒ Object
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_tos ⇒ Object
Return the value of TOS field.
67 68 69 |
# File 'lib/spcap/ippacket.rb', line 67 def ip_tos # TODO end |
#ip_ttl ⇒ Object
Return TTL.
73 74 75 |
# File 'lib/spcap/ippacket.rb', line 73 def ip_ttl @raw_data.getbyte(8) end |
#ip_ver ⇒ Object
Return IP version.
79 80 81 |
# File 'lib/spcap/ippacket.rb', line 79 def ip_ver ( @raw_data.getbyte(0) & 0xF0 ) / 16 end |
#to_s ⇒ Object
Return string representation.
84 85 86 |
# File 'lib/spcap/ippacket.rb', line 84 def to_s "TODO" # TODO end |