Skip to content

Commit 11287fc

Browse files
oznubauer-andreas
andauthored
Fix #945 - Node.js v18 os.networkInterfaces()[].family number/string comparison (#947)
Co-authored-by: Andi <mail@anderl-bauer.de>
1 parent 19c7161 commit 11287fc

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/lib/util/eventedhttp.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ export class HAPConnection extends EventEmitter {
713713

714714
if (ipVersion === "ipv4") {
715715
for (const info of infos) {
716-
if (info.family === "IPv4") {
716+
// @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4"
717+
if (info.family === "IPv4" || info.family === 4) {
717718
return info.address;
718719
}
719720
}
@@ -723,7 +724,8 @@ export class HAPConnection extends EventEmitter {
723724
let localUniqueAddress: string | undefined = undefined;
724725

725726
for (const info of infos) {
726-
if (info.family === "IPv6") {
727+
// @ts-expect-error Nodejs 18+ uses the number 6 instead of the string "IPv6"
728+
if (info.family === "IPv6" || info.family === 6) {
727729
if (!info.scopeid) {
728730
return info.address;
729731
} else if (!localUniqueAddress) {

src/lib/util/net-utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ export function findLoopbackAddress(): string {
1313
}
1414

1515
internal = true;
16-
if (info.family === "IPv4") {
16+
// @ts-expect-error Nodejs 18+ uses the number 4 the string "IPv4"
17+
if (info.family === "IPv4" || info.family === 4) {
1718
if (!ipv4) {
1819
ipv4 = info.address;
1920
}
20-
} else if (info.family === "IPv6") {
21+
// @ts-expect-error Nodejs 18+ uses the number 6 the string "IPv6"
22+
} else if (info.family === "IPv6" || info.family === 6) {
2123
if (info.scopeid) {
2224
if (!ipv6LinkLocal) {
2325
ipv6LinkLocal = info.address + "%" + name; // ipv6 link local addresses are only valid with a scope

0 commit comments

Comments
 (0)