You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When parsing CIDR address notation to generate a NetworkAddress type, the Address and SubnetMask properties store the intended values. However, the logic for StartAddress and EndAddress attempt to exclude the lowest (original network) IP and the highest (broadcast) IP. This works for large subnet masks, but is improperly executed when using a small mask to request a small number of IP addresses per this sample program:
var addresses = new string[] {
"1.1.1.1/8",
"1.1.1.1/16",
"1.1.1.1/30",
"1.1.1.1/31",
"1.1.1.1/32"
};
foreach(string a in addresses)
{
NetworkAddress na = NetworkAddress.Parse(a);
Console.WriteLine($"CIDR: {a}\nAddress: {na.Address}\nSubnetMask: {na.SubnetMask}\nStartAddress: {na.StartAddress}\nEndAddress: {na.EndAddress}\n");
}
Note that StartAddress and EndAddress are reversed for the /31 case.
At a high level, these results are counter-intuitive to begin with as when requesting a /30, one would expect 4 IP addresses when only 2 are provided. When requesting a /31, intuitively 2 IP addresses would be provided. Seemingly returning the full range without truncation would be a better behavior than having both '/31' and '/30' returning 2 IP addresses.
The text was updated successfully, but these errors were encountered:
StartAddress works as intended when commenting out the final mask addressBytes[addressBytes.Length - 1] |= 0x01 and EndAddress works as intended when commenting out addressBytes[addressBytes.Length - 1] &= 0xFE.
When parsing CIDR address notation to generate a
NetworkAddress
type, theAddress
andSubnetMask
properties store the intended values. However, the logic forStartAddress
andEndAddress
attempt to exclude the lowest (original network) IP and the highest (broadcast) IP. This works for large subnet masks, but is improperly executed when using a small mask to request a small number of IP addresses per this sample program:Note that
StartAddress
andEndAddress
are reversed for the/31
case.At a high level, these results are counter-intuitive to begin with as when requesting a
/30
, one would expect 4 IP addresses when only 2 are provided. When requesting a/31
, intuitively 2 IP addresses would be provided. Seemingly returning the full range without truncation would be a better behavior than having both '/31' and '/30' returning 2 IP addresses.The text was updated successfully, but these errors were encountered: