Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where an exception was thrown when properties were refer… #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down