Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #945 - Node.js v18 os.networkInterfaces()[].family number/string comparison #947

Merged
merged 2 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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