Skip to content

Commit

Permalink
Fix #945 - Node.js v18 os.networkInterfaces()[].family number/string …
Browse files Browse the repository at this point in the history
…comparison (#947)

Co-authored-by: Andi <[email protected]>
  • Loading branch information
oznu and Supereg authored Apr 27, 2022
1 parent 19c7161 commit 11287fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/lib/util/eventedhttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/util/net-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11287fc

Please sign in to comment.