-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the library to create pcap files
under the hood it makes use of the libpcap's capability to create pcap the add-on makes use of the Async worker
- Loading branch information
1 parent
6b422a1
commit f6585fc
Showing
11 changed files
with
543 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,6 @@ node_modules | |
build | ||
|
||
#OSX garbage | ||
.DS_Store | ||
.DS_Store | ||
examples/*.pcap | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
|
||
|
||
var pcap = require("../pcap"), | ||
|
||
pcap_dump = new pcap.PcapDumpSession('en0', "ip proto \\tcp",10*1024*1024,"tmp95.pcap",false,5); | ||
|
||
pcap_dump.on('pcap_write_complete_async',function(message){ | ||
console.log("done.....",message); | ||
}); | ||
|
||
pcap_dump.on('pcap_write_error',function(message){ | ||
console.log("pcap_write_error.....",message); | ||
}); | ||
|
||
//pcap_dump.start(); | ||
pcap_dump.startAsyncCapture(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
var util = require("util"); | ||
var events = require("events"); | ||
var binding = require("./build/Release/pcap_binding"); | ||
|
||
|
||
function PcapDumpSession(device_name, filter, buffer_size, outfile, is_monitor, number_of_packets_to_be_read) { | ||
|
||
this.device_name = device_name; | ||
this.filter = filter || ""; | ||
this.buffer_size = buffer_size; | ||
this.outfile = outfile || "tmp.pcap"; | ||
this.is_monitor = Boolean(is_monitor); | ||
this.opened = null; | ||
this.packets_read = 0; | ||
this.number_of_packets_to_be_read = number_of_packets_to_be_read || 1; | ||
this.session = new binding.PcapSession(); | ||
|
||
if (typeof this.buffer_size === "number" && !isNaN(this.buffer_size)) { | ||
this.buffer_size = Math.round(this.buffer_size); | ||
} else { | ||
this.buffer_size = 10 * 1024 * 1024; // Default buffer size is 10MB | ||
} | ||
|
||
this.device_name = this.device_name || binding.default_device(); | ||
events.EventEmitter.call(this); | ||
} | ||
|
||
util.inherits(PcapDumpSession, events.EventEmitter); | ||
|
||
exports.lib_version = binding.lib_version(); | ||
|
||
exports.findalldevs = function () { | ||
return binding.findalldevs(); | ||
}; | ||
|
||
|
||
PcapDumpSession.prototype.startAsyncCapture = function () { | ||
|
||
this.opened = true; | ||
binding.create_pcap_dump_async( | ||
this.device_name, | ||
this.filter, | ||
this.buffer_size, | ||
this.outfile, | ||
PcapDumpSession.prototype.on_packet.bind(this), | ||
this.is_monitor, | ||
this.number_of_packets_to_be_read, | ||
PcapDumpSession.prototype.on_pcap_write_complete_async.bind(this) | ||
); | ||
}; | ||
|
||
|
||
PcapDumpSession.prototype.close = function () { | ||
this.opened = false; | ||
this.session.close(); | ||
}; | ||
|
||
PcapDumpSession.prototype.stats = function () { | ||
return this.session.stats(); | ||
}; | ||
|
||
PcapDumpSession.prototype.on_pcap_write_complete_async = function (err, packet_count) { | ||
|
||
if (err) { | ||
this.emit("pcap_write_error", err); | ||
|
||
} else { | ||
this.emit("pcap_write_complete_async", { | ||
"packets_read": packet_count, | ||
"fileName": this.outfile | ||
}); | ||
} | ||
|
||
}; | ||
|
||
|
||
PcapDumpSession.prototype.on_packet = function (packet) { | ||
this.emit("packet", packet); | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
exports.PcapDumpSession = PcapDumpSession; | ||
|
||
|
||
exports.createPcapDumpSession = function (device, filter, buffer_size, path, monitor, number_of_packets) { | ||
return new PcapDumpSession(device, filter, buffer_size, path, monitor, number_of_packets); | ||
}; |
Oops, something went wrong.