Skip to content

Add offset() and nextNetwork(), accept prefix-length ip6.arpa names, correct the IPv6 end-address docs - #225

Merged
beaugunderson merged 1 commit into
mainfrom
bg-long-tail
Aug 29, 2026
Merged

Add offset() and nextNetwork(), accept prefix-length ip6.arpa names, correct the IPv6 end-address docs#225
beaugunderson merged 1 commit into
mainfrom
bg-long-tail

Conversation

@beaugunderson

Copy link
Copy Markdown
Owner

Three long-standing issues in one small pass.

#118: offset(n) returns the address n after (or before, negative) this one with the same subnet mask; nextNetwork() returns the network after endAddress() with the same mask. Both classes. n is a number or bigint; non-integers, NaN, Infinity, unsafe integers, and non-numeric values throw AddressError, and so does a result outside the address space (255.255.255.255.offset(1), ::/0.nextNetwork()).

#141: Address6.fromArpa() accepts 1 to 32 nibbles and returns the delegated network with subnetMask = nibbles × 4, so fromArpa(x.reverseForm()).networkForm() === x.networkForm() for any prefix. A full 32-nibble name still gives a /128 (existing behavior). The root dot is now optional. Input is validated by a single anchored regex (^[0-9a-f](\.[0-9a-f]){0,31}$, case-insensitive) before any processing.

#172: Address6.endAddress() / endAddressExclusive() docs no longer describe a broadcast; IPv6 has none, the last address is assignable, and the exclusive form drops exactly one address rather than modeling the RFC 2526 reserved subnet-anycast block. Behavior unchanged.

Surface check on the new entry points: 1 MB of nibbles, junk, or dots into fromArpa rejects in under 1 ms (anchored regex, no backtracking); fullwidth digits, newlines, and an inner .ip6.arpa are rejected; offset with 2**200n, objects with valueOf, strings, undefined all throw. No new string parsing beyond fromArpa, and everything else routes through the existing validated fromBigInt constructors.

…correct the IPv6 end-address docs

offset(n) returns the address n after (or before) this one with the
same subnet mask; nextNetwork() returns the network after endAddress().
Both take a number or bigint, reject non-integers, and throw when the
result leaves the address space.

Address6.fromArpa() accepts a name of 1 to 32 nibbles and returns the
network it delegates with a mask of four bits per nibble, so
fromArpa(x.reverseForm()) round-trips for any prefix; a full 32-nibble
name still yields a /128. The root dot is optional.

endAddress() and endAddressExclusive() on Address6 no longer describe a
broadcast address: IPv6 has none, the last address is assignable, and
the exclusive form drops exactly one address rather than the RFC 2526
reserved subnet-anycast block.
@beaugunderson
beaugunderson merged commit 87fae23 into main Aug 29, 2026
6 checks passed
@beaugunderson
beaugunderson deleted the bg-long-tail branch August 29, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant