function cidrv6FirstAddress
cidrv6FirstAddress(cidr: Cidrv6): bigint

Returns the first address of a CIDR block.

IPv6 has no equivalent of the IPv4 network address, so unlike cidrv4FirstAddress this is normally assignable to an interface. The one caveat is per-link rather than universal: RFC 4291 section 2.6.1 reserves the all-zeros interface identifier as the Subnet-Router anycast address, while RFC 6164 assigns both addresses of a /127 inter-router link.

Because that reservation depends on the link, there is deliberately no cidrv6FirstUsableAddress to pair with cidrv4FirstUsableAddress. Callers whose link does reserve the anycast skip it themselves — see the second example.

Examples

Getting first address

import { assertEquals } from "@std/assert";
import { cidrv6FirstAddress, parseCidrv6 } from "@hertzg/ip/cidrv6";
import { parseAddressv6 } from "@hertzg/ip/addressv6";

const cidr = parseCidrv6("2001:db8::/32");
assertEquals(cidrv6FirstAddress(cidr), parseAddressv6("2001:db8::").address);

Skipping the Subnet-Router anycast on a link that reserves it

import { assertEquals } from "@std/assert";
import { cidrv6Addresses, parseCidrv6 } from "@hertzg/ip/cidrv6";
import { stringifyAddressv6 } from "@hertzg/ip/addressv6";

const cidr = parseCidrv6("2001:db8::/126");
const assignable = Array.from(cidrv6Addresses(cidr, { offset: 1n }));
assertEquals(assignable.map(stringifyAddressv6), [
  "2001:db8::1",
  "2001:db8::2",
  "2001:db8::3",
]);

Parameters

cidr: Cidrv6

The CIDR block

Return Type

bigint

The first address as a bigint