Class: Spcap::TCPPacket

Inherits:
IPPacket show all
Defined in:
lib/spcap/tcppacket.rb

Instance Attribute Summary

Attributes inherited from IPPacket

#dst, #ip_hlen, #ip_len, #src

Attributes inherited from Packet

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

Instance Method Summary collapse

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

#channelObject



8
# File 'lib/spcap/tcppacket.rb', line 8

def channel ; [[src,sport],[dst,dport]] ; end

#directionObject



11
# File 'lib/spcap/tcppacket.rb', line 11

def direction ; full_session == channel ; end

#dportObject



28
# File 'lib/spcap/tcppacket.rb', line 28

def dport ; tcp_dport ; end

#full_sessionObject



9
# File 'lib/spcap/tcppacket.rb', line 9

def full_session ; channel.sort ; end

#sessionObject



10
# File 'lib/spcap/tcppacket.rb', line 10

def session ; full_session.hash ; end

#sportObject



24
# File 'lib/spcap/tcppacket.rb', line 24

def sport ; tcp_sport ; end

#tcp_ackObject

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

Returns:

  • (Boolean)


46
# File 'lib/spcap/tcppacket.rb', line 46

def tcp_ack? ; flag?(3) ; end

#tcp_dataObject

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_lenObject

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_dportObject

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.

Returns:

  • (Boolean)


42
# File 'lib/spcap/tcppacket.rb', line 42

def tcp_fin? ; flag?(7) ; end

#tcp_flagsObject

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_sObject

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_hlenObject

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_offObject



51
# File 'lib/spcap/tcppacket.rb', line 51

def tcp_off ; tcp_hlen ; end

#tcp_psh?Boolean

Returns:

  • (Boolean)


45
# File 'lib/spcap/tcppacket.rb', line 45

def tcp_psh? ; flag?(4) ; end

#tcp_rst?Boolean

Returns:

  • (Boolean)


44
# File 'lib/spcap/tcppacket.rb', line 44

def tcp_rst? ; flag?(5) ; end

#tcp_seqObject

Return sequence number.



54
# File 'lib/spcap/tcppacket.rb', line 54

def tcp_seq ; ( ip_data[4,4].unpack("N").first ) ; end

#tcp_sportObject

Return destination port number.



23
# File 'lib/spcap/tcppacket.rb', line 23

def tcp_sport ; ip_data[0,2].unpack("n").first ; end

#tcp_sumObject

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

Returns:

  • (Boolean)


43
# File 'lib/spcap/tcppacket.rb', line 43

def tcp_syn? ; flag?(6) ; end

#tcp_urg?Boolean

Returns:

  • (Boolean)


47
# File 'lib/spcap/tcppacket.rb', line 47

def tcp_urg? ; flag?(2) ; end

#tcp_urpObject

Return urgent pointer.



60
# File 'lib/spcap/tcppacket.rb', line 60

def tcp_urp ; ( ip_data[18,2].unpack("n").first ) ; end

#tcp_winObject

Return window size.



63
# File 'lib/spcap/tcppacket.rb', line 63

def tcp_win ; ( ip_data[14,2].unpack("n").first ) ; end

#to_sObject

Return string representation.



66
# File 'lib/spcap/tcppacket.rb', line 66

def to_s ; "TODO" ; end