function cidrv6Size
cidrv6Size(cidr: Cidrv6): bigint

Returns the total number of IP addresses in a CIDR block.

For a /120 network, this returns 256n. For a /128, this returns 1n. The result is a bigint because IPv6 blocks can hold up to 2^128 addresses.

Examples

Getting CIDR size from Cidrv6 object

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

assertEquals(cidrv6Size(parseCidrv6("fd00::/120")), 256n);
assertEquals(cidrv6Size(parseCidrv6("2001:db8::/32")), 79228162514264337593543950336n);
assertEquals(cidrv6Size(parseCidrv6("::1/128")), 1n);
assertEquals(cidrv6Size(parseCidrv6("::/64")), 18446744073709551616n);

Parameters

cidr: Cidrv6

The CIDR block

Return Type

bigint

The total number of addresses in the CIDR block as a bigint

cidrv6Size(prefixLength: PrefixLengthv6): bigint

Returns the total number of IP addresses for a given prefix length.

Examples

Getting CIDR size from prefix length

import { assertEquals } from "@std/assert";
import { cidrv6Size } from "@hertzg/ip/cidrv6";

assertEquals(cidrv6Size(120), 256n);
assertEquals(cidrv6Size(128), 1n);
assertEquals(cidrv6Size(64), 18446744073709551616n);

Out-of-range prefix length throws

import { assertThrows } from "@std/assert";
import { cidrv6Size } from "@hertzg/ip/cidrv6";

assertThrows(() => cidrv6Size(-1), RangeError);
assertThrows(() => cidrv6Size(129), RangeError);

Parameters

prefixLength: PrefixLengthv6

The CIDR prefix length (0-128)

Return Type

bigint

The total number of addresses as a bigint

Throws

RangeError

If the prefix length is out of range (not 0-128)

cidrv6Size(cidrOrPrefixLength: Cidrv6 | PrefixLengthv6): bigint

Returns the total number of IP addresses for either a CIDR block or a prefix length.

Parameters

cidrOrPrefixLength: Cidrv6 | PrefixLengthv6

A Cidrv6 block or a prefix length (0-128)

Return Type

bigint

The total number of addresses as a bigint