3 ms·
What spec says that 127.1 and 127.0.0.1 are equivalent?
by sigjuice 9y ago
What spec says that 127.1 and 127.0.0.1 are equivalent?
- nerdwaller 9y agoI don’t actually think it’s in a spec formally but is in a common c lib[0]. > a.b > Part a specifies the first byte of the binary address. Part b is interpreted as a 24-bit value that defines the rightmost three bytes of the binary address. This notation is suitable for specifying (outmoded) Class C network addresses. [0]: https://linux.die.net/man/3/inet_aton https://linux.die.net/man/3/inet_aton
- sigjuice 9y agoThanks. I just came across the man page myself while I was writing this tiny program. $ cat 127.1.c #include <stdio.h> #include <arpa/inet.h> int main(int argc, char *argv[]) { struct in_addr addr; if (inet_aton(argv[1], &addr)) printf("%08x\n", addr.s_addr); return 0; } $ make 127.1 CFLAGS=-Wall cc -Wall 127.1.c -o 127.1 $ ./127.1 1.1 01000001 $ ./127.1 127.1 0100007f
- tzs 9y agoThe POSIX spec (IEEE 1003.1) says the same thing for inet_addr(), so it does occur in an actual spec.
- avip 9y agoYou are right, I faithfully assumed it's a spec without checking. Thanks.