Class: Pcap::TCPPacket

Inherits:
IPPacket show all
Defined in:
lib/pcap_misc.rb,
ext/tcp_packet.c

Instance Method Summary collapse

Methods inherited from IPPacket

#dst, #dst=, #ip_data, #ip_df?, #ip_dst, #ip_dst=, #ip_flags, #ip_hlen, #ip_id, #ip_len, #ip_mf?, #ip_off, #ip_proto, #ip_src, #ip_src=, #ip_sum, #ip_sum_update!, #ip_sumok?, #ip_tos, #ip_ttl, #ip_ver, #src, #src=

Methods inherited from Packet

#=~, #_dump, #_dump_to, _load, _load_from, #caplen, #datalink, #inspect, #ip?, #length, #raw_data, #size, #tcp?, #time, #time_i, #time_i=, #udata, #udata=, #udp?

Instance Method Details

#dportObject

#dst_mac_addressObject



42
43
44
# File 'lib/pcap_misc.rb', line 42

def dst_mac_address
  return unpack_hex_string(raw_data[0, 6])
end

#sportObject

#src_mac_addressObject



38
39
40
# File 'lib/pcap_misc.rb', line 38

def src_mac_address
  return unpack_hex_string(raw_data[6, 12])
end

#tcp_ackObject

#tcp_ack?Boolean

Returns:

  • (Boolean)

#tcp_dataObject

#tcp_data_lenObject



20
21
22
# File 'lib/pcap_misc.rb', line 20

def tcp_data_len
  ip_len - 4 * (ip_hlen + tcp_hlen)
end

#tcp_dportObject

#tcp_fin?Boolean

Returns:

  • (Boolean)

#tcp_flagsObject

#tcp_flags_sObject



24
25
26
27
28
29
30
31
32
# File 'lib/pcap_misc.rb', line 24

def tcp_flags_s
  return \
	(tcp_urg? ? 'U' : '.') +
	(tcp_ack? ? 'A' : '.') +
	(tcp_psh? ? 'P' : '.') +
	(tcp_rst? ? 'R' : '.') +
	(tcp_syn? ? 'S' : '.') +
    (tcp_fin? ? 'F' : '.')
end

#tcp_hlenObject

#tcp_offObject

#tcp_psh?Boolean

Returns:

  • (Boolean)

#tcp_rst?Boolean

Returns:

  • (Boolean)

#tcp_seqObject

#tcp_sportObject

#tcp_sumObject

#tcp_syn?Boolean

Returns:

  • (Boolean)

#tcp_urg?Boolean

Returns:

  • (Boolean)

#tcp_urpObject

#tcp_winObject

#to_sObject



34
35
36
# File 'lib/pcap_misc.rb', line 34

def to_s
  "#{src}:#{sport} > #{dst}:#{dport} #{tcp_flags_s}"
end

#unpack_hex_string(hex) ⇒ Object



46
47
48
# File 'lib/pcap_misc.rb', line 46

def unpack_hex_string(hex)
  return hex.unpack('H2H2H2H2H2H2').join('')
end