←back to thread

1895 points _l4jh | 5 comments | | HN request time: 0s | source
Show context
DyslexicAtheist ◴[] No.16728255[source]
TIL you can also use 1.1 and it will expand to 1.0.0.1

  $> ping 1.1

  PING 1.1 (1.0.0.1) 56(84) bytes of data.
  64 bytes from 1.0.0.1: icmp_seq=1 ttl=55 time=28.3 ms
  64 bytes from 1.0.0.1: icmp_seq=2 ttl=55 time=33.0 ms
  64 bytes from 1.0.0.1: icmp_seq=3 ttl=55 time=43.6 ms
  64 bytes from 1.0.0.1: icmp_seq=4 ttl=55 time=41.7 ms
  64 bytes from 1.0.0.1: icmp_seq=5 ttl=55 time=56.5 ms
  64 bytes from 1.0.0.1: icmp_seq=6 ttl=55 time=38.4 ms
  64 bytes from 1.0.0.1: icmp_seq=7 ttl=55 time=34.8 ms
  64 bytes from 1.0.0.1: icmp_seq=8 ttl=55 time=45.7 ms
  64 bytes from 1.0.0.1: icmp_seq=9 ttl=55 time=45.2 ms
  64 bytes from 1.0.0.1: icmp_seq=10 ttl=55 time=43.1 ms
replies(5): >>16728294 #>>16728342 #>>16728382 #>>16728420 #>>16729271 #
dieulot ◴[] No.16728382[source]
The most useful case for this shortcut is 127.1 -> 127.0.0.1
replies(3): >>16728626 #>>16728629 #>>16729229 #
avip ◴[] No.16728626[source]
Don't try that in the wild, most sw out there would ignore spec and use some arbitrary regex to validate IP format.

i.e python:

    octets = ip_str.split('.')
    if len(octets) != 4:
        raise AddressValueError("Expected 4 octets in %r" % ip_str)
replies(1): >>16729004 #
1. sigjuice ◴[] No.16729004[source]
What spec says that 127.1 and 127.0.0.1 are equivalent?
replies(2): >>16729069 #>>16729584 #
2. nerdwaller ◴[] No.16729069[source]
I 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

replies(2): >>16729230 #>>16730361 #
3. sigjuice ◴[] No.16729230[source]
Thanks. 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
4. avip ◴[] No.16729584[source]
You are right, I faithfully assumed it's a spec without checking. Thanks.
5. tzs ◴[] No.16730361[source]
The POSIX spec (IEEE 1003.1) says the same thing for inet_addr(), so it does occur in an actual spec.