Unstable return of IPv4 address
Opened this issue · 1 comments
maziarzamani commented
I am experiencing problems with returning the IPv4 address on OSX.
Rarely i see a IPv4 address but rest of the time its IPv6.
When i check with the application Bonjour Browser
on OSX i see the IPv4 address without any problems, so i assume its an issue with the module.
Heres the code:
var mdns = require('mdns')
, listOfOscDevices = { /*name: {adresses: ['192.168.0.24', 'fe80::0:18'], port: 10001}}*/ }
;
var mdnsBrowser = mdns.createBrowser(mdns.udp('put'));
mdnsBrowser.on('serviceUp', function(service) {
// ignore duplicate ups
if(listOfOscDevices[service.name]) return;
listOfOscDevices[service.name] = {'addresses': service.addresses, 'port': service.port};
var cnt = Object.keys(listOfOscDevices).length;
console.log('osc device "'+service.name+' up at '+service.addresses+':'+service.port+', now '+cnt+' devices on the net');
});
mdnsBrowser.on('serviceDown', function(service) {
// ignore duplicate downs
if(!listOfOscDevices[service.name]) return;
var device = listOfOscDevices[service.name];
delete listOfOscDevices[service.name];
var cnt = Object.keys(listOfOscDevices).length;
console.log('osc device "'+service.name+' up at '+device.addresses+':'+device.port+', now '+cnt+' devices on the net');
});
console.log('listening for osc-compatible devices on the net')
mdnsBrowser.start();
agnat commented
Apologies for not responding...
Nope, the module is fine. It is how the underlying system service behaves. IIRC, the default is to return the first address available, which is (almost) always IPv6. You can fine-tune the behavior using the resolver chain, but there will be dragons...
The best cause of action is to fix the applications to support IPv6, though.