coapjs / node-coap

CoAP - Node.js style
MIT License
528 stars 154 forks source link

The device cannot be found when multiple IP addresses are configured for the network link #355

Closed Martin-CF closed 2 months ago

Martin-CF commented 1 year ago

The device can be found normally by configuring a single IP for my network link. When multiple IP addresses are configured, the device cannot be found. How to solve this problem? Thank you for your help。

htool commented 1 year ago

I ran into the same problem.

the function allAddresses should not include network aliases. They can be identied by the mac address:

function allAddresses(type) { var _a; let family = 'IPv4'; if (type === 'udp6') { family = 'IPv6'; } var macs = [] const addresses = []; const interfaces = os_1.default.networkInterfaces(); for (const ifname in interfaces) { if (ifname in interfaces) { (_a = interfaces[ifname]) === null || _a === void 0 ? void 0 : _a.forEach((a) => { if (a.family === family && macs.includes(a.mac) == false) { addresses.push(a.address); macs.push(a.mac); } }); } } return addresses; }

htool commented 1 year ago

I've added: https://github.com/coapjs/node-coap/pull/370