From 7724459151daef704a6ec4549c0793b2a6e1c3ed Mon Sep 17 00:00:00 2001 From: mfranchi18 Date: Thu, 5 Jul 2018 15:09:51 -0500 Subject: [PATCH] Fix an issue where an exception was thrown when properties were referenced on undefined objects --- index.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 231c116..9921552 100644 --- a/index.js +++ b/index.js @@ -74,21 +74,26 @@ var register = function(mac_addresses, iface, timeout, protocol) { for (var i = 0, l = mac_addresses.length; i < l; i++) { var mac_address = mac_addresses[i]; - if((packet.payload.ethertype === 2054 //ensures it is an arp packet - && _.isEqual(packet.payload.payload.sender_ha.addr, - hex_to_int_array(mac_address))) - || (packet.payload.ethertype === 2048 - && _.isEqual(packet.payload.shost.addr, - hex_to_int_array(mac_address)))) { - if (just_emitted[mac_address]) { - break; - } + //sometimes the object properties referenced below throw exceptions because their parent object is undefined + try { + if((packet.payload.ethertype === 2054 //ensures it is an arp packet + && _.isEqual(packet.payload.payload.sender_ha.addr, + hex_to_int_array(mac_address))) + || (packet.payload.ethertype === 2048 + && _.isEqual(packet.payload.shost.addr, + hex_to_int_array(mac_address)))) { + if (just_emitted[mac_address]) { + break; + } - readStream.emit('detected', mac_address); - just_emitted[mac_address] = true; - setTimeout(function () { just_emitted[mac_address] = false; }, timeout); + readStream.emit('detected', mac_address); + just_emitted[mac_address] = true; + setTimeout(function () { just_emitted[mac_address] = false; }, timeout); - break; + break; + } + } catch (err) { + //console.error(err); } } });