[TUHS] conventions around zero padding in ip4

Ralph Corderoy ralph at inputplus.co.uk
Sun May 8 20:22:08 AEST 2022


Hi Ron,

> I first learned in the 80s that 127.1 meant 127.0.0.1. I always
> assumed zero padding was defined in a standard *somewhere*, but am
> finding out maybe not.

It has been standardised; see inet_addr(3p) where ‘p’ means the POSIX
version of the man page or
https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_addr.html

Briefly, the string must be one of

    a.b.c.d
    a.b.cd
    a.bcd
    abcd

where the number of bytes represented is the number of characters.
Each number is as defined by ISO C, e.g. ‘0x...’ means hex, thus
‘ping 017777777776’.

That's all there is to it.  It's simple to explain and I've used it for
years too.  Given POSIX defines it, without deprecation, programming
languages which don't use the C library and programs which must parse
the string themselves should follow POSIX to avoid those annoying
programs which deviate from the long-established norm.

> IP4 padding came up recently: the ip command interprets 10.2 as
> 10.2.0.0, whereas most things (golang libraries, ping, ...) interpret
> it as 10.0.0.2.

Bug the ip(1) folks, pointing to POSIX.  :-)

-- 
Cheers, Ralph.


More information about the TUHS mailing list