Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method which returns CIDR bit #84

Open
ktdann opened this issue Jun 2, 2024 · 2 comments
Open

Method which returns CIDR bit #84

ktdann opened this issue Jun 2, 2024 · 2 comments

Comments

@ktdann
Copy link

ktdann commented Jun 2, 2024

Hi,

Here is a code that does NOT work, but explains what I want to do.
var ipBegin = IPAddress.Parse("192.168.0.0");
var rangeA = new IPAddressRange(ipBegin, maskLength: 24);
rangeA.ToCidrBit() // is 24

I'm looking for a way to get the CIDR bit (or maskLength, as this project calls it) from the existing IPAddressRange object. (none exist)

And the closest I've found is by, see below,
var ipSubnet = IPAddress.Parse("255.255.255.0");
IPAddressRange.SubnetMaskLength(ipSubnet); // is 24

However, this will not help me as I can't find a way to get the subnet mask from the existing IPAddressRange object.
Is there a way to do this?

@jsakamoto
Copy link
Owner

Hi @ktdann,

The GetPrefixLength() method of the IPAddressRange object might work for that purpose, like the ToCidrBit() method in your fictitious sample programs. Could you try it out?

@ktdann
Copy link
Author

ktdann commented Jun 3, 2024

Spot on. That certainly went past my radar :)
I appreciate your help.

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

No branches or pull requests

2 participants