var dns_sd = require('./dns_sd');

function supportsInterfaceIndexLocalOnly() {
  try {
    var sr = new dns_sd.DNSServiceRef()
      , flags  = 0
      , iface  = dns_sd.kDNSServiceInterfaceIndexLocalOnly
      , name   = null
      , type   = '_http._tcp'
      , domain = null
      , host   = null
      , port   = 4321
      , txtRec = null
      , cb     = null
      , ctx    = null
      ;
    dns_sd.DNSServiceRegister( sr, flags, iface, name, type, domain,
          host, port, txtRec, cb, ctx);
  } catch (ex) {
    if (ex.errorCode === dns_sd.kDNSServiceErr_Unsupported) {
      if (sr && sr.initialized) {
        dns_sd.DNSServiceRefDeallocate(sr);
      }
      return false;
    }
    console.warn('Unexpected result while probing for avahi:', ex);
  }
  dns_sd.DNSServiceRefDeallocate(sr);
  return true;
}

module.exports = ! supportsInterfaceIndexLocalOnly();

var dns_sd = require('./dns_sd');

function supportsInterfaceIndexLocalOnly() {
  try {
    var sr = new dns_sd.DNSServiceRef()
      , flags  = 0
      , iface  = dns_sd.kDNSServiceInterfaceIndexLocalOnly
      , name   = null
      , type   = '_http._tcp'
      , domain = null
      , host   = null
      , port   = 4321
      , txtRec = null
      , cb     = null
      , ctx    = null
      ;
    dns_sd.DNSServiceRegister( sr, flags, iface, name, type, domain,
          host, port, txtRec, cb, ctx);
  } catch (ex) {
    if (ex.errorCode === dns_sd.kDNSServiceErr_Unsupported) {
      if (sr && sr.initialized) {
        dns_sd.DNSServiceRefDeallocate(sr);
      }
      return false;
    }
    console.warn('Unexpected result while probing for avahi:', ex);
  }
  if (sr && sr.initialized) {
    dns_sd.DNSServiceRefDeallocate(sr);
  }
  return true;
}

module.exports = ! supportsInterfaceIndexLocalOnly();

Fix exception from require('mdns') if Avahi detection fails with an unexpected error
Fix exception from require('mdns') if Avahi detection fails with an unexpected error

It can also fail e.g. with kDNSServiceErr_ServiceNotRunning (at least on Windows).
