Class: FlowTag::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/flowtag/pcapparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, data) ⇒ Packet

Returns a new instance of Packet.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/flowtag/pcapparser.rb', line 60

def initialize(time, data)
	@time = time
	@data = data
	@length = data.length
	@ip = @tcp = @udp = false
	@ip_src = @ip_dst = @sport = @dport = @tcp_sport = @tcp_dport = @udp_sport = @udp_dport = nil
	@ip = (data[12,2].unpack("n")[0] == 0x0800) ? true : false
	offset = 14
	if @ip
		@ip_hlen = (data[offset,1].unpack("C")[0] & 0x0f) << 2
		@ip_proto = data[offset+9,1].unpack("C")[0]
		@ip_src, @ip_dst = data[offset+12,8].unpack("NN")
		offset += @ip_hlen
		@tcp = true if @ip_proto == 0x06
		@udp = true if @ip_proto == 0x11
		if @tcp
			@sport, @dport = data[offset,4].unpack("nn")
			@tcp_sport = @sport
			@tcp_dport = @dport
			@tcp_hlen = (data[offset+12,1].unpack("C")[0] >> 4) << 2
			offset += @tcp_hlen
		elsif @udp
			@sport, @dport = data[offset,4].unpack("nn")
			@udp_sport = @sport
			@udp_dport = @dport
			offset += 8
		end
	end
	@data_offset = offset
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def data
  @data
end

#dportObject (readonly)

Returns the value of attribute dport.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def dport
  @dport
end

#ip_dstObject (readonly)

Returns the value of attribute ip_dst.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def ip_dst
  @ip_dst
end

#ip_srcObject (readonly)

Returns the value of attribute ip_src.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def ip_src
  @ip_src
end

#lengthObject (readonly)

Returns the value of attribute length.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def length
  @length
end

#sportObject (readonly)

Returns the value of attribute sport.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def sport
  @sport
end

#tcp_dportObject (readonly)

Returns the value of attribute tcp_dport.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def tcp_dport
  @tcp_dport
end

#tcp_sportObject (readonly)

Returns the value of attribute tcp_sport.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def tcp_sport
  @tcp_sport
end

#timeObject (readonly)

Returns the value of attribute time.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def time
  @time
end

#udp_dportObject (readonly)

Returns the value of attribute udp_dport.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def udp_dport
  @udp_dport
end

#udp_sportObject (readonly)

Returns the value of attribute udp_sport.



59
60
61
# File 'lib/flowtag/pcapparser.rb', line 59

def udp_sport
  @udp_sport
end

Instance Method Details

#ip?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/flowtag/pcapparser.rb', line 91

def ip?
	@ip
end

#payloadObject



103
104
105
# File 'lib/flowtag/pcapparser.rb', line 103

def payload
	@data[@data_offset,10000]
end

#tcp?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/flowtag/pcapparser.rb', line 99

def tcp?
	@tcp
end

#udp?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/flowtag/pcapparser.rb', line 95

def udp?
	@udp
end