Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's some weird legacy parsing for IPv4 addresses with less than four components. 1.2.3.4 can be represented equivalently as 1.2.772, 1.131844, or 16909060. (Note that 772 = 0x0304, 131844 = 0x020304, and 16909060 = 0x01020304.)

TL;DR: the second "1" in "1.1" is treated as a 24-bit integer.

Longer explanation: https://blog.dave.tf/post/ip-addr-parsing/



Aha. I had thought I recalled the two-dot case being 16+16, rather than 8+24.


It was for compatibility with classful networks. If you have a class A (/8) network, you could (in principle) treat it as a single network and number all the machines on it sequentially from 12.1 to 12.16777215.

Of course, nobody actually does that anymore. But the parser behavior is still out there because there's the possibility that someone is still using it...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: