Skip to content

API proposal: Mask testing for IPAddress #42845

@huoyaoyuan

Description

@huoyaoyuan

Background and Motivation

From #42840
A weird workaround is used for mask testing. Masking should be exposed as a direct concept for ip addresses.

Proposed API

namespace System.Net
{
    public class IPAddress
    {
+        public bool IsMask(IPAddress address, int maskLength);
    }
}

Usage Examples

var mask = IPAddress.Parse("192.168.0.0");
var address = IPAddress.Parse("192.168.1.1");
Assert.True(mask.IsMask(address, 16));

Alternative Designs

Expose a separated IPAddressMask type? Then mask length doesn't needed to be passed in every call.

Risks

Is storing masks violating the IPAddress type? If so, an IPAddressMask type should be appropriate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Netneeds-author-actionAn issue or pull request that requires more info or actions from the author.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions