pmcf 1.43.0 → 1.43.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.43.0",
3
+ "version": "1.43.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/host.mjs CHANGED
@@ -402,7 +402,7 @@ export class NetworkInterface extends Base {
402
402
  subnetForAddress(address) {
403
403
  return (
404
404
  this.network?.subnetForAddress(address) ||
405
- this.owner.owner.subnetForAddress(address)
405
+ this.host.owner.subnetForAddress(address)
406
406
  );
407
407
  }
408
408
 
@@ -427,8 +427,8 @@ export class NetworkInterface extends Base {
427
427
  }
428
428
 
429
429
  get ipAddressesWithPrefixLength() {
430
- return [...this.ipAddresses].map(address =>
431
- this.addressWithPrefixLength(address)
430
+ return [...this.#ipAddresses].map(
431
+ ([address, subnet]) => `${address}/${subnet?.prefixLength}`
432
432
  );
433
433
  }
434
434
 
@@ -440,10 +440,6 @@ export class NetworkInterface extends Base {
440
440
  return [...this.ipAddresses].filter(a => isIPv6Address(a));
441
441
  }
442
442
 
443
- get prefixLength() {
444
- return this.network?.prefixLength;
445
- }
446
-
447
443
  get host() {
448
444
  return this.owner;
449
445
  }
package/src/owner.mjs CHANGED
@@ -165,6 +165,16 @@ export class Owner extends Base {
165
165
  if (cidr) {
166
166
  return this.subnetNamed(cidr) || new Subnet(this, cidr);
167
167
  }
168
+
169
+ const subnets = [...this.subnets()];
170
+ if (subnets.length === 1) {
171
+ return subnets[0];
172
+ }
173
+
174
+ this.error(
175
+ `Address without subnet ${address}`,
176
+ [...this.subnets()].map(s => s.address)
177
+ );
168
178
  }
169
179
 
170
180
  subnetForAddress(address) {
package/src/subnet.mjs CHANGED
@@ -14,7 +14,11 @@ export class Subnet extends Base {
14
14
  name: "subnet",
15
15
  extends: "base",
16
16
  properties: {
17
- // address: {}
17
+ /*
18
+ address: {},
19
+ networks: { type: "network", collection true },
20
+ prefixLength: { type: "number", writeable: false }
21
+ */
18
22
  }
19
23
  };
20
24
  }
package/src/utils.mjs CHANGED
@@ -137,15 +137,27 @@ export function normalizeCIDR(address) {
137
137
  prefix = "fe80::";
138
138
  prefixLength = 64;
139
139
  } else {
140
+ const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
141
+ let n = _encode(definition, prefix);
142
+
140
143
  if (prefixLength) {
141
- const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
142
- let n = _encode(definition, prefix);
143
144
  n = n & (definition.mask << BigInt(definition.length - prefixLength));
144
145
  prefix = _decode(definition, n, prefixLength);
145
146
  } else {
146
- return {};
147
+ if (n === IPV4_LOCALHOST) {
148
+ prefixLength = 8;
149
+ prefix = _decode(definition, n, prefixLength);
150
+ } else if (n === IPV6_LOCALHOST) {
151
+ prefixLength = 127;
152
+ prefix = _decode(definition, n, prefixLength);
153
+ } else {
154
+ return {};
155
+ }
147
156
  }
148
157
  }
149
158
 
150
159
  return { prefix, prefixLength, cidr: `${prefix}/${prefixLength}` };
151
160
  }
161
+
162
+ const IPV4_LOCALHOST = _encode(ipv4, "127.0.0.1");
163
+ const IPV6_LOCALHOST = _encode(ipv6, "::1");
package/types/host.d.mts CHANGED
@@ -75,7 +75,6 @@ export class NetworkInterface extends Base {
75
75
  get ipAddressesWithPrefixLength(): string[];
76
76
  get ipv4Addresses(): any[];
77
77
  get ipv6Addresses(): any[];
78
- get prefixLength(): any;
79
78
  get scope(): any;
80
79
  get metric(): any;
81
80
  get ssid(): any;