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
I use IPNetwork.Parse to parse a user's configuration when they set up their allowed IP ranges. I'd like to allow them to type in single IP addresses and for my code to interpret that this-IP-only, but instead I get the class-A/B/C network that IP is in. (Because of this, my code calls IPAddress.Parse first, falling back to IPNetwork.Parse.)
What if we added IPNetwork.ParseFlex which is documented as being tailored for user configuration, leaving Parse as suitable for validation and code expecting legacy behaviour.
Changed my mind, as ParseFlex would be just what I want. I'd instead add IPNetwork.Parse(string, ParseOptions)
ParseOptions would have the following get/set properties...
SingleIP (enum - What to do if the string is a single IP without a "/".)
Classful (Default - Cut at /8, /16 or /24 per IPv4 class or /64 for IPv6)
SingleIPNetwork (Adds /32 or /128 as applicable.)
Zeros (Count any ".0" or ":0000" on the right as the network size. "10.11.0.0" becomes 10.11.0.0/16)
RequireIP (enum - Require a particular version of IP.)
Any (Default - Allow IPv4 and IPv6.)
IPv4Only (Reject any string that isn't IPv4.)
IPv6Only (Reject any string that isn't IPv6.)
This class ParseOptions could be extended with new options, as long as the default is the status quo.
Thoughts?
billpg
changed the title
IPNetwork.ParseFlex, where single IP address strings are returned as /32 or /128.
IPNetwork.Parse(string, ParseOptions)
Dec 23, 2022
I use
IPNetwork.Parse
to parse a user's configuration when they set up their allowed IP ranges. I'd like to allow them to type in single IP addresses and for my code to interpret that this-IP-only, but instead I get the class-A/B/C network that IP is in. (Because of this, my code callsIPAddress.Parse
first, falling back toIPNetwork.Parse
.)What if we added
IPNetwork.ParseFlex
which is documented as being tailored for user configuration, leavingParse
as suitable for validation and code expecting legacy behaviour.IPNetwork.ParseFlex("192.168.1.1/8")
returns192.0.0.0/8
.IPNetwork.ParseFlex("192.168.1.1")
returns192.168.1.1/32
.I'm happy to work on this but I'd like to establish a consensus that we want this before I barrel ahead and start coding.
The text was updated successfully, but these errors were encountered: