Class: Spcap::TCPPacket
- Defined in:
- lib/spcap/tcppacket.rb
Instance Attribute Summary
Attributes inherited from IPPacket
Attributes inherited from Packet
#caplen, #datalink, #len, #raw_data, #time
Instance Method Summary collapse
- #channel ⇒ Object
- #direction ⇒ Object
- #dport ⇒ Object
- #full_session ⇒ Object
-
#initialize(time, data, len, datalink) ⇒ TCPPacket
constructor
A new instance of TCPPacket.
- #session ⇒ Object
- #sport ⇒ Object
-
#tcp_ack ⇒ Object
Return acknowledgement number.
- #tcp_ack? ⇒ Boolean
-
#tcp_data ⇒ Object
Return data part as String.
-
#tcp_data_len ⇒ Object
Return length of data part.
-
#tcp_dport ⇒ Object
Return destination port number.
-
#tcp_fin? ⇒ Boolean
Return true if flag is set.
-
#tcp_flags ⇒ Object
Return the value of 6-bits flag field.
-
#tcp_flags_s ⇒ Object
Return the value of 6-bits flag field as string like “.A…F”.
-
#tcp_hlen ⇒ Object
Return TCP data offset (header length).
- #tcp_off ⇒ Object
- #tcp_psh? ⇒ Boolean
- #tcp_rst? ⇒ Boolean
-
#tcp_seq ⇒ Object
Return sequence number.
-
#tcp_sport ⇒ Object
Return destination port number.
-
#tcp_sum ⇒ Object
Return the value of checksum field.
- #tcp_syn? ⇒ Boolean
- #tcp_urg? ⇒ Boolean
-
#tcp_urp ⇒ Object
Return urgent pointer.
-
#tcp_win ⇒ Object
Return window size.
-
#to_s ⇒ Object
Return string representation.
Methods inherited from IPPacket
#ip_data, #ip_df?, #ip_dst, #ip_flags, #ip_id, #ip_mf?, #ip_off, #ip_proto, #ip_src, #ip_sum, #ip_tos, #ip_ttl, #ip_ver
Methods inherited from Packet
#ip?, #length, #size, #tcp?, #time_i, #udp?
Constructor Details
#initialize(time, data, len, datalink) ⇒ TCPPacket
Returns a new instance of TCPPacket.
4 5 6 |
# File 'lib/spcap/tcppacket.rb', line 4 def initialize(time,data,len,datalink) super(time,data,len,datalink) end |
Instance Method Details
#channel ⇒ Object
8 |
# File 'lib/spcap/tcppacket.rb', line 8 def channel ; [[src,sport],[dst,dport]] ; end |
#direction ⇒ Object
11 |
# File 'lib/spcap/tcppacket.rb', line 11 def direction ; full_session == channel ; end |
#dport ⇒ Object
28 |
# File 'lib/spcap/tcppacket.rb', line 28 def dport ; tcp_dport ; end |
#full_session ⇒ Object
9 |
# File 'lib/spcap/tcppacket.rb', line 9 def full_session ; channel.sort ; end |
#session ⇒ Object
10 |
# File 'lib/spcap/tcppacket.rb', line 10 def session ; full_session.hash ; end |
#sport ⇒ Object
24 |
# File 'lib/spcap/tcppacket.rb', line 24 def sport ; tcp_sport ; end |
#tcp_ack ⇒ Object
Return acknowledgement number.
14 |
# File 'lib/spcap/tcppacket.rb', line 14 def tcp_ack ; ip_data[8,4].unpack("N").first ; end |
#tcp_ack? ⇒ Boolean
46 |
# File 'lib/spcap/tcppacket.rb', line 46 def tcp_ack? ; flag?(3) ; end |
#tcp_data ⇒ Object
Return data part as String.
17 |
# File 'lib/spcap/tcppacket.rb', line 17 def tcp_data ; ip_data[tcp_off*4,tcp_data_len] ; end |
#tcp_data_len ⇒ Object
Return length of data part.
20 |
# File 'lib/spcap/tcppacket.rb', line 20 def tcp_data_len ; ip_len - ( ip_hlen * 4 ) - (tcp_hlen * 4) ; end |
#tcp_dport ⇒ Object
Return destination port number.
27 |
# File 'lib/spcap/tcppacket.rb', line 27 def tcp_dport ; ip_data[2,2].unpack("n").first ; end |
#tcp_fin? ⇒ Boolean
Return true if flag is set.
42 |
# File 'lib/spcap/tcppacket.rb', line 42 def tcp_fin? ; flag?(7) ; end |
#tcp_flags ⇒ Object
Return the value of 6-bits flag field.
31 |
# File 'lib/spcap/tcppacket.rb', line 31 def tcp_flags ; ( ip_data.getbyte(13) & 0x6F ) ; end |
#tcp_flags_s ⇒ Object
Return the value of 6-bits flag field as string like “.A…F”.
34 35 36 37 38 39 |
# File 'lib/spcap/tcppacket.rb', line 34 def tcp_flags_s ip_data[13].unpack("B*").first[2,6]. chars.zip(TCP_FLAGS.chars).collect { |flag,flag_s| (flag == '0' ? '.' : flag_s) }.join end |
#tcp_hlen ⇒ Object
Return TCP data offset (header length). (Unit: 4-octets)
50 |
# File 'lib/spcap/tcppacket.rb', line 50 def tcp_hlen ; ( ( ip_data.getbyte(12) & 0XF0) / 16 ) ; end |
#tcp_off ⇒ Object
51 |
# File 'lib/spcap/tcppacket.rb', line 51 def tcp_off ; tcp_hlen ; end |
#tcp_psh? ⇒ Boolean
45 |
# File 'lib/spcap/tcppacket.rb', line 45 def tcp_psh? ; flag?(4) ; end |
#tcp_rst? ⇒ Boolean
44 |
# File 'lib/spcap/tcppacket.rb', line 44 def tcp_rst? ; flag?(5) ; end |
#tcp_seq ⇒ Object
Return sequence number.
54 |
# File 'lib/spcap/tcppacket.rb', line 54 def tcp_seq ; ( ip_data[4,4].unpack("N").first ) ; end |
#tcp_sport ⇒ Object
Return destination port number.
23 |
# File 'lib/spcap/tcppacket.rb', line 23 def tcp_sport ; ip_data[0,2].unpack("n").first ; end |
#tcp_sum ⇒ Object
Return the value of checksum field.
57 |
# File 'lib/spcap/tcppacket.rb', line 57 def tcp_sum ; ( ip_data[16,2].unpack("n").first ) ; end |
#tcp_syn? ⇒ Boolean
43 |
# File 'lib/spcap/tcppacket.rb', line 43 def tcp_syn? ; flag?(6) ; end |
#tcp_urg? ⇒ Boolean
47 |
# File 'lib/spcap/tcppacket.rb', line 47 def tcp_urg? ; flag?(2) ; end |
#tcp_urp ⇒ Object
Return urgent pointer.
60 |
# File 'lib/spcap/tcppacket.rb', line 60 def tcp_urp ; ( ip_data[18,2].unpack("n").first ) ; end |
#tcp_win ⇒ Object
Return window size.
63 |
# File 'lib/spcap/tcppacket.rb', line 63 def tcp_win ; ( ip_data[14,2].unpack("n").first ) ; end |
#to_s ⇒ Object
Return string representation.
66 |
# File 'lib/spcap/tcppacket.rb', line 66 def to_s ; "TODO" ; end |