Closed RobbyScherpereel closed 2 years ago
@RobbyScherpereel Thank you for your proposal! Please let me try to explain this idea.
First, the IPAddresRange
class does not represent an IP subnet.
It merely represents a range of IP addresses purely.
"A range of IP addresses" does not equal "an IP subnet".
For example, let's think about the IP address range 10.0.0.0-10.0.255.255.
If you use this IP address range in the 8bit subnet address world, a broadcast address in this world is 10.255.255.255. So the end of that IP address range 10.0.255.255 is usable for a host.
On the other hand, If you use this IP address range in the 16bit subnet address world, a broadcast address in this world is 10.0.255.255. So the end of that IP address range 10.0.255.255 is not usable for a host.
As you can see above, calculating a broadcast address requires the information that the bit length of a subnet.
However, the IPAddressRaneg
class does not have such information.
Therefore, producing a method like the ToUsableHostIPRange()
is impossible.
Again, the IPAddresRange
class merely represents a range of IP addresses purely.
There is no restriction involved with subnets.
By the way, you may create an extension method like IPAddressRange ToUsableHostIPRange(this IPAddressRange range, int subnetLength);
, and also creating that method by yourself might be easy for you.
Finally, I would like to conclude that I would not implement the feature like the ToUsableHostIPRange()
method, at least now.
I hope my conclusion above makes sense to you.
thanks for the explaination. I figured it out already and we are already considering the extension method :)
Hi,
I saw that wen you are returning an IPAddressRange, you guys are including the network and broadcast addresses. I don't know if this is on purpose, but these addresses are not really usable..
Can you modify this so that they are not included?
192.168.1.0 - 192.168.1.255 shoud rather be 192.168.1.1 - 192.168.1.254. We now have to add an extra if to skip the network and broadcast addresses.
Maybe it is an idea to add a for example IPAddressRange.ToUsableHostIPRange() -> see also https://www.calculator.net/ip-subnet-calculator.html .