mfucci / node-matter

Matter protocol client / server for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling MDNS request from localhost

jdesai61 opened this issue · comments

Currently, the code throws an exception and exits if MDNS request is received from localhost (127.0.0.1)

Here is the message and my workaround

/home/me/tmp/node-matter/build/util/Network.js:42
    throw new Error(`Cannot find the device IP on the subnet containing ${remoteAddress}`);
    ^

Error: Cannot find the device IP on the subnet containing 127.0.0.1
    at getIpMacOnInterface (/home/me/tmp/node-matter/build/util/Network.js:42:11)
    at MdnsServer.handleDnsMessage (/home/me/tmp/node-matter/build/mdns/MdnsServer.js:33:63)
    at /home/me/tmp/node-matter/build/mdns/MdnsServer.js:24:63
    at Socket.<anonymous> (/home/me/tmp/node-matter/build/io/udp/UdpMulticastServer.js:28:77)
    at Socket.emit (node:events:513:28)
    at UDP.onMessage [as onmessage] (node:dgram:922:8)

Node.js v18.7.0
$:~/tmp/node-matter$ diff node-matter/build/mdns/MdnsServer.js node-matter.x/build/mdns/MdnsServer.js
24c24,27
<         multicastServer.onMessage((message, remoteIp) => this.handleDnsMessage(message, remoteIp));
---
>         multicastServer.onMessage((message, remoteIp) => { try {
>             this.handleDnsMessage(message, remoteIp);
>         }
>         catch (e) { } });

Thanks! Here is a fix to handle MDNS requests from localhost: #19

Let me know if this fixes the issue!

I have tested the fix - it works.