Repository navigation
Bitvantage.InternetProtocol.IPNetworkExtensions 1.0.0
First release of Bitvantage.InternetProtocol.IPNetworkExtensions: C# 14 extension members for .NET's built-in
System.Net.IPNetwork and IPAddress that add CIDR, subnet and supernet math. It targets .NET 8 and .NET 10 and is
licensed under MIT.
dotnet add package Bitvantage.InternetProtocol.IPNetworkExtensionsThe extension members need C# 14, which comes with the .NET 10 SDK. A .NET 10 project has it already; a .NET 8 or
.NET 9 project turns it on with <LangVersion>14</LangVersion>.
Breaking changes from Bitvantage.InternetProtocol.NetworkPrefix
This package succeeds Bitvantage.InternetProtocol.NetworkPrefix 2.0.0. The
migration guide maps
every member and lists every change; the main ones are:
- The
NetworkPrefixclass is gone. Its members are extension members onIPNetwork, in the same
Bitvantage.InternetProtocolnamespace, and the containment methods take .NET's set names:IsSubnetOf,
IsSupernetOf,IsProperSubnetOfandIsProperSupernetOf. ParseStrictaccepts only standard dotted-decimal IPv4, so010.0.0.0/8, whichIPAddressreads as octal
8.0.0.0/8, and shorthand such as10.0.0/24are rejected.- Parsing no longer looks up host names;
IPNetwork.ResolveandResolveAsyncdo. - Sorting needs
IPNetwork.Comparer, sinceIPNetworkdoes not implementIComparable. NetworkPrefixJsonConverteris replaced byIPNetworkJsonConverter, and XML serialization is no longer supported.Excludefollows set semantics and returns a sorted list,Summarizereturns the sorted minimal set, IPv6 host
ranges and counts include the last address, andAllocationfollows the IANA special-purpose registries.
Features
- Masks and host ranges: network and wildcard masks, first and last host, host and address counts, and enumeration.
- Subnet and supernet tests, overlap, splitting, halves, supernets and complementary networks.
- Set operations on lists of networks:
Summarize,Intersect,ExcludeandGetRanges. - Address ranges: the fewest networks that cover a range, and parsing of text such as
10.0.0.1-10.0.0.9. - Address planning: free subnets of a given length with
AvailableSubnets, and offsets within a network. - Classification by IANA allocation and by class, and the networks of an allocation, such as the private networks.
- Reverse DNS names and zones, including zones of networks that are not on a label boundary.
IPAddressmembers: strict parsing, comparison, arithmetic, classification,Unmapfor IPv4-mapped addresses and
the expanded IPv6 form.- JSON converters for
IPNetworkandIPAddress, which also work as dictionary keys and with source-generated
serialization, and type converters so that configuration binding reads networks and addresses instead of silently
leaving them empty. - Compatible with trimming and native AOT, with Source Link and a symbol package.
Fixes
Compared with NetworkPrefix 2.0.0:
- Converting an IPv4 address wrote 16 bytes into a 4 byte array, past its end.
TryParsethrew for an out-of-range prefix length or a mask with gaps, rather than returningfalse.- Text with leading whitespace or extra separators parsed as a /0, and a mask of the other IP version was accepted.
GetContainingNetworkreturned the IPv40.0.0.0/0for an IPv6 /0.Summarizethrew on duplicates or on a network listed with both of its halves, and kept covered networks.- Enumerating addresses or hosts never ended at the top of the IPv6 space, and
Split(128)of::/0overflowed. Allocationreported reserved blocks, and networks that take in special-purpose space, asGlobal.