matterbridge 3.3.8 → 3.3.9-dev-20251119-ea13a99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README-DEV.md +20 -25
- package/dist/broadcastServer.js +1 -93
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +1 -97
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +0 -38
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -105
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -43
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -24
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +39 -454
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +0 -25
- package/dist/jestutils/export.js +0 -1
- package/dist/jestutils/jestHelpers.js +104 -278
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +51 -792
- package/dist/matterbridgeAccessoryPlatform.js +0 -38
- package/dist/matterbridgeBehaviors.js +5 -68
- package/dist/matterbridgeDeviceTypes.js +14 -635
- package/dist/matterbridgeDynamicPlatform.js +0 -38
- package/dist/matterbridgeEndpoint.js +82 -1445
- package/dist/matterbridgeEndpointHelpers.js +21 -483
- package/dist/matterbridgeEndpointTypes.js +0 -25
- package/dist/matterbridgePlatform.js +16 -355
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +11 -346
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -60
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/format.js +0 -49
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +1 -69
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -96
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +1 -64
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/broadcastServer.d.ts +0 -115
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -806
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -30
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -48
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -128
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -76
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -238
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -34
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jestutils/export.d.ts +0 -2
- package/dist/jestutils/export.d.ts.map +0 -1
- package/dist/jestutils/export.js.map +0 -1
- package/dist/jestutils/jestHelpers.d.ts +0 -250
- package/dist/jestutils/jestHelpers.d.ts.map +0 -1
- package/dist/jestutils/jestHelpers.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -469
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -2404
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -698
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1490
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgeEndpointTypes.d.ts +0 -197
- package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
- package/dist/matterbridgeEndpointTypes.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -415
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -239
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -371
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -101
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -66
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/format.d.ts +0 -53
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/inspector.d.ts +0 -87
- package/dist/utils/inspector.d.ts.map +0 -1
- package/dist/utils/inspector.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -101
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -35
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/tracker.d.ts +0 -108
- package/dist/utils/tracker.d.ts.map +0 -1
- package/dist/utils/tracker.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
package/dist/dgram/mdns.js
CHANGED
|
@@ -1,28 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the class Mdns.
|
|
3
|
-
* @file mdns.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2025-03-22
|
|
6
|
-
* @version 1.0.0
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
// AnsiLogger imports
|
|
24
1
|
import { BLUE, CYAN, db, er, GREEN, idn, MAGENTA, nf, rs } from 'node-ansi-logger';
|
|
25
|
-
// Net imports
|
|
26
2
|
import { Multicast } from './multicast.js';
|
|
27
3
|
export var DnsRecordType;
|
|
28
4
|
(function (DnsRecordType) {
|
|
@@ -114,7 +90,6 @@ export var DnsRecordType;
|
|
|
114
90
|
DnsRecordType[DnsRecordType["DOA"] = 259] = "DOA";
|
|
115
91
|
DnsRecordType[DnsRecordType["AMTRELAY"] = 260] = "AMTRELAY";
|
|
116
92
|
DnsRecordType[DnsRecordType["ZONEVERSION"] = 261] = "ZONEVERSION";
|
|
117
|
-
// 262-32767 are unassigned/reserved
|
|
118
93
|
DnsRecordType[DnsRecordType["TA"] = 32768] = "TA";
|
|
119
94
|
DnsRecordType[DnsRecordType["DLV"] = 32769] = "DLV";
|
|
120
95
|
})(DnsRecordType || (DnsRecordType = {}));
|
|
@@ -128,25 +103,12 @@ export var DnsClass;
|
|
|
128
103
|
export var DnsClassFlag;
|
|
129
104
|
(function (DnsClassFlag) {
|
|
130
105
|
DnsClassFlag[DnsClassFlag["FLUSH"] = 32768] = "FLUSH";
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
|
|
132
106
|
DnsClassFlag[DnsClassFlag["QU"] = 32768] = "QU";
|
|
133
107
|
})(DnsClassFlag || (DnsClassFlag = {}));
|
|
134
108
|
export class Mdns extends Multicast {
|
|
135
109
|
deviceQueries = new Map();
|
|
136
110
|
deviceResponses = new Map();
|
|
137
111
|
filters = [];
|
|
138
|
-
/**
|
|
139
|
-
* Creates an instance of the Mdns class.
|
|
140
|
-
*
|
|
141
|
-
* @param {string} name - The internal name of the mDNS server for the logs.
|
|
142
|
-
* @param {string} multicastAddress - The multicast address for mDNS (i.e. 224.0.0.251 for udp4 or ff02::fb for udp6).
|
|
143
|
-
* @param {number} multicastPort - The port for mDNS (i.e. 5353).
|
|
144
|
-
* @param {('udp4' | 'udp6')} socketType - The type of socket to create (either 'udp4' or 'udp6').
|
|
145
|
-
* @param {boolean} [reuseAddr] - Whether to reuse the address. Defaults to true.
|
|
146
|
-
* @param {string} [interfaceName] - The optional name of the network interface to use.
|
|
147
|
-
* @param {string} [interfaceAddress] - The optional IP address of the network interface to use.
|
|
148
|
-
* @param {string} [outgoingInterfaceAddress] - The address of the outgoing network interface.
|
|
149
|
-
*/
|
|
150
112
|
constructor(name, multicastAddress, multicastPort, socketType, reuseAddr = true, interfaceName, interfaceAddress, outgoingInterfaceAddress) {
|
|
151
113
|
super(name, multicastAddress, multicastPort, socketType, reuseAddr, interfaceName, interfaceAddress, outgoingInterfaceAddress);
|
|
152
114
|
}
|
|
@@ -166,14 +128,14 @@ export class Mdns extends Multicast {
|
|
|
166
128
|
this.onQuery(rinfo, result);
|
|
167
129
|
}
|
|
168
130
|
else {
|
|
169
|
-
const ptr = result.answers?.find((record) => record.name === '_shelly._tcp.local' && record.type === 12
|
|
170
|
-
result.answers?.find((record) => record.name === '_http._tcp.local' && record.type === 12
|
|
171
|
-
result.answers?.find((record) => record.type === 12
|
|
172
|
-
result.answers?.find((record) => record.type === 16
|
|
131
|
+
const ptr = result.answers?.find((record) => record.name === '_shelly._tcp.local' && record.type === 12) ||
|
|
132
|
+
result.answers?.find((record) => record.name === '_http._tcp.local' && record.type === 12) ||
|
|
133
|
+
result.answers?.find((record) => record.type === 12) ||
|
|
134
|
+
result.answers?.find((record) => record.type === 16) ||
|
|
173
135
|
result.answers
|
|
174
136
|
? result.answers[0]
|
|
175
|
-
: undefined;
|
|
176
|
-
this.deviceResponses.set(rinfo.address, { rinfo, response: result, dataPTR: ptr?.type === 12
|
|
137
|
+
: undefined;
|
|
138
|
+
this.deviceResponses.set(rinfo.address, { rinfo, response: result, dataPTR: ptr?.type === 12 ? ptr?.data : ptr?.name });
|
|
177
139
|
this.onResponse(rinfo, result);
|
|
178
140
|
}
|
|
179
141
|
if (this.filters.length > 0) {
|
|
@@ -197,28 +159,20 @@ export class Mdns extends Multicast {
|
|
|
197
159
|
this.log.error(`Error decoding mDNS message: ${error instanceof Error ? error.message : error}`);
|
|
198
160
|
}
|
|
199
161
|
}
|
|
200
|
-
/**
|
|
201
|
-
* Decodes an mDNS message, including the header, question section, answer section,
|
|
202
|
-
* authority section, and additional section.
|
|
203
|
-
*
|
|
204
|
-
* @param {Buffer} msg - The raw mDNS message buffer.
|
|
205
|
-
* @returns {MdnsMessage} An object representing the decoded mDNS message.
|
|
206
|
-
* @throws {Error} if the message is too short.
|
|
207
|
-
*/
|
|
208
162
|
decodeMdnsMessage(msg) {
|
|
209
163
|
if (msg.length < 12) {
|
|
210
164
|
throw new Error('mDNS message too short');
|
|
211
165
|
}
|
|
212
166
|
const id = msg.readUInt16BE(0);
|
|
213
167
|
const flags = msg.readUInt16BE(2);
|
|
214
|
-
const qr = (flags & 0x8000) >> 15;
|
|
215
|
-
const opcode = (flags & 0x7800) >> 11;
|
|
216
|
-
const aa = Boolean(flags & 0x0400);
|
|
217
|
-
const tc = Boolean(flags & 0x0200);
|
|
218
|
-
const rd = Boolean(flags & 0x0100);
|
|
219
|
-
const ra = Boolean(flags & 0x0080);
|
|
220
|
-
const z = (flags & 0x0070) >> 4;
|
|
221
|
-
const rcode = flags & 0x000f;
|
|
168
|
+
const qr = (flags & 0x8000) >> 15;
|
|
169
|
+
const opcode = (flags & 0x7800) >> 11;
|
|
170
|
+
const aa = Boolean(flags & 0x0400);
|
|
171
|
+
const tc = Boolean(flags & 0x0200);
|
|
172
|
+
const rd = Boolean(flags & 0x0100);
|
|
173
|
+
const ra = Boolean(flags & 0x0080);
|
|
174
|
+
const z = (flags & 0x0070) >> 4;
|
|
175
|
+
const rcode = flags & 0x000f;
|
|
222
176
|
const qdCount = msg.readUInt16BE(4);
|
|
223
177
|
const anCount = msg.readUInt16BE(6);
|
|
224
178
|
const nsCount = msg.readUInt16BE(8);
|
|
@@ -243,7 +197,6 @@ export class Mdns extends Multicast {
|
|
|
243
197
|
additionals: [],
|
|
244
198
|
};
|
|
245
199
|
let offset = 12;
|
|
246
|
-
// Decode the question section.
|
|
247
200
|
for (let i = 0; i < qdCount; i++) {
|
|
248
201
|
const qnameResult = this.decodeDnsName(msg, offset);
|
|
249
202
|
const qname = qnameResult.name;
|
|
@@ -254,19 +207,16 @@ export class Mdns extends Multicast {
|
|
|
254
207
|
offset += 2;
|
|
255
208
|
mdnsMessage.questions?.push({ name: qname, type: qtype, class: qclass });
|
|
256
209
|
}
|
|
257
|
-
// Decode the answer section.
|
|
258
210
|
for (let i = 0; i < anCount; i++) {
|
|
259
211
|
const rrResult = this.decodeResourceRecord(msg, offset);
|
|
260
212
|
mdnsMessage.answers?.push(rrResult.record);
|
|
261
213
|
offset = rrResult.newOffset;
|
|
262
214
|
}
|
|
263
|
-
// Decode the authority (NS) section.
|
|
264
215
|
for (let i = 0; i < nsCount; i++) {
|
|
265
216
|
const rrResult = this.decodeResourceRecord(msg, offset);
|
|
266
217
|
mdnsMessage.authorities?.push(rrResult.record);
|
|
267
218
|
offset = rrResult.newOffset;
|
|
268
219
|
}
|
|
269
|
-
// Decode the additional records section.
|
|
270
220
|
for (let i = 0; i < arCount; i++) {
|
|
271
221
|
const rrResult = this.decodeResourceRecord(msg, offset);
|
|
272
222
|
mdnsMessage.additionals?.push(rrResult.record);
|
|
@@ -274,25 +224,15 @@ export class Mdns extends Multicast {
|
|
|
274
224
|
}
|
|
275
225
|
return mdnsMessage;
|
|
276
226
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Decodes a DNS name from a buffer, handling compression.
|
|
279
|
-
*
|
|
280
|
-
* @param {Buffer} msg - The full mDNS message buffer.
|
|
281
|
-
* @param {number} offset - The offset at which the DNS name starts.
|
|
282
|
-
* @returns {{ name: string; newOffset: number }} An object with the decoded name and the new offset.
|
|
283
|
-
* @throws {Error} if the offset exceeds the buffer length or too many iterations are performed.
|
|
284
|
-
*/
|
|
285
227
|
decodeDnsName(msg, offset) {
|
|
286
228
|
const labels = [];
|
|
287
229
|
let jumped = false;
|
|
288
230
|
let originalOffset = offset;
|
|
289
|
-
let iterations = 0;
|
|
231
|
+
let iterations = 0;
|
|
290
232
|
while (true) {
|
|
291
|
-
// Safety guard: prevent infinite loops in malformed messages.
|
|
292
233
|
if (iterations++ > 1000) {
|
|
293
234
|
throw new Error('Too many iterations while decoding DNS name. Possible malformed message.');
|
|
294
235
|
}
|
|
295
|
-
// Check that offset is within buffer bounds.
|
|
296
236
|
if (offset >= msg.length) {
|
|
297
237
|
throw new Error('Offset exceeds buffer length while decoding DNS name.');
|
|
298
238
|
}
|
|
@@ -301,9 +241,7 @@ export class Mdns extends Multicast {
|
|
|
301
241
|
offset++;
|
|
302
242
|
break;
|
|
303
243
|
}
|
|
304
|
-
// Check for pointer (first two bits are 11)
|
|
305
244
|
if ((len & 0xc0) === 0xc0) {
|
|
306
|
-
// Ensure the pointer has two bytes available.
|
|
307
245
|
if (offset + 1 >= msg.length) {
|
|
308
246
|
throw new Error('Incomplete pointer encountered while decoding DNS name.');
|
|
309
247
|
}
|
|
@@ -316,7 +254,6 @@ export class Mdns extends Multicast {
|
|
|
316
254
|
continue;
|
|
317
255
|
}
|
|
318
256
|
offset++;
|
|
319
|
-
// Check that the label length doesn't go beyond the buffer.
|
|
320
257
|
if (offset + len > msg.length) {
|
|
321
258
|
throw new Error('Label length exceeds buffer bounds while decoding DNS name.');
|
|
322
259
|
}
|
|
@@ -325,15 +262,6 @@ export class Mdns extends Multicast {
|
|
|
325
262
|
}
|
|
326
263
|
return { name: labels.join('.'), newOffset: jumped ? originalOffset : offset };
|
|
327
264
|
}
|
|
328
|
-
/**
|
|
329
|
-
* Encodes a domain name into the DNS label format.
|
|
330
|
-
*
|
|
331
|
-
* For example, "example.local" becomes:
|
|
332
|
-
* [7] "example" [5] "local" [0]
|
|
333
|
-
*
|
|
334
|
-
* @param {string} name - The domain name to encode.
|
|
335
|
-
* @returns {Buffer} The encoded domain name as a Buffer.
|
|
336
|
-
*/
|
|
337
265
|
encodeDnsName(name) {
|
|
338
266
|
const labels = name.split('.');
|
|
339
267
|
const buffers = labels.map((label) => {
|
|
@@ -341,22 +269,12 @@ export class Mdns extends Multicast {
|
|
|
341
269
|
lenBuf.writeUInt8(label.length, 0);
|
|
342
270
|
return Buffer.concat([lenBuf, Buffer.from(label)]);
|
|
343
271
|
});
|
|
344
|
-
// Append the null byte to terminate the name.
|
|
345
272
|
return Buffer.concat([...buffers, Buffer.from([0])]);
|
|
346
273
|
}
|
|
347
|
-
/**
|
|
348
|
-
* Decodes a DNS resource record.
|
|
349
|
-
*
|
|
350
|
-
* @param {Buffer} msg - The full mDNS message buffer.
|
|
351
|
-
* @param {number} offset - The offset at which the resource record starts.
|
|
352
|
-
* @returns {{ record: MdnsRecord; newOffset: number }} An object containing the decoded record and the new offset.
|
|
353
|
-
*/
|
|
354
274
|
decodeResourceRecord(msg, offset) {
|
|
355
|
-
// Decode the NAME field (which may be compressed)
|
|
356
275
|
const nameResult = this.decodeDnsName(msg, offset);
|
|
357
276
|
const name = nameResult.name;
|
|
358
277
|
offset = nameResult.newOffset;
|
|
359
|
-
// Read TYPE (16 bits), CLASS (16 bits), TTL (32 bits), and RDLENGTH (16 bits)
|
|
360
278
|
const type = msg.readUInt16BE(offset);
|
|
361
279
|
offset += 2;
|
|
362
280
|
const rrclass = msg.readUInt16BE(offset);
|
|
@@ -366,14 +284,12 @@ export class Mdns extends Multicast {
|
|
|
366
284
|
const rdlength = msg.readUInt16BE(offset);
|
|
367
285
|
offset += 2;
|
|
368
286
|
let data = '';
|
|
369
|
-
if (type === 12
|
|
370
|
-
// PTR record (type 12): decode its RDATA as a domain name.
|
|
287
|
+
if (type === 12) {
|
|
371
288
|
const ptrResult = this.decodeDnsName(msg, offset);
|
|
372
289
|
data = ptrResult.name;
|
|
373
290
|
offset += rdlength;
|
|
374
291
|
}
|
|
375
|
-
else if (type === 16
|
|
376
|
-
// TXT record: may consist of one or more length-prefixed strings.
|
|
292
|
+
else if (type === 16) {
|
|
377
293
|
const txtStrings = [];
|
|
378
294
|
const end = offset + rdlength;
|
|
379
295
|
while (offset < end) {
|
|
@@ -385,8 +301,7 @@ export class Mdns extends Multicast {
|
|
|
385
301
|
}
|
|
386
302
|
data = txtStrings.join(', ');
|
|
387
303
|
}
|
|
388
|
-
else if (type === 33
|
|
389
|
-
// SRV record (type === 33): consists of 2 bytes for priority, 2 for weight, 2 for port, followed by the target domain name.
|
|
304
|
+
else if (type === 33) {
|
|
390
305
|
const priority = msg.readUInt16BE(offset);
|
|
391
306
|
const weight = msg.readUInt16BE(offset + 2);
|
|
392
307
|
const port = msg.readUInt16BE(offset + 4);
|
|
@@ -400,16 +315,13 @@ export class Mdns extends Multicast {
|
|
|
400
315
|
});
|
|
401
316
|
offset = srvTargetResult.newOffset;
|
|
402
317
|
}
|
|
403
|
-
else if (type === 1
|
|
404
|
-
// A record (type 1): an IPv4 address stored in 4 bytes.
|
|
318
|
+
else if (type === 1) {
|
|
405
319
|
const ipBytes = msg.slice(offset, offset + 4);
|
|
406
320
|
data = Array.from(ipBytes).join('.');
|
|
407
321
|
offset += 4;
|
|
408
322
|
}
|
|
409
|
-
else if (type === 28
|
|
410
|
-
// AAAA record (type 28): IPv6 address stored in 16 bytes.
|
|
323
|
+
else if (type === 28) {
|
|
411
324
|
const ipBytes = msg.slice(offset, offset + 16);
|
|
412
|
-
// Convert the 16 bytes into an IPv6 address string (colon-separated)
|
|
413
325
|
const ipv6Parts = [];
|
|
414
326
|
for (let i = 0; i < 16; i += 2) {
|
|
415
327
|
ipv6Parts.push(ipBytes.readUInt16BE(i).toString(16));
|
|
@@ -417,14 +329,10 @@ export class Mdns extends Multicast {
|
|
|
417
329
|
data = ipv6Parts.join(':');
|
|
418
330
|
offset += 16;
|
|
419
331
|
}
|
|
420
|
-
else if (type === 47
|
|
421
|
-
// NSEC record: RDATA consists of:
|
|
422
|
-
// - Next Domain Name (in DNS label format)
|
|
423
|
-
// - Type Bit Maps (variable length)
|
|
332
|
+
else if (type === 47) {
|
|
424
333
|
const { name: nextDomain, newOffset } = this.decodeDnsName(msg, offset);
|
|
425
334
|
const nextDomainLength = newOffset - offset;
|
|
426
335
|
offset = newOffset;
|
|
427
|
-
// Calculate the remaining length for the type bit maps.
|
|
428
336
|
const bitmapLength = rdlength - nextDomainLength;
|
|
429
337
|
const bitmapData = msg.slice(offset, offset + bitmapLength);
|
|
430
338
|
const types = [];
|
|
@@ -451,7 +359,6 @@ export class Mdns extends Multicast {
|
|
|
451
359
|
offset += bitmapLength;
|
|
452
360
|
}
|
|
453
361
|
else {
|
|
454
|
-
// Fall back
|
|
455
362
|
data = msg.slice(offset, offset + rdlength).toString('hex');
|
|
456
363
|
offset += rdlength;
|
|
457
364
|
}
|
|
@@ -460,28 +367,19 @@ export class Mdns extends Multicast {
|
|
|
460
367
|
newOffset: offset,
|
|
461
368
|
};
|
|
462
369
|
}
|
|
463
|
-
/**
|
|
464
|
-
* Sends a DNS query with multiple questions.
|
|
465
|
-
*
|
|
466
|
-
* @param {Array<{ name: string; type: number; class: number; unicastResponse?: boolean }>} questions - Array of questions
|
|
467
|
-
*
|
|
468
|
-
* @remarks
|
|
469
|
-
* Each question should have a name (e.g., "_http._tcp.local"), type (e.g., DnsRecordType.PTR), class (e.g., DnsClass.IN),
|
|
470
|
-
* and an optional unicastResponse flag (this will add the DnsClassFlag.QU flag to the query).
|
|
471
|
-
*/
|
|
472
370
|
sendQuery(questions) {
|
|
473
371
|
const header = Buffer.alloc(12);
|
|
474
|
-
header.writeUInt16BE(0, 0);
|
|
475
|
-
header.writeUInt16BE(0, 2);
|
|
476
|
-
header.writeUInt16BE(questions.length, 4);
|
|
477
|
-
header.writeUInt16BE(0, 6);
|
|
478
|
-
header.writeUInt16BE(0, 8);
|
|
479
|
-
header.writeUInt16BE(0, 10);
|
|
372
|
+
header.writeUInt16BE(0, 0);
|
|
373
|
+
header.writeUInt16BE(0, 2);
|
|
374
|
+
header.writeUInt16BE(questions.length, 4);
|
|
375
|
+
header.writeUInt16BE(0, 6);
|
|
376
|
+
header.writeUInt16BE(0, 8);
|
|
377
|
+
header.writeUInt16BE(0, 10);
|
|
480
378
|
const questionBuffers = questions.map(({ name, type: qtype, class: qclass, unicastResponse = false }) => {
|
|
481
379
|
const qname = this.encodeDnsName(name);
|
|
482
380
|
const qfields = Buffer.alloc(4);
|
|
483
381
|
qfields.writeUInt16BE(qtype, 0);
|
|
484
|
-
qfields.writeUInt16BE(unicastResponse ? qclass | 32768
|
|
382
|
+
qfields.writeUInt16BE(unicastResponse ? qclass | 32768 : qclass, 2);
|
|
485
383
|
return Buffer.concat([qname, qfields]);
|
|
486
384
|
});
|
|
487
385
|
const query = Buffer.concat([header, ...questionBuffers]);
|
|
@@ -501,46 +399,22 @@ export class Mdns extends Multicast {
|
|
|
501
399
|
}
|
|
502
400
|
});
|
|
503
401
|
}
|
|
504
|
-
/**
|
|
505
|
-
* Constructs an mDNS response packet and sends it to the multicast address and port.
|
|
506
|
-
*
|
|
507
|
-
* @param {string} name - The domain name being responded to (e.g., "example.local").
|
|
508
|
-
* @param {number} rtype - The response type (e.g., 1 for A, 28 for AAAA, etc.).
|
|
509
|
-
* @param {number} rclass - The response class (typically 1 for IN).
|
|
510
|
-
* @param {number} ttl - The time-to-live for the answer record.
|
|
511
|
-
* @param {Buffer} rdata - The resource data for the response (e.g., 4 bytes for an A record IPv4 address).
|
|
512
|
-
*
|
|
513
|
-
* @example
|
|
514
|
-
* const ptrRdata = mdnsIpv4.encodeDnsName('matterbridge._http._tcp.local');
|
|
515
|
-
* mdnsIpv4.sendResponse('_http._tcp.local', DnsRecordType.PTR, DnsClass.IN, 120, ptrRdata);
|
|
516
|
-
*/
|
|
517
402
|
sendResponse(name, rtype, rclass, ttl, rdata) {
|
|
518
|
-
// Create a 12-byte DNS header.
|
|
519
403
|
const header = Buffer.alloc(12);
|
|
520
|
-
header.writeUInt16BE(0, 0);
|
|
521
|
-
// Set flags: QR (response) bit and AA (authoritative answer) bit.
|
|
404
|
+
header.writeUInt16BE(0, 0);
|
|
522
405
|
header.writeUInt16BE(0x8400, 2);
|
|
523
|
-
header.writeUInt16BE(0, 4);
|
|
524
|
-
header.writeUInt16BE(1, 6);
|
|
525
|
-
header.writeUInt16BE(0, 8);
|
|
526
|
-
header.writeUInt16BE(0, 10);
|
|
527
|
-
// Encode the domain name in DNS label format.
|
|
406
|
+
header.writeUInt16BE(0, 4);
|
|
407
|
+
header.writeUInt16BE(1, 6);
|
|
408
|
+
header.writeUInt16BE(0, 8);
|
|
409
|
+
header.writeUInt16BE(0, 10);
|
|
528
410
|
const aname = this.encodeDnsName(name);
|
|
529
|
-
// Prepare the fixed part of the answer record:
|
|
530
|
-
// - 2 bytes for qtype,
|
|
531
|
-
// - 2 bytes for qclass,
|
|
532
|
-
// - 4 bytes for TTL,
|
|
533
|
-
// - 2 bytes for RDLENGTH (length of the rdata).
|
|
534
411
|
const answerFixed = Buffer.alloc(10);
|
|
535
|
-
answerFixed.writeUInt16BE(rtype, 0);
|
|
536
|
-
answerFixed.writeUInt16BE(rclass, 2);
|
|
537
|
-
answerFixed.writeUInt32BE(ttl, 4);
|
|
538
|
-
answerFixed.writeUInt16BE(rdata.length, 8);
|
|
539
|
-
// Concatenate the answer: encoded name, fixed fields, and resource data.
|
|
412
|
+
answerFixed.writeUInt16BE(rtype, 0);
|
|
413
|
+
answerFixed.writeUInt16BE(rclass, 2);
|
|
414
|
+
answerFixed.writeUInt32BE(ttl, 4);
|
|
415
|
+
answerFixed.writeUInt16BE(rdata.length, 8);
|
|
540
416
|
const answer = Buffer.concat([aname, answerFixed, rdata]);
|
|
541
|
-
// Concatenate header and answer to form the complete mDNS response packet.
|
|
542
417
|
const response = Buffer.concat([header, answer]);
|
|
543
|
-
// Send the response packet via the socket.
|
|
544
418
|
this.socket.send(response, 0, response.length, this.multicastPort, this.multicastAddress, (error) => {
|
|
545
419
|
if (error) {
|
|
546
420
|
this.log.error(`Dgram mDNS server failed to send response message for ${MAGENTA}${name}${er} type ${MAGENTA}${this.dnsTypeToString(rtype)}${er} class ${MAGENTA}${this.dnsResponseClassToString(rclass)}${er} ttl ${MAGENTA}${ttl}${er}: ${error instanceof Error ? error.message : error}`);
|
|
@@ -552,128 +426,116 @@ export class Mdns extends Multicast {
|
|
|
552
426
|
}
|
|
553
427
|
});
|
|
554
428
|
}
|
|
555
|
-
/**
|
|
556
|
-
* Converts a DNS record type numeric value to its string representation.
|
|
557
|
-
*
|
|
558
|
-
* @param {number} type - The numeric DNS record type.
|
|
559
|
-
* @returns {string} The string representation of the record type.
|
|
560
|
-
*/
|
|
561
429
|
dnsTypeToString(type) {
|
|
562
430
|
const typeMap = {
|
|
563
|
-
[1
|
|
564
|
-
[2
|
|
565
|
-
[3
|
|
566
|
-
[4
|
|
567
|
-
[5
|
|
568
|
-
[6
|
|
569
|
-
[7
|
|
570
|
-
[8
|
|
571
|
-
[9
|
|
572
|
-
[10
|
|
573
|
-
[11
|
|
574
|
-
[12
|
|
575
|
-
[13
|
|
576
|
-
[14
|
|
577
|
-
[15
|
|
578
|
-
[16
|
|
579
|
-
[17
|
|
580
|
-
[18
|
|
581
|
-
[19
|
|
582
|
-
[20
|
|
583
|
-
[21
|
|
584
|
-
[22
|
|
585
|
-
[23
|
|
586
|
-
[24
|
|
587
|
-
[25
|
|
588
|
-
[26
|
|
589
|
-
[27
|
|
590
|
-
[28
|
|
591
|
-
[29
|
|
592
|
-
[30
|
|
593
|
-
[31
|
|
594
|
-
[32
|
|
595
|
-
[33
|
|
596
|
-
[34
|
|
597
|
-
[35
|
|
598
|
-
[36
|
|
599
|
-
[37
|
|
600
|
-
[38
|
|
601
|
-
[39
|
|
602
|
-
[40
|
|
603
|
-
[41
|
|
604
|
-
[42
|
|
605
|
-
[43
|
|
606
|
-
[44
|
|
607
|
-
[45
|
|
608
|
-
[46
|
|
609
|
-
[47
|
|
610
|
-
[48
|
|
611
|
-
[49
|
|
612
|
-
[50
|
|
613
|
-
[51
|
|
614
|
-
[52
|
|
615
|
-
[53
|
|
616
|
-
[55
|
|
617
|
-
[56
|
|
618
|
-
[57
|
|
619
|
-
[58
|
|
620
|
-
[59
|
|
621
|
-
[60
|
|
622
|
-
[61
|
|
623
|
-
[62
|
|
624
|
-
[63
|
|
625
|
-
[64
|
|
626
|
-
[65
|
|
627
|
-
[99
|
|
628
|
-
[100
|
|
629
|
-
[101
|
|
630
|
-
[102
|
|
631
|
-
[103
|
|
632
|
-
[104
|
|
633
|
-
[105
|
|
634
|
-
[106
|
|
635
|
-
[107
|
|
636
|
-
[108
|
|
637
|
-
[109
|
|
638
|
-
[249
|
|
639
|
-
[250
|
|
640
|
-
[251
|
|
641
|
-
[252
|
|
642
|
-
[253
|
|
643
|
-
[254
|
|
644
|
-
[255
|
|
645
|
-
[256
|
|
646
|
-
[257
|
|
647
|
-
[258
|
|
648
|
-
[259
|
|
649
|
-
[260
|
|
650
|
-
[261
|
|
651
|
-
[32768
|
|
652
|
-
[32769
|
|
431
|
+
[1]: 'A',
|
|
432
|
+
[2]: 'NS',
|
|
433
|
+
[3]: 'MD',
|
|
434
|
+
[4]: 'MF',
|
|
435
|
+
[5]: 'CNAME',
|
|
436
|
+
[6]: 'SOA',
|
|
437
|
+
[7]: 'MB',
|
|
438
|
+
[8]: 'MG',
|
|
439
|
+
[9]: 'MR',
|
|
440
|
+
[10]: 'NULL',
|
|
441
|
+
[11]: 'WKS',
|
|
442
|
+
[12]: 'PTR',
|
|
443
|
+
[13]: 'HINFO',
|
|
444
|
+
[14]: 'MINFO',
|
|
445
|
+
[15]: 'MX',
|
|
446
|
+
[16]: 'TXT',
|
|
447
|
+
[17]: 'RP',
|
|
448
|
+
[18]: 'AFSDB',
|
|
449
|
+
[19]: 'X25',
|
|
450
|
+
[20]: 'ISDN',
|
|
451
|
+
[21]: 'RT',
|
|
452
|
+
[22]: 'NSAP',
|
|
453
|
+
[23]: 'NSAP_PTR',
|
|
454
|
+
[24]: 'SIG',
|
|
455
|
+
[25]: 'KEY',
|
|
456
|
+
[26]: 'PX',
|
|
457
|
+
[27]: 'GPOS',
|
|
458
|
+
[28]: 'AAAA',
|
|
459
|
+
[29]: 'LOC',
|
|
460
|
+
[30]: 'NXT',
|
|
461
|
+
[31]: 'EID',
|
|
462
|
+
[32]: 'NIMLOC',
|
|
463
|
+
[33]: 'SRV',
|
|
464
|
+
[34]: 'ATMA',
|
|
465
|
+
[35]: 'NAPTR',
|
|
466
|
+
[36]: 'KX',
|
|
467
|
+
[37]: 'CERT',
|
|
468
|
+
[38]: 'A6',
|
|
469
|
+
[39]: 'DNAME',
|
|
470
|
+
[40]: 'SINK',
|
|
471
|
+
[41]: 'OPT',
|
|
472
|
+
[42]: 'APL',
|
|
473
|
+
[43]: 'DS',
|
|
474
|
+
[44]: 'SSHFP',
|
|
475
|
+
[45]: 'IPSECKEY',
|
|
476
|
+
[46]: 'RRSIG',
|
|
477
|
+
[47]: 'NSEC',
|
|
478
|
+
[48]: 'DNSKEY',
|
|
479
|
+
[49]: 'DHCID',
|
|
480
|
+
[50]: 'NSEC3',
|
|
481
|
+
[51]: 'NSEC3PARAM',
|
|
482
|
+
[52]: 'TLSA',
|
|
483
|
+
[53]: 'SMIMEA',
|
|
484
|
+
[55]: 'HIP',
|
|
485
|
+
[56]: 'NINFO',
|
|
486
|
+
[57]: 'RKEY',
|
|
487
|
+
[58]: 'TALINK',
|
|
488
|
+
[59]: 'CDS',
|
|
489
|
+
[60]: 'CDNSKEY',
|
|
490
|
+
[61]: 'OPENPGPKEY',
|
|
491
|
+
[62]: 'CSYNC',
|
|
492
|
+
[63]: 'ZONEMD',
|
|
493
|
+
[64]: 'SVCB',
|
|
494
|
+
[65]: 'HTTPS',
|
|
495
|
+
[99]: 'SPF',
|
|
496
|
+
[100]: 'UINFO',
|
|
497
|
+
[101]: 'UID',
|
|
498
|
+
[102]: 'GID',
|
|
499
|
+
[103]: 'UNSPEC',
|
|
500
|
+
[104]: 'NID',
|
|
501
|
+
[105]: 'L32',
|
|
502
|
+
[106]: 'L64',
|
|
503
|
+
[107]: 'LP',
|
|
504
|
+
[108]: 'EUI48',
|
|
505
|
+
[109]: 'EUI64',
|
|
506
|
+
[249]: 'TKEY',
|
|
507
|
+
[250]: 'TSIG',
|
|
508
|
+
[251]: 'IXFR',
|
|
509
|
+
[252]: 'AXFR',
|
|
510
|
+
[253]: 'MAILB',
|
|
511
|
+
[254]: 'MAILA',
|
|
512
|
+
[255]: 'ANY',
|
|
513
|
+
[256]: 'URI',
|
|
514
|
+
[257]: 'CAA',
|
|
515
|
+
[258]: 'AVC',
|
|
516
|
+
[259]: 'DOA',
|
|
517
|
+
[260]: 'AMTRELAY',
|
|
518
|
+
[261]: 'ZONEVERSION',
|
|
519
|
+
[32768]: 'TA',
|
|
520
|
+
[32769]: 'DLV',
|
|
653
521
|
};
|
|
654
522
|
return typeMap[type] ?? `TYPE${type}`;
|
|
655
523
|
}
|
|
656
|
-
/**
|
|
657
|
-
* Converts a DNS response class numeric value to its string representation.
|
|
658
|
-
*
|
|
659
|
-
* @param {number} cls - The numeric DNS class.
|
|
660
|
-
* @returns {string} The string representation of the DNS class.
|
|
661
|
-
*/
|
|
662
524
|
dnsResponseClassToString(cls) {
|
|
663
|
-
const isFlush = !!(cls & 32768
|
|
525
|
+
const isFlush = !!(cls & 32768);
|
|
664
526
|
const baseClass = cls & 0x7fff;
|
|
665
527
|
let classStr;
|
|
666
528
|
switch (baseClass) {
|
|
667
|
-
case 1
|
|
529
|
+
case 1:
|
|
668
530
|
classStr = 'IN';
|
|
669
531
|
break;
|
|
670
|
-
case 3
|
|
532
|
+
case 3:
|
|
671
533
|
classStr = 'CH';
|
|
672
534
|
break;
|
|
673
|
-
case 4
|
|
535
|
+
case 4:
|
|
674
536
|
classStr = 'HS';
|
|
675
537
|
break;
|
|
676
|
-
case 255
|
|
538
|
+
case 255:
|
|
677
539
|
classStr = 'ANY';
|
|
678
540
|
break;
|
|
679
541
|
default:
|
|
@@ -681,28 +543,21 @@ export class Mdns extends Multicast {
|
|
|
681
543
|
}
|
|
682
544
|
return isFlush ? `${classStr}|FLUSH` : classStr;
|
|
683
545
|
}
|
|
684
|
-
/**
|
|
685
|
-
* Converts a DNS question class to a human-readable string.
|
|
686
|
-
* Adds support for mDNS QU (unicast-response) bit.
|
|
687
|
-
*
|
|
688
|
-
* @param {number} cls - The numeric question class.
|
|
689
|
-
* @returns {string} The string representation, e.g. "IN|QU"
|
|
690
|
-
*/
|
|
691
546
|
dnsQuestionClassToString(cls) {
|
|
692
|
-
const isQU = !!(cls & 32768
|
|
547
|
+
const isQU = !!(cls & 32768);
|
|
693
548
|
const baseClass = cls & 0x7fff;
|
|
694
549
|
let classStr;
|
|
695
550
|
switch (baseClass) {
|
|
696
|
-
case 1
|
|
551
|
+
case 1:
|
|
697
552
|
classStr = 'IN';
|
|
698
553
|
break;
|
|
699
|
-
case 3
|
|
554
|
+
case 3:
|
|
700
555
|
classStr = 'CH';
|
|
701
556
|
break;
|
|
702
|
-
case 4
|
|
557
|
+
case 4:
|
|
703
558
|
classStr = 'HS';
|
|
704
559
|
break;
|
|
705
|
-
case 255
|
|
560
|
+
case 255:
|
|
706
561
|
classStr = 'ANY';
|
|
707
562
|
break;
|
|
708
563
|
default:
|
|
@@ -710,11 +565,6 @@ export class Mdns extends Multicast {
|
|
|
710
565
|
}
|
|
711
566
|
return isQU ? `${classStr}|QU` : classStr;
|
|
712
567
|
}
|
|
713
|
-
/**
|
|
714
|
-
* Logs the decoded mDNS message header.
|
|
715
|
-
*
|
|
716
|
-
* @param {MdnsMessage} msg - The mDNS message header object.
|
|
717
|
-
*/
|
|
718
568
|
logMdnsMessage(msg) {
|
|
719
569
|
this.log.info(`Decoded mDNS message: ID ${MAGENTA}${msg.id}${nf}, QR ${GREEN}${msg.qr === 0 ? 'Query' : 'Response'}${nf}, OPCODE ${MAGENTA}${msg.opcode}${nf}, AA ${MAGENTA}${msg.aa}${nf}, TC ${MAGENTA}${msg.tc}${nf}, RD ${MAGENTA}${msg.rd}${nf}, RA ${MAGENTA}${msg.ra}${nf}, Z ${MAGENTA}${msg.z}${nf}, RCODE ${MAGENTA}${msg.rcode}${nf}, QDCount ${MAGENTA}${msg.qdCount}${nf}, ANCount ${MAGENTA}${msg.anCount}${nf}, NSCount ${MAGENTA}${msg.nsCount}${nf}, ARCount ${MAGENTA}${msg.arCount}${nf}`);
|
|
720
570
|
msg.questions?.forEach((question) => {
|
|
@@ -731,14 +581,9 @@ export class Mdns extends Multicast {
|
|
|
731
581
|
});
|
|
732
582
|
this.log.info(`---\n`);
|
|
733
583
|
}
|
|
734
|
-
/**
|
|
735
|
-
* Logs the discovered devices from the mDNS queries and responses.
|
|
736
|
-
*/
|
|
737
584
|
logDevices() {
|
|
738
585
|
this.log.info(`Discovered query devices: ${MAGENTA}${this.deviceQueries.size}${nf}`);
|
|
739
|
-
// Collect devices into an array
|
|
740
586
|
const deviceQueryArray = Array.from(this.deviceQueries.entries());
|
|
741
|
-
// Sort the array by numeric value of the IP address
|
|
742
587
|
deviceQueryArray.sort(([addressA], [addressB]) => {
|
|
743
588
|
const partsA = addressA.split('.').map(Number);
|
|
744
589
|
const partsB = addressB.split('.').map(Number);
|
|
@@ -747,17 +592,13 @@ export class Mdns extends Multicast {
|
|
|
747
592
|
if (diff !== 0)
|
|
748
593
|
return diff;
|
|
749
594
|
}
|
|
750
|
-
// istanbul ignore next
|
|
751
595
|
return 0;
|
|
752
596
|
});
|
|
753
|
-
// Log the sorted devices
|
|
754
597
|
deviceQueryArray.forEach(([rinfo, response]) => {
|
|
755
598
|
this.log.info(`- ${MAGENTA}${rinfo}${nf} family ${BLUE}${response.rinfo.family}${nf} address ${BLUE}${response.rinfo.address}${nf} port ${BLUE}${response.rinfo.port}${nf}`);
|
|
756
599
|
});
|
|
757
600
|
this.log.info(`Discovered response devices: ${MAGENTA}${this.deviceResponses.size}${nf}`);
|
|
758
|
-
// Collect devices into an array
|
|
759
601
|
const deviceResponseArray = Array.from(this.deviceResponses.entries());
|
|
760
|
-
// Sort the array by numeric value of the IP address
|
|
761
602
|
deviceResponseArray.sort(([addressA], [addressB]) => {
|
|
762
603
|
const partsA = addressA.split(/[:.]/).map((part) => parseInt(part, 16));
|
|
763
604
|
const partsB = addressB.split(/[:.]/).map((part) => parseInt(part, 16));
|
|
@@ -766,13 +607,10 @@ export class Mdns extends Multicast {
|
|
|
766
607
|
if (diff !== 0)
|
|
767
608
|
return diff;
|
|
768
609
|
}
|
|
769
|
-
// istanbul ignore next
|
|
770
610
|
return 0;
|
|
771
611
|
});
|
|
772
|
-
// Log the sorted devices
|
|
773
612
|
deviceResponseArray.forEach(([rinfo, response]) => {
|
|
774
613
|
this.log.info(`- ${MAGENTA}${rinfo}${nf} family ${BLUE}${response.rinfo.family}${nf} address ${BLUE}${response.rinfo.address}${nf} port ${BLUE}${response.rinfo.port}${nf} PTR ${GREEN}${response.dataPTR}${nf}`);
|
|
775
614
|
});
|
|
776
615
|
}
|
|
777
616
|
}
|
|
778
|
-
//# sourceMappingURL=mdns.js.map
|