@ai-ecoverse/slicc-kernel 1.26.2 → 1.26.4

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.
@@ -6375,12 +6375,20 @@ function readAddr(view, ptr) {
6375
6375
  return { family: "inet", host, port };
6376
6376
  }
6377
6377
  if (tag === INET6) {
6378
- const bytes = new Uint8Array(view.buffer, ptr + 4, 16);
6379
- const any = bytes.every((b) => b === 0);
6380
- return { family: "inet", host: any ? "0.0.0.0" : LOOPBACK, port };
6378
+ return { family: "inet", host: ipv6Host(new Uint8Array(view.buffer, ptr + 4, 16)), port };
6381
6379
  }
6382
6380
  throw new WasiError("EAFNOSUPPORT");
6383
6381
  }
6382
+ function ipv6Host(bytes) {
6383
+ const zeros = (n) => bytes.subarray(0, n).every((b) => b === 0);
6384
+ if (zeros(16)) return "0.0.0.0";
6385
+ if (zeros(15) && bytes[15] === 1) return LOOPBACK;
6386
+ if (zeros(10) && bytes[10] === 255 && bytes[11] === 255) return bytes.subarray(12).join(".");
6387
+ const groups = [0, 2, 4, 6, 8, 10, 12, 14].map(
6388
+ (i) => (bytes[i] << 8 | bytes[i + 1]).toString(16)
6389
+ );
6390
+ return new URL(`http://[${groups.join(":")}]/`).hostname.slice(1, -1);
6391
+ }
6384
6392
  function writeAddr(view, ptr, addr) {
6385
6393
  new Uint8Array(view.buffer, ptr, 110).fill(0);
6386
6394
  if (!addr) return;