Class: PStream::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/pstream/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pcap, prot, id, desc, frames) ⇒ Stream

Returns a new instance of Stream.



54
55
56
57
58
59
60
# File 'lib/pstream/stream.rb', line 54

def initialize(pcap, prot, id, desc, frames)
    @desc = desc
    @frames = frames
    @id = id
    @pcap = pcap
    @prot = prot
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



4
5
6
# File 'lib/pstream/stream.rb', line 4

def desc
  @desc
end

#framesObject (readonly)

Returns the value of attribute frames.



5
6
7
# File 'lib/pstream/stream.rb', line 5

def frames
  @frames
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/pstream/stream.rb', line 6

def id
  @id
end

Instance Method Details

#contentsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pstream/stream.rb', line 8

def contents
    case @prot
    when /^tcp$/i
        stream=@id
    when /^udp$/i
        stream=@desc.gsub(" <-> ", ",")
    else
        raise PStream::Error::ProtocolNotSupported.new(@prot)
    end

    ret = Array.new
    %x(
        tshark -r #{@pcap} -z follow,#{@prot},hex,#{stream} | \
             sed "s|^	||" | \grep -E "^[0-9A-Fa-f]{8}"
    ).split("\n").each do |line|
        m = line.match(/([0-9A-Fa-f]{8}) (.*) (.{17})/)
        ret.push(
            [
                hilight_address(m[1]),
                hilight_hex(m[2]),
                hilight_ascii(m[3])
            ].join(" ")
        )
    end

    return ret.join("\n")
end

#to_sObject



62
63
64
# File 'lib/pstream/stream.rb', line 62

def to_s
    return contents
end