source: trip-planner-front/node_modules/multicast-dns/README.md@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[6a3a178]1# multicast-dns
2
3Low level multicast-dns implementation in pure javascript
4
5```
6npm install multicast-dns
7```
8
9[![build status](http://img.shields.io/travis/mafintosh/multicast-dns.svg?style=flat)](http://travis-ci.org/mafintosh/multicast-dns)
10
11## Usage
12
13``` js
14var mdns = require('multicast-dns')()
15
16mdns.on('response', function(response) {
17 console.log('got a response packet:', response)
18})
19
20mdns.on('query', function(query) {
21 console.log('got a query packet:', query)
22})
23
24// lets query for an A record for 'brunhilde.local'
25mdns.query({
26 questions:[{
27 name: 'brunhilde.local',
28 type: 'A'
29 }]
30})
31```
32
33Running the above (change `brunhilde.local` to `your-own-hostname.local`) will print an echo of the query packet first
34
35``` js
36got a query packet: { type: 'query',
37 questions: [ { name: 'brunhilde.local', type: 'A', class: 1 } ],
38 answers: [],
39 authorities: [],
40 additionals: [] }
41```
42
43And then a response packet
44
45``` js
46got a response packet: { type: 'response',
47 questions: [],
48 answers:
49 [ { name: 'brunhilde.local',
50 type: 'A',
51 class: 1,
52 ttl: 120,
53 flush: true,
54 data: '192.168.1.5' } ],
55 authorities: [],
56 additionals:
57 [ { name: 'brunhilde.local',
58 type: 'A',
59 class: 1,
60 ttl: 120,
61 flush: true,
62 data: '192.168.1.5' },
63 { name: 'brunhilde.local',
64 type: 'AAAA',
65 class: 1,
66 ttl: 120,
67 flush: true,
68 data: 'fe80::5ef9:38ff:fe8c:ceaa' } ] }
69```
70
71
72# CLI
73
74```
75npm install -g multicast-dns
76```
77
78```
79multicast-dns brunhilde.local
80> 192.168.1.1
81```
82
83# API
84
85A packet has the following format
86
87``` js
88{
89 questions: [{
90 name:'brunhilde.local',
91 type:'A'
92 }],
93 answers: [{
94 name:'brunhilde.local',
95 type:'A',
96 ttl:seconds,
97 data:(record type specific data)
98 }],
99 additionals: [
100 (same format as answers)
101 ],
102 authorities: [
103 (same format as answers)
104 ]
105}
106```
107
108Currently data from `SRV`, `A`, `PTR`, `TXT`, `AAAA` and `HINFO` records is passed
109
110#### `mdns = multicastdns([options])`
111
112Creates a new `mdns` instance. Options can contain the following
113
114``` js
115{
116 multicast: true // use udp multicasting
117 interface: '192.168.0.2' // explicitly specify a network interface. defaults to all
118 port: 5353, // set the udp port
119 ip: '224.0.0.251', // set the udp ip
120 ttl: 255, // set the multicast ttl
121 loopback: true, // receive your own packets
122 reuseAddr: true // set the reuseAddr option when creating the socket (requires node >=0.11.13)
123}
124```
125
126#### `mdns.on('query', (packet, rinfo))`
127
128Emitted when a query packet is received.
129
130``` js
131mdns.on('query', function(query) {
132 if (query.questions[0] && query.questions[0].name === 'brunhilde.local') {
133 mdns.respond(someResponse) // see below
134 }
135})
136```
137
138#### `mdns.on('response', (packet, rinfo))`
139
140Emitted when a response packet is received.
141
142The response might not be a response to a query you send as this
143is the result of someone multicasting a response.
144
145#### `mdns.query(packet, [cb])`
146
147Send a dns query. The callback will be called when the packet was sent.
148
149The following shorthands are equivalent
150
151``` js
152mdns.query('brunhilde.local', 'A')
153mdns.query([{name:'brunhilde.local', type:'A'}])
154mdns.query({
155 questions: [{name:'brunhilde.local', type:'A'}]
156})
157```
158
159#### `mdns.respond(packet, [cb])`
160
161Send a dns response. The callback will be called when the packet was sent.
162
163``` js
164// reply with a SRV and a A record as an answer
165mdns.respond({
166 answers: [{
167 name: 'my-service',
168 type: 'SRV',
169 data: {
170 port:9999,
171 weigth: 0,
172 priority: 10,
173 target: 'my-service.example.com'
174 }
175 }, {
176 name: 'brunhilde.local',
177 type: 'A',
178 ttl: 300,
179 data: '192.168.1.5'
180 }]
181})
182```
183
184The following shorthands are equivalent
185
186``` js
187mdns.respond([{name:'brunhilde.local', type:'A', data:'192.158.1.5'}])
188mdns.respond({
189 answers: [{name:'brunhilde.local', type:'A', data:'192.158.1.5'}]
190})
191```
192
193#### `mdns.destroy()`
194
195Destroy the mdns instance. Closes the udp socket.
196
197# Development
198
199To start hacking on this module you can use this example to get started
200
201```
202git clone git://github.com/mafintosh/multicast-dns.git
203npm install
204node example.js
205node cli.js $(hostname).local
206```
207
208## License
209
210MIT
Note: See TracBrowser for help on using the repository browser.