From b5ff3324ea4da4b73c419bdaa16f1a3beaf4c224 Mon Sep 17 00:00:00 2001 From: oznu Date: Tue, 26 Apr 2022 21:39:01 +1000 Subject: [PATCH] Fix #945 - Node.js v18 os.networkInterfaces()[].family number/string comparison --- src/lib/util/eventedhttp.ts | 6 ++++-- src/lib/util/net-utils.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/util/eventedhttp.ts b/src/lib/util/eventedhttp.ts index 7a96488d3..585a0cad7 100644 --- a/src/lib/util/eventedhttp.ts +++ b/src/lib/util/eventedhttp.ts @@ -713,7 +713,8 @@ export class HAPConnection extends EventEmitter { if (ipVersion === "ipv4") { for (const info of infos) { - if (info.family === "IPv4") { + // @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4" + if (info.family === "IPv4" || info.family === 4) { return info.address; } } @@ -723,7 +724,8 @@ export class HAPConnection extends EventEmitter { let localUniqueAddress: string | undefined = undefined; for (const info of infos) { - if (info.family === "IPv6") { + // @ts-expect-error Nodejs 18+ uses the number 6 instead of the string "IPv6" + if (info.family === "IPv6" || info.family === 6) { if (!info.scopeid) { return info.address; } else if (!localUniqueAddress) { diff --git a/src/lib/util/net-utils.ts b/src/lib/util/net-utils.ts index 63e10703d..0acc6a0a4 100644 --- a/src/lib/util/net-utils.ts +++ b/src/lib/util/net-utils.ts @@ -13,11 +13,13 @@ export function findLoopbackAddress(): string { } internal = true; - if (info.family === "IPv4") { + // @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4" + if (info.family === "IPv4" || info.family === 4) { if (!ipv4) { ipv4 = info.address; } - } else if (info.family === "IPv6") { + // @ts-expect-error Nodejs 18+ uses the number 6 the string "IPv6" + } else if (info.family === "IPv6" || info.family === 6) { if (info.scopeid) { if (!ipv6LinkLocal) { ipv6LinkLocal = info.address + "%" + name; // ipv6 link local addresses are only valid with a scope