mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-31 20:01:36 +00:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import os from "node:os";
|
|
import type { NetworkInterfacesSnapshot } from "../infra/network-interfaces.js";
|
|
|
|
type NetworkInterfaceEntry = NonNullable<ReturnType<typeof os.networkInterfaces>[string]>[number];
|
|
|
|
export type NetworkInterfaceEntryInput = {
|
|
address: string;
|
|
family: "IPv4" | "IPv6";
|
|
internal?: boolean;
|
|
netmask?: string;
|
|
};
|
|
|
|
export function makeNetworkInterfaceEntry(
|
|
input: NetworkInterfaceEntryInput,
|
|
): NetworkInterfaceEntry {
|
|
if (input.family === "IPv6") {
|
|
return {
|
|
address: input.address,
|
|
family: "IPv6",
|
|
internal: input.internal ?? false,
|
|
netmask: input.netmask ?? "",
|
|
cidr: null,
|
|
mac: "",
|
|
scopeid: 0,
|
|
};
|
|
}
|
|
|
|
return {
|
|
address: input.address,
|
|
family: "IPv4",
|
|
internal: input.internal ?? false,
|
|
netmask: input.netmask ?? "",
|
|
cidr: null,
|
|
mac: "",
|
|
};
|
|
}
|
|
|
|
export function makeNetworkInterfacesSnapshot(
|
|
snapshot: Record<string, NetworkInterfaceEntryInput[]>,
|
|
): NetworkInterfacesSnapshot {
|
|
return Object.fromEntries(
|
|
Object.entries(snapshot).map(([name, entries]) => [
|
|
name,
|
|
entries.map((entry) => makeNetworkInterfaceEntry(entry)),
|
|
]),
|
|
);
|
|
}
|