10

I've this sample Node.js script:

var mdns = require('mdns');

var browser = mdns.createBrowser(mdns.tcp('http'));
browser.on('error', function (error) {
    console.log("error");
    console.log(error);
});
browser.on('serviceUp', function (service) {
    console.log("serviceUp");
    console.log(service);
});
browser.start();

On my Mac it's working fine, and two services is found. If I run the exact same script on my Raspberry PI 2 running Raspbean (connected to the same network), I get this output:

pi@raspberrypi ~ $ node mdns.js 
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>
error
{ [Error: getaddrinfo -3008] code: -3008, errno: -3008, syscall: 'getaddrinfo' }
error
{ [Error: getaddrinfo -3008] code: -3008, errno: -3008, syscall: 'getaddrinfo' }

A issue on the mdns GitHub, states that it's fair to ignore the warnings.

But what about the two errors? Is that some kind of configuration issue on my Raspberry PI?

dhrm
  • 14,335
  • 34
  • 117
  • 183
  • Just for your information, `getaddrinfo` error codes can be translated into human-readable text using `gai_strerror`, defined in [`netdb.h`](http://pubs.opengroup.org/onlinepubs/7908799/xns/netdb.h.html). Unfortunately, the error code -3008 is represented as "Unknown error". My guess is that the error code comes from somewhere else than the `getaddrinfo` function, perhaps some underlying system call or whatever... – Robert Rossmann Apr 16 '15 at 08:29
  • which version of node.js is running on the raspberry pi? – flotto Apr 21 '15 at 13:36

2 Answers2

5

It's a bad practice to modify node modules code locally.

You should better do the following when you create a mdns Browser:

var sequence = [
  mdns.rst.DNSServiceResolve(),
  'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({families:[4]}),
  mdns.rst.makeAddressesUnique()
];
var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence});

Like said in this comment: https://github.com/agnat/node_mdns/issues/130#issuecomment-120731155

Thus, it will avoid bugs and allow everybody working on the project to get the same version and don't have to modify locally mdns code.

Art2B
  • 185
  • 1
  • 17
3

A solution was found on this GitHub issue: https://github.com/agnat/node_mdns/issues/130

Modify Browser.defaultResolverSequence inside lib/browser.js in mdns.

Browser.defaultResolverSequence = [
  rst.DNSServiceResolve(), 'DNSServiceGetAddrInfo' in dns_sd ? rst.DNSServiceGetAddrInfo() : rst.getaddrinfo({families:[4]})
, rst.makeAddressesUnique()
];
dhrm
  • 14,335
  • 34
  • 117
  • 183