Skip to content

Commit

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

Co-authored-by: Andi <mail@anderl-bauer.de>
  • Loading branch information
2 people authored and Koushik Dutta committed Jun 28, 2022
1 parent 4b1cc68 commit fc381e0
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 @@ -686,7 +686,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 @@ -696,7 +697,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 @@ -16,11 +16,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 fc381e0

Please sign in to comment.