For example there is an IP address 192.168.0.1
It is clear that you can use it as the full line, but try that one 192.168.1
It will also work, and it will be automatically converted to 192.168.0.1
That way you can use the address 192.1 and it will act as 192.0.0.1
So if used an address .0.0. you don't need to enter the full line, but only two numbers.
For example, CloudFlare's DNS address 1.0.0.1 can be used as 1.1 instead.
The short version of IP4 supported everywhere, but no related documentation found.
Can someone please explain that?
-
It should be said, not all networking libraries are created equal. And most web-forms use a regex that will only match a full dot-quad.– RickyMay 17, 2022 at 22:08
-
@Ricky yes, I agree with that. But for some settings, like DNS address it is perfect– IGHORMay 18, 2022 at 23:09
2 Answers
Take a look at Textual Representation of IPv4 and IPv6 Addresses
In particular:
Meanwhile, a very popular implementation of IP networking went off in its own direction. 4.2BSD introduced a function inet_aton(), whose job was to interpret character strings as IP addresses. It interpreted both of the syntaxes mentioned in [MTP] (see above): a single number giving the entire 32-bit address, and dot-separated octet values. It also interpreted two intermediate syntaxes: octet- dot-octet-dot-16bits, intended for class B addresses, and octet- dot-24bits, intended for class A addresses. It also allowed some flexibility in how the individual numeric parts were specified: it allowed octal and hexadecimal in addition to decimal, distinguishing these radices by using the C language syntax involving a prefix "0" or "0x", and allowed the numbers to be arbitrarily long.
Those variants are remnants from the classful networking era that ended in 1993. They allowed you to use the class prefix in combination with a single, host-specific number, but not limited to that.
By convention, missing octets are added as 0
after the first one to complete a 32-bit IPv4 address. Possibly the only real-world example actually in broad use was 127.1
for the 127.0.0.1
loopback address.
In addition to your examples, even weirder ones are often possible, e.g. 192.168.257
instead of 192.168.1.1
: 16-bit or even 24-bit values at the end are expanded to two or three octets, respectively. And of course, using a 32-bit value for an address is also possible, somewhat less weirdly.
To make things even more obscure, you can throw in octals or hexadecimals at will: 192.0250.0x101
.
Fortunately, there are many places today where you cannot use those odd notations.