Classful adresses with less than three groupings
When writing classful addresses in decimal, you are allowed to combine octets in the host part. So in a class A network: 10.0.23.112, 10.23.112 and 10.6000 are equivalent. Note that the last representation gives the wrong output in the current implementation while "192.6000" should return false, given that it would be a class C address.
Such complex state tracking is in my opinion not suitable for regex evaluation (arguably not for a composition either). I suggest we change this implementation to split the string by periods into a list of strings (like PHP's
explode()), converting each list item to an integer and continuing from there. When support for that arrives, of course.
The function should also take a boolean as an input to decide whether it should use classful notations at all. Preferably such an option should default to false given that is has been discouraged for 30 years, but that is also not possible on Wikifunctions.
- “are allowed”… well it depends. There is no formal specification of a textual IPv4 address format. Some libraries support various formats (including possible octal or hexadecimal syntaxes), others do not. POSIX
inet_ptonallows only four-quad decimal notation. (See also w:Dot-decimal notation#IPv4 address.) I would expect this function to support only full four-quad notation as well. (And no boolean arguments for switching behavior please. Different behaviors should be different functions, not one functions with a bunch of toggles.) --Mormegil (talk) 09:44, 22 August 2023 (UTC)