Class: Spcap::TCPPacket

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

Instance Attribute Summary

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_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

#dportObject



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

def dport ; tcp_dport ; end

#sportObject



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

def sport ; tcp_sport ; end

#tcp_ackObject

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

Returns:

  • (Boolean)


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

def tcp_ack? ; flags?(3) ; end

#tcp_dataObject

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_lenObject

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_dportObject

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.

Returns:

  • (Boolean)


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

def tcp_fin? ; flags?(7) ; end

#tcp_flagsObject

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_sObject

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_hlenObject

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_offObject



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

def tcp_off ; tcp_hlen ; end

#tcp_psh?Boolean

Returns:

  • (Boolean)


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

def tcp_psh? ; flags?(4) ; end

#tcp_rst?Boolean

Returns:

  • (Boolean)


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

def tcp_rst? ; flags?(5) ; end

#tcp_seqObject

Return sequence number.



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

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

#tcp_sportObject

Return destination port number.



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

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

#tcp_sumObject

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

Returns:

  • (Boolean)


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

def tcp_syn? ; flags?(6) ; end

#tcp_urg?Boolean

Returns:

  • (Boolean)


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

def tcp_urg? ; flags?(2) ; end

#tcp_urpObject

Return urgent pointer.



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

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

#tcp_winObject

Return window size.



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

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

#to_sObject

Return string representation.



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

def to_s ; "TODO" ; end