Fixed bug
This commit is contained in:
parent
88748db36c
commit
d230d26825
12
main.js
12
main.js
@ -10,7 +10,7 @@
|
|||||||
*********************************/
|
*********************************/
|
||||||
|
|
||||||
// 0. HELPER FUNCTIONS
|
// 0. HELPER FUNCTIONS
|
||||||
function convertBufferToString(a) {if (a.data) for (i in a.data) a.data[i] = a.data[i].toString(); return a;}
|
|
||||||
|
|
||||||
// 1. Database functions
|
// 1. Database functions
|
||||||
function saveDbToFile(data, filename) {return fs.writeFileSync(filename,typeof data === 'object'?JSON.stringify(data):data);}
|
function saveDbToFile(data, filename) {return fs.writeFileSync(filename,typeof data === 'object'?JSON.stringify(data):data);}
|
||||||
@ -39,13 +39,13 @@ function sniffmDNSLocalPackets() {
|
|||||||
// 1. Listen for responses
|
// 1. Listen for responses
|
||||||
mdns.on('response', function(response) {
|
mdns.on('response', function(response) {
|
||||||
// console.log("got a new mDNS response.",response);
|
// console.log("got a new mDNS response.",response);
|
||||||
for (k in response.answers) {
|
for (let k in response.answers) {
|
||||||
let answer = response.answers[k];
|
let answer = response.answers[k];
|
||||||
|
|
||||||
// 1. Handle DEVICES for a given SERVICE
|
// 1. Handle DEVICES for a given SERVICE
|
||||||
if (answer.type == "PTR") {
|
if (answer.type == "PTR") {
|
||||||
// 1.1 Filter by RELEVANT SERVICE TYPES
|
// 1.1 Filter by RELEVANT SERVICE TYPES
|
||||||
if (!["in-addr.arpa","_googlecast._tcp.local","_tcp.local"].some(suffix => answer.name.endsWith(suffix))) return;
|
if (!["in-addr.arpa","_googlecast._tcp.local","_tcp.local"].some(suffix => answer.name.endsWith(suffix))) continue;
|
||||||
|
|
||||||
// 1.2 Initialize POINTERS (services) sub-database
|
// 1.2 Initialize POINTERS (services) sub-database
|
||||||
if (!db.local.PTR) db.local.PTR = {};
|
if (!db.local.PTR) db.local.PTR = {};
|
||||||
@ -122,9 +122,11 @@ const mdns = require('mdns-server')({interface: LOCAL_IP_ADDR,reuseAddr: true,lo
|
|||||||
sniffmDNSLocalPackets();
|
sniffmDNSLocalPackets();
|
||||||
|
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
|
if (!db.remote || !db.remote.PTR) return;
|
||||||
|
|
||||||
// INJECT PTR - Pointers services
|
// INJECT PTR - Pointers services
|
||||||
for (name in db.remote.PTR) {
|
for (let name in db.remote.PTR) {
|
||||||
for (i in db.remote.PTR[name])
|
for (let i in db.remote.PTR[name])
|
||||||
injectmDNSPacketLocally('PTR',name,db.remote.PTR[name][i]);
|
injectmDNSPacketLocally('PTR',name,db.remote.PTR[name][i]);
|
||||||
}
|
}
|
||||||
// INJECT A - Addresses
|
// INJECT A - Addresses
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user