Reputation: 3676
According to the IP dot notation, it is standard to use base 10 representation rather than hexadecimal.
127.0.0.1 -> 7F.0.0.1
255.255.255.255 -> FF.FF.FF.FF
10.0.0.1 -> 0A.0.0.1
10.0.0.1/24 -> 0A.0.0.1/18
I couldn't find any references in RFC's as to why the convention for IPv4 is base 10, but MAC and IPV6 use Hex by default.
Is there a reason we do this? Or is it purely historic in nature?
Upvotes: 6
Views: 1643
Reputation: 343
Decimal is a de facto standard; string formatting for IPv4 addresses was never properly standardised. Almost all tools will only take decimal, dotted-quad, notation, but that's not universally true; any tools still using common implementations of inet_aton()
are likely to handle alternative formats.
ping
included in the iputils package is a useful example. Take one of google's addresses, and try decimal, hex, and octal dotted-quads:
ping -c1 216.58.195.238
ping -c1 0xd8.0x3a.0xc3.0xee
ping -c1 0330.072.0303.0356
These all ping the same address, because they all represent the same 32 bits.
But it goes further than that. You don't strictly have to use four octets; classful addressing once specified 8-bit, 16-bit, and 24-bit network prefixes, before the days of classless addressing and variable-length netmasks. Some of that is still baked into inet_aton()
:
The address above, formatted as 8/8/16 bits:
ping -c1 216.58.50158
ping -c1 0330.072.0141756
ping -c1 0xd8.0x3a.0xc3ee
Or, formatted as 8/24 bits:
ping -c1 216.3851246
ping -c1 0330.016541756
ping -c1 0xd8.0x3ac3ee
Or, forget the dots and just throw in 32 bits:
ping -c1 3627729902
ping -c1 033016541756
ping -c1 0xd83ac3ee
But even better, you don't have to hand over each chunk in the same format:
ping -c1 0xd8.072.195.0xee
This all leads to a legitimate reminder, however: inet_aton()
is an old, old function, and has no comprehension of what an IPv6 address is. If you're writing code today, you wouldn't want to use inet_aton()
, you'd want to use inet_pton()
, which handles both. Implementations of inet_pton()
that I've used stick more faithfully to the de-facto standard IPv4 address representation of decimal dotted-quads. For IPv6, which actually does have an RFC on string representation, inet_pton()
follows the standards!
Upvotes: 10
Reputation: 21
In RFC 790, the network numbers are assigned , from there you can get answer to your question.
RFC 790 talks about the diffrent network numbers assigned and all these are in 10 base decimal format.
Upvotes: 0