From ce4b0b03736096496f8fc5561e2069d2783dc80c Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Thu, 14 May 2020 10:51:32 +0000 Subject: [PATCH 1/4] upgrade to pcap3 --- package.json | 2 +- pcap.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 50535b9..cc9a873 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "node-red" ], "dependencies": { - "pcap": "^2.0.0" + "pcap": "^3.0.0" }, "node-red": { "nodes": { diff --git a/pcap.js b/pcap.js index 2b757bc..b200546 100644 --- a/pcap.js +++ b/pcap.js @@ -17,7 +17,7 @@ module.exports = function(RED) { "use strict"; var os = require('os'); - var pcap = require('pcap2'); + var pcap = require('pcap'); function PacketCapture(n) { RED.nodes.createNode(this, n); @@ -28,7 +28,7 @@ module.exports = function(RED) { node.path = n.path; if (node.ifname) { - node.session = pcap.createSession(node.ifname, node.filter); + node.session = pcap.createSession(node.ifname, {filter: node.filter}); node.session.on('packet', function (raw_packet) { var msg = {}; if (node.output == "raw") { @@ -59,7 +59,7 @@ module.exports = function(RED) { try { node.session.close(); } catch (err) { - node.error(err); + node.error("errpr", err); } }); } From 1fb4f44ee0f08da4e9d83966b9ac2e649be1e592 Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Thu, 14 May 2020 11:03:16 +0000 Subject: [PATCH 2/4] Workaround for issue https://github.com/node-pcap/node_pcap/pull/263 --- pcap.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pcap.js b/pcap.js index b200546..dfc5c8e 100644 --- a/pcap.js +++ b/pcap.js @@ -35,7 +35,7 @@ module.exports = function(RED) { msg.payload = raw_packet; } else { var decoded = pcap.decode.packet(raw_packet); - + if (node.path) { var pathParts = node.path.split("."); pathParts.reduce(function(obj, i) { @@ -47,7 +47,10 @@ module.exports = function(RED) { if (node.output == "object") { msg.payload = decoded; } else if (node.output == "string") { - msg.payload = String(decoded) + msg.payload = ''; + if (decoded.payload !== null) { + msg.payload = String(decoded); + } } } msg.topic = node.ifname; From d9ca0c57a780760f0006a5dd19acdc38bf065fd2 Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Thu, 14 May 2020 11:07:21 +0000 Subject: [PATCH 3/4] Workaround for issue https://github.com/node-pcap/node_pcap/pull/263 --- pcap.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pcap.js b/pcap.js index dfc5c8e..5ff2080 100644 --- a/pcap.js +++ b/pcap.js @@ -48,7 +48,8 @@ module.exports = function(RED) { msg.payload = decoded; } else if (node.output == "string") { msg.payload = ''; - if (decoded.payload !== null) { + // workaround for https://github.com/node-pcap/node_pcap/pull/263 + if (decoded.payload.payload !== null) { msg.payload = String(decoded); } } From 4b21126d83fe13f89e443b6ecbcd765333d8d60e Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Thu, 14 May 2020 11:09:05 +0000 Subject: [PATCH 4/4] Remove debug data --- pcap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcap.js b/pcap.js index 5ff2080..4a79cba 100644 --- a/pcap.js +++ b/pcap.js @@ -63,7 +63,7 @@ module.exports = function(RED) { try { node.session.close(); } catch (err) { - node.error("errpr", err); + node.error(err); } }); }