Skip to content

API Proposal: IPNetwork to support CIDR notation #64033

@alrz

Description

@alrz

Background and motivation

An implementation is exposed through HttpOverrides middleware package at https://github.com/dotnet/aspnetcore/blob/main/src/Middleware/HttpOverrides/src/IPNetwork.cs

This proposal is to promote it under System.Net namespace for a built-in support.

API Proposal

namespace System.Net
{
    public struct IPNetwork
    {
        // eg: "192.168.0.0/16"
        public static IPNetwork Parse(string);
        public IPNetwork(IPAddress, IPAddress);
        public IPNetwork(IPAddress, int);
        public bool Contains(IPAddress);
        // ..
    }
}

API Usage

var range = IPNetwork.Parse(cidr);
bool result = range.Contains(address);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Net

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions