From: Henry Spencer (henry@spsystems.net)
Date: Tue Apr 11 2000 - 15:02:07 CDT
On Tue, 11 Apr 2000, Clive D.W. Feather wrote:
> > > number : non-zero *digit | ( "0x" | "0X" ) 1*hex | "0" *octal
> > Is this drawn from an existing spec, or invented?
>
> I don't know a formal spec, but it's what works here...
It probably works in a lot of places, because people are using the same
utility functions, but that doesn't mean it's desirable... Much of that
flexibility is just *never* used, some of it is error-prone, and requiring
everyone to implement it forever more is a mistake.
We had some discussion about this in the Linux FreeS/WAN project (for
details of the project, <http://www.freeswan.org>), for user interfaces.
We quickly came to the conclusions that:
(1) Octal is an error-prone nuisance that *nobody* uses deliberately.
Leading zeros are invariably meant as padding on decimal numbers.
(2) The old class-A/B/C-based idea of writing the network number as octets
but the host number as a single number is even worse. IP addresses went
classless many years ago. Nowadays, somebody who writes 10.2 is thinking
of the 10.2.0.0/16 subnet, rather than the 10.0.0.2 host.
(3) Hex is occasionally needed but typically as a single number rather
than multiple components (because some ill-designed software outputs
addresses as 32-bit hex). Worse, sometimes it comes in host byte order.
We ended up accepting three forms:
1.2.3.4
0x01020304
0h04030201
The dotted-decimal form is decimal only, its components are 0-255 only,
and each component is exactly one octet. The difference between 0x and 0h
is that 0x uses network byte order (so the first two examples above are
guaranteed equivalent) while 0h uses host byte order (so the third might
be equivalent and might not). We strongly discourage use of the two hex
forms -- they're purely concessions to dealing with broken software -- and
our reverse-conversion routines generate only dotted-decimal.
We've had zero complaints about this.
For news, I would strongly recommend being as strict and narrow as
possible. We're not even talking about user interfaces here. Allow only
dotted decimal with exactly four components, no leading zeros, no hex.
Henry Spencer
henry@spsystems.net