{"_id":"@alcalzone/mdns-server","_rev":"1-04de23addb39a3ebb9c74b8a0293142d","name":"@alcalzone/mdns-server","dist-tags":{"latest":"1.0.6"},"versions":{"1.0.6":{"name":"@alcalzone/mdns-server","version":"1.0.6","description":"Low level Multicast DNS implementation in pure javascript.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/AlCalzone/mdns-server.git"},"author":{"name":"Bryan Nielsen","url":"@bnielsen1965"},"contributors":[{"name":"AlCalzone","url":"d.griesel@gmx.net"}],"license":"MIT","dependencies":{"dns-packet":"^1.1.1"},"gitHead":"2f990b4e482647ce8ef187dec5bae0f05588843e","bugs":{"url":"https://github.com/AlCalzone/mdns-server/issues"},"homepage":"https://github.com/AlCalzone/mdns-server#readme","_id":"@alcalzone/mdns-server@1.0.6","_npmVersion":"6.2.0","_nodeVersion":"10.0.0","_npmUser":{"name":"alcalzone","email":"d.griesel@gmx.net"},"dist":{"integrity":"sha512-DOdXaLcI1g3DS9S0kAQTcM8RV/L6WSApxO489XLQpm7JrCtXQ6GaF1Wooi31emW/RLp6B2C/DgjheX8ceScSOg==","shasum":"231a83f0a86b1d821a9d7c0db1a1f4d44fb7080c","tarball":"https://registry.npmjs.org/@alcalzone/mdns-server/-/mdns-server-1.0.6.tgz","fileCount":3,"unpackedSize":18279,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbkCY6CRA9TVsSAnZWagAAhAYP/A0gfrMqNy7JJhN564mh\nBYlP2CWYMrRmkIG3W4fXIiNRckz+ZGB51Wo2Zva2NGdwXPhHPD4JfnK4Zk56\n1GNSaclx8oXc8rdhrZRo00xu+15ZajOs6XI8sLPsgPcQn51gRe2Hizs7JfZA\nJI5luUgmGQ9I3t9zV4cT+ekg85O3jgSqok3y8vkH7wEvrDzoVM5IRhkvz3Ap\nzFKafmpzT4zwGa1A3x0RElRh+xQ3PAvhR1MQuezS1nMZKomb/V49/LmDLg2e\nBXAmOwmvKEEevTEtPaIIJF60Xbi5l5YqzZsn7u2nBTQIPcg3OkCoGOyiQmG/\nKFGD874ENKfclsRDdNh4szZ/7ZW/GNcE82cxlUBtSqEZjN+1tC8fArGS1U6C\nltxrtlm5wcV5Ls3zVhfz7D1JYomIMbeXg9t6/3oDpEtxgT5YCQJp9skjLgor\n4ZY8xnRXuQnIEg1cNvnMmVBlweZs4dQT+E0PBvY5+0Sv9Kl29Jq86joX51o+\nAnSE6DYabCrWBzDx4hCszBwh7GDmfvTNyc2uuEew07qVowOlrGEswEGhJGCB\nQ1wDCzvPwejSt9fi3hsE+rZpyI20fbu3SKofwQ60V3O25KtGmCdmisaafeG3\nBByU4qCpMLY0tJxF7vxmej/pidlQLmwMRxEmCbbsd/hjT/WsOLTPyjyyRsW8\nyndP\r\n=niCo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB8IivsAuokVvP8axZ9iU9nckbwoLVZCvtpe4rKUVJwiAiAd2s5MYQ9E0X1bjIImhbeWnM5tQ+sBoTenB+vqOGi+6A=="}]},"maintainers":[{"name":"alcalzone","email":"d.griesel@gmx.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mdns-server_1.0.6_1536173626143_0.025421333418335523"},"_hasShrinkwrap":false}},"time":{"created":"2018-09-05T18:53:45.977Z","1.0.6":"2018-09-05T18:53:46.238Z","modified":"2022-04-04T12:35:39.046Z"},"maintainers":[{"name":"alcalzone","email":"d.griesel@gmx.net"}],"description":"Low level Multicast DNS implementation in pure javascript.","homepage":"https://github.com/AlCalzone/mdns-server#readme","repository":{"type":"git","url":"git+https://github.com/AlCalzone/mdns-server.git"},"contributors":[{"name":"AlCalzone","url":"d.griesel@gmx.net"}],"author":{"name":"Bryan Nielsen","url":"@bnielsen1965"},"bugs":{"url":"https://github.com/AlCalzone/mdns-server/issues"},"license":"MIT","readme":"# mdns-server\r\n\r\nLow level Multicast DNS implementation in pure javascript. This is a fork of [Bryan Nielsen's](@bnielsen1965) version, with a small bug fix.\r\n\r\nBased on [multicast-dns](https://github.com/mafintosh/multicast-dns) by Mathias Buus.\r\n\r\nCan be configured to work with a single network interface or multiple network interfaces. When no interface is specified the OS package is used to detect all available interfaces.\r\n\r\n```\r\nnpm install mdns-server\r\n```\r\n\r\n## Usage\r\n\r\n``` js\r\nvar mdns = require('mdns-server')({\r\n  reuseAddr: true, // in case other mdns service is running\r\n  loopback: true,  // receive our own mdns messages\r\n  noInit: true     // do not initialize on creation\r\n})\r\n\r\n// listen for response events from server\r\nmdns.on('response', function(response) {\r\n  console.log('got a response packet:')\r\n  var a = []\r\n  if (response.answers) {\r\n    a = a.concat(response.answers)\r\n  }\r\n  if (response.additionals) {\r\n    a = a.concat(response.additionals)\r\n  }\r\n  console.log(a)\r\n})\r\n\r\n// listen for query events from server\r\nmdns.on('query', function(query) {\r\n  console.log('got a query packet:')\r\n  var q = []\r\n  if (query.questions) {\r\n    q = q.concat(query.questions)\r\n  }\r\n  console.log(q)\r\n})\r\n\r\n// listen for the server being destroyed\r\nmdns.on('destroyed', function () {\r\n  console.log('Server destroyed.')\r\n  process.exit(0)\r\n})\r\n\r\n// query for 'foo.local' A record when the server is ready\r\nmdns.on('ready', function () {\r\n  mdns.query({\r\n    questions:[{\r\n      name: 'foo.local',\r\n      type: 'A'\r\n    }]\r\n  })\r\n})\r\n\r\n// initialize the server now that we are watching for events\r\nmdns.initServer()\r\n\r\n// destroy the server after 10 seconds\r\nsetTimeout(function () { mdns.destroy() }, 10000)\r\n```\r\n\r\n### query packets\r\n\r\nIn this example a query will be sent on all available IPv4\r\nand IPv6 interfaces. With loopback enabled these queries\r\nshould be recorded by the server. I.E.\r\n\r\n``` text\r\ngot a query packet:\r\n[ { name: 'foo.local', type: 'A', class: 1 } ]\r\ngot a query packet:\r\n[ { name: 'foo.local', type: 'A', class: 1 } ]\r\n```\r\n\r\nHere there were two query packets because the system has\r\nboth an IPv4 and IPv6 address on one interface.\r\n\r\n### response packets\r\n\r\nAssuming a device on the local network matches the query\r\nrequest for 'foo.local' the server should record a\r\nresponse similar to the following...\r\n\r\n``` text\r\ngot a response packet:\r\n[ { name: 'foo.local',\r\n    type: 'A',\r\n    class: 1,\r\n    ttl: 120,\r\n    flush: true,\r\n    data: '192.168.251.125' } ]\r\n```\r\n\r\n\r\n## API\r\n\r\nA packet has the following format\r\n\r\n``` js\r\n{\r\n  questions: [{\r\n    name:'brunhilde.local',\r\n    type:'A'\r\n  }],\r\n  answers: [{\r\n    name:'brunhilde.local',\r\n    type:'A',\r\n    ttl:seconds,\r\n    data:(record type specific data)\r\n  }],\r\n  additionals: [\r\n    (same format as answers)\r\n  ],\r\n  authorities: [\r\n    (same format as answers)\r\n  ]\r\n}\r\n```\r\n\r\nCurrently data from `SRV`, `A`, `PTR`, `TXT`, `AAAA` and `HINFO` records is passed\r\n\r\n### `mdns = mdns-server([options])`\r\n\r\nCreates a new `mdns` instance. Options can contain the following\r\n\r\n``` js\r\n{\r\n  reuseAddr: (true) || Boolean,\r\n  interfaces: (null) || String || [String, String, ...],\r\n  ttl: (255) || Integer,\r\n  loopback: (true) || Boolean,\r\n  noInit: (false) || Boolean\r\n}\r\n```\r\n\r\n#### reuseAddr\r\n\r\nDetermines if socket will be allowed to reuse an address\r\nalready in use. (requires node >=0.11.13) This is helpful\r\nif another process is also listening for mDNS packets.\r\n\r\n#### interfaces\r\n\r\nSpecify the interface or interfaces to be used on the\r\nmDNS server. If no interfaces are specified then all\r\navailable network interfaces will be used. To select a\r\nsingle interface set interfaces to the ip address of\r\nthe selected interface. To select multiple interfaces\r\nuse an array of ip addresses.\r\n\r\nFor backward compatability with [multicast-dns](https://github.com/mafintosh/multicast-dns) *interface* may be used in place of *interfaces*.\r\n\r\n##### single interface\r\n\r\n``` js\r\nvar mdns = require('mdns-server')({\r\n  interfaces: \"192.168.8.233\"\r\n})\r\n```\r\n\r\n##### multiple interfaces\r\n\r\n``` js\r\nvar mdns = require('mdns-server')({\r\n  interfaces: [\"192.168.8.233\", \"10.69.4.10\", \"fe80::e03c:16d2:1ba:e62\"]\r\n})\r\n```\r\n\r\n#### ttl\r\n\r\nSet the multicast ttl.\r\n\r\n#### loopback\r\n\r\nSet whether server will report on mDNS packets\r\noriginating from the same machine.\r\n\r\n#### noInit\r\n\r\nControl automatic server initialization. If set to\r\nfalse then server will not automatically initialize\r\nand the initServer() method must be called when\r\nyour application is ready.\r\n\r\n\r\n## Events\r\n\r\n### `mdns.on('query', (packet, rinfo))`\r\n\r\nEmitted when a query packet is received.\r\n\r\n``` js\r\nmdns.on('query', function(query) {\r\n  if (query.questions[0] && query.questions[0].name === 'brunhilde.local') {\r\n    mdns.respond(someResponse) // see below\r\n  }\r\n})\r\n```\r\n\r\n### `mdns.on('response', (packet, rinfo))`\r\n\r\nEmitted when a response packet is received.\r\n\r\nThe response might not be a response to a query you send as this\r\nis the result of someone multicasting a response.\r\n\r\n\r\n## Methods\r\n\r\n### `mdns.query(packet, [cb])`\r\n\r\nSend a dns query. The callback will be called when the packet was sent.\r\n\r\nThe following shorthands are equivalent\r\n\r\n``` js\r\nmdns.query('brunhilde.local', 'A')\r\nmdns.query([{name:'brunhilde.local', type:'A'}])\r\nmdns.query({\r\n  questions: [{name:'brunhilde.local', type:'A'}]\r\n})\r\n```\r\n\r\n### `mdns.respond(packet, [cb])`\r\n\r\nSend a dns response. The callback will be called when the packet was sent.\r\n\r\n``` js\r\n// reply with a SRV and a A record as an answer\r\nmdns.respond({\r\n  answers: [{\r\n    name: 'my-service',\r\n    type: 'SRV',\r\n    data: {\r\n      port:9999,\r\n      weigth: 0,\r\n      priority: 10,\r\n      target: 'my-service.example.com'\r\n    }\r\n  }, {\r\n    name: 'brunhilde.local',\r\n    type: 'A',\r\n    ttl: 300,\r\n    data: '192.168.1.5'\r\n  }]\r\n})\r\n```\r\n\r\nThe following shorthands are equivalent\r\n\r\n``` js\r\nmdns.respond([{name:'brunhilde.local', type:'A', data:'192.158.1.5'}])\r\nmdns.respond({\r\n  answers: [{name:'brunhilde.local', type:'A', data:'192.158.1.5'}]\r\n})\r\n```\r\n\r\n### `mdns.destroy()`\r\n\r\nDestroy the mdns instance. Closes the udp socket.\r\n\r\n### `mdns.initServer()`\r\n\r\nInitialize the server. Only call this method if the constructor\r\nwas called with the option noInit: true. This is used if your\r\napplication needs some time to setup events before the server initialization.\r\n\r\n\r\n## License\r\n\r\nMIT\r\n","readmeFilename":"README.md"}