Class: Spcap::TCPPacket
- Defined in:
- lib/spcap/tcppacket.rb
Instance Attribute Summary
Attributes inherited from Packet
#caplen, #datalink, #len, #raw_data, #time
Instance Method Summary collapse
- #dport ⇒ Object
-
#initialize(time, data, len, datalink) ⇒ TCPPacket
constructor
A new instance of TCPPacket.
- #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_hlen, #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
#dport ⇒ Object
23 |
# File 'lib/spcap/tcppacket.rb', line 23 def dport ; tcp_dport ; end |
#sport ⇒ Object
19 |
# File 'lib/spcap/tcppacket.rb', line 19 def sport ; tcp_sport ; end |
#tcp_ack ⇒ Object
Return acknowledgement number.
9 |
# File 'lib/spcap/tcppacket.rb', line 9 def tcp_ack ; ip_data[8,4].unpack("N").first ; end |
#tcp_ack? ⇒ Boolean
41 |
# File 'lib/spcap/tcppacket.rb', line 41 def tcp_ack? ; flags?(3) ; end |
#tcp_data ⇒ Object
Return data part as String.
12 |
# File 'lib/spcap/tcppacket.rb', line 12 def tcp_data ; ip_data[tcp_off,tcp_data_len] ; end |
#tcp_data_len ⇒ Object
Return length of data part.
15 |
# File 'lib/spcap/tcppacket.rb', line 15 def tcp_data_len ; ip_len - ( ip_hlen * 4 ) - (tcp_hlen * 4) ; end |
#tcp_dport ⇒ Object
Return destination port number.
22 |
# File 'lib/spcap/tcppacket.rb', line 22 def tcp_dport ; ip_data[2,2].unpack("n").first ; end |
#tcp_fin? ⇒ Boolean
Return true if flag is set.
37 |
# File 'lib/spcap/tcppacket.rb', line 37 def tcp_fin? ; flags?(7) ; end |
#tcp_flags ⇒ Object
Return the value of 6-bits flag field.
26 |
# File 'lib/spcap/tcppacket.rb', line 26 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”.
29 30 31 32 33 34 |
# File 'lib/spcap/tcppacket.rb', line 29 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)
45 |
# File 'lib/spcap/tcppacket.rb', line 45 def tcp_hlen ; ( ( ip_data.getbyte(12) & 0XF0) / 16 ) ; end |
#tcp_off ⇒ Object
46 |
# File 'lib/spcap/tcppacket.rb', line 46 def tcp_off ; tcp_hlen ; end |
#tcp_psh? ⇒ Boolean
40 |
# File 'lib/spcap/tcppacket.rb', line 40 def tcp_psh? ; flags?(4) ; end |
#tcp_rst? ⇒ Boolean
39 |
# File 'lib/spcap/tcppacket.rb', line 39 def tcp_rst? ; flags?(5) ; end |
#tcp_seq ⇒ Object
Return sequence number.
49 |
# File 'lib/spcap/tcppacket.rb', line 49 def tcp_seq ; ( ip_data[4,4].unpack("N").first ) ; end |
#tcp_sport ⇒ Object
Return destination port number.
18 |
# File 'lib/spcap/tcppacket.rb', line 18 def tcp_sport ; ip_data[0,2].unpack("n").first ; end |
#tcp_sum ⇒ Object
Return the value of checksum field.
52 |
# File 'lib/spcap/tcppacket.rb', line 52 def tcp_sum ; ( ip_data[16,2].unpack("n").first ) ; end |
#tcp_syn? ⇒ Boolean
38 |
# File 'lib/spcap/tcppacket.rb', line 38 def tcp_syn? ; flags?(6) ; end |
#tcp_urg? ⇒ Boolean
42 |
# File 'lib/spcap/tcppacket.rb', line 42 def tcp_urg? ; flags?(2) ; end |
#tcp_urp ⇒ Object
Return urgent pointer.
55 |
# File 'lib/spcap/tcppacket.rb', line 55 def tcp_urp ; ( ip_data[18,2].unpack("n").first ) ; end |
#tcp_win ⇒ Object
Return window size.
58 |
# File 'lib/spcap/tcppacket.rb', line 58 def tcp_win ; ( ip_data[14,2].unpack("n").first ) ; end |
#to_s ⇒ Object
Return string representation.
61 |
# File 'lib/spcap/tcppacket.rb', line 61 def to_s ; "TODO" ; end |