cidrv6Intersect(): Cidrv6 | null
Returns the intersection of two IPv6 CIDR blocks.
Since CIDR blocks are power-of-2-aligned, two overlapping blocks always have a containment relationship -- the intersection is the more specific (longer prefix) block with its canonical network address.
The result matches the dialect of the inputs. When they disagree, it is a MaskedCidrv6 (ADR 0006).
Find overlap between allocations
Find overlap between allocations
import { assertEquals } from "@std/assert"; import { cidrv6Intersect, parseCidrv6, stringifyCidrv6 } from "@hertzg/ip/cidrv6"; const result = cidrv6Intersect( parseCidrv6("2001:db8::/32"), parseCidrv6("2001:db8::/48"), ); assertEquals(result && stringifyCidrv6(result), "2001:db8::/48");
No overlap returns null
No overlap returns null
import { assertEquals } from "@std/assert"; import { cidrv6Intersect, parseCidrv6 } from "@hertzg/ip/cidrv6"; assertEquals(cidrv6Intersect( parseCidrv6("2001:db8::/32"), parseCidrv6("2001:db9::/32"), ), null);
Mixed dialects intersect to a masked block
Mixed dialects intersect to a masked block
import { assertEquals } from "@std/assert"; import { cidrv6Intersect, parseCidrv6 } from "@hertzg/ip/cidrv6"; const mask = 0xFFFFFFFFFFFF00000000000000000000n; const result = cidrv6Intersect( parseCidrv6("2001:db8::/32"), { address: 0x20010db8n << 96n, mask }, ); assertEquals(result, { address: 0x20010db8n << 96n, mask });
Cidrv6 | null
The overlapping CIDR with canonical network address, or null if disjoint