Add offset() and nextNetwork(), accept prefix-length ip6.arpa names, correct the IPv6 end-address docs - #225
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three long-standing issues in one small pass.
#118:
offset(n)returns the addressnafter (or before, negative) this one with the same subnet mask;nextNetwork()returns the network afterendAddress()with the same mask. Both classes.nis a number or bigint; non-integers,NaN,Infinity, unsafe integers, and non-numeric values throwAddressError, 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 withsubnetMask = nibbles × 4, sofromArpa(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
fromArparejects in under 1 ms (anchored regex, no backtracking); fullwidth digits, newlines, and an inner.ip6.arpaare rejected;offsetwith2**200n, objects withvalueOf, strings,undefinedall throw. No new string parsing beyondfromArpa, and everything else routes through the existing validatedfromBigIntconstructors.