diff --git a/README.md b/README.md index 77aefd6..bcc427b 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,13 @@ If you no longer need to receive packets, you can use `pcap_session.close()`. To read packets from a file instead of from a live interface, use `createOfflineSession` instead: ```javascript -pcap.createOfflineSession('/path/to/capture.pcap', options); +const pcap_session = pcap.createOfflineSession('/path/to/capture.pcap', options); +pcap_session.on('packet', function (raw_packet) { + // do some stuff with a raw packet +}); +pcap_session.on('end', function () { + // do some stuff when file ends +}); ``` Where `options` only accepts the `filter` property. diff --git a/examples/tcp_metrics b/examples/tcp_metrics index 7f38d79..94ef3da 100755 --- a/examples/tcp_metrics +++ b/examples/tcp_metrics @@ -20,10 +20,6 @@ pcap_session.on("packet", function (raw_packet) { tcp_tracker.track_packet(packet); }); -pcap_session.on("complete", function () { - console.log("pcap session complete."); -}); - // tracker emits sessions, and sessions emit data tcp_tracker.on("session", function (session) { console.log("Start of TCP session between " + session.src_name + " and " + session.dst_name); diff --git a/pcap.js b/pcap.js index 9675b65..b3db700 100644 --- a/pcap.js +++ b/pcap.js @@ -82,6 +82,7 @@ function PcapSession(is_live, device_name, filter, buffer_size, snap_length, out do { packets = this.session.dispatch(this.buf, this.header); } while ( packets > 0 ); + this.emit("end"); this.emit("complete"); }); }