Class: DIY::Offline
- Inherits:
-
Object
- Object
- DIY::Offline
- Defined in:
- lib/diy/offline.rb
Instance Method Summary collapse
- #fetch_one ⇒ Object
- #filename ⇒ Object
- #files_size ⇒ Object
- #fullname ⇒ Object
-
#initialize(pcap_files) ⇒ Offline
constructor
A new instance of Offline.
- #next_pcap ⇒ Object
- #nexts ⇒ Object
- #now_size ⇒ Object
Constructor Details
#initialize(pcap_files) ⇒ Offline
Returns a new instance of Offline.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/diy/offline.rb', line 6 def initialize( pcap_files ) @pcap_files = [ pcap_files ] if pcap_files.kind_of?(String) @pcap_files ||= pcap_files @off = FFI::PCap::Offline.new(@pcap_files[0]) @ml = MacLearner.new # 记录文件在目录中的位置 @position = 0 # 记录包在当前文件的位置 @num = 0 @tmp_pcap = nil end |
Instance Method Details
#fetch_one ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/diy/offline.rb', line 46 def fetch_one pkt = fetch_cache if pkt.nil? pkt = self.next end pkt end |
#filename ⇒ Object
94 95 96 |
# File 'lib/diy/offline.rb', line 94 def filename @pcap_files[@position] end |
#files_size ⇒ Object
106 107 108 |
# File 'lib/diy/offline.rb', line 106 def files_size @pcap_files.size end |
#fullname ⇒ Object
98 99 100 |
# File 'lib/diy/offline.rb', line 98 def fullname "pkt: `#{filename}: #{@num}th' " end |
#next_pcap ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/diy/offline.rb', line 81 def next_pcap if @position >= @pcap_files.size - 1 raise EOFError, " end of pcaps " end # must close before's handle @off.close @position += 1 DIY::Logger.info("pcap file changed: #{@pcap_files[@position]} ( #{@position} of #{@pcap_files.size} )") @off = FFI::PCap::Offline.new(@pcap_files[@position]) @num = 0 fetch_cache end |
#nexts ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/diy/offline.rb', line 21 def nexts ret = [] # 取一个 pkt = fetch_one if pkt.nil? next_pcap pkt = fetch_one end ret << pkt where = @ml.tellme(pkt.content) loop do pkt = fetch_one return ret if pkt.nil? if @ml.tellme(pkt.content) != where cached(pkt) return ret else ret << pkt end end end |
#now_size ⇒ Object
102 103 104 |
# File 'lib/diy/offline.rb', line 102 def now_size @num end |