Most active commenters

    ←back to thread

    1895 points _l4jh | 15 comments | | HN request time: 0.201s | source | bottom
    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 #
    1. dieulot ◴[] No.16728382[source]
    The most useful case for this shortcut is 127.1 -> 127.0.0.1
    replies(3): >>16728626 #>>16728629 #>>16729229 #
    2. 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 #
    3. fwgwgwgch ◴[] No.16728629[source]
    Where have you been all my life?
    replies(1): >>16728777 #
    4. mathgeek ◴[] No.16728777[source]
    Sitting at 127.1, apparently.
    5. sigjuice ◴[] No.16729004[source]
    What spec says that 127.1 and 127.0.0.1 are equivalent?
    replies(2): >>16729069 #>>16729584 #
    6. nerdwaller ◴[] No.16729069{3}[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 #
    7. aexaey ◴[] No.16729229[source]
    0, which is a shorthand for 0.0.0.0 is likely the most code-golf-y way to write localhost, as many [EDIT: Linux] systems alias 0.0.0.0 to 127.0.0.1:

      $ ping 0
      PING 0 (127.0.0.1) 56(84) bytes of data.
      64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.032 ms
    
    Of course, don't expect this to work universally. A lot of software will try to be clever with input validation, and fail.

    Tangentially related: https://fosdem.org/2018/schedule/event/email_address_quiz/

    replies(3): >>16729337 #>>16729709 #>>16730226 #
    8. sigjuice ◴[] No.16729230{4}[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
    9. mrkstu ◴[] No.16729337[source]
    Stays unaliased on macOS:

    My-MacBook-Pro:bottle mrkstu$ ping 0 PING 0 (0.0.0.0): 56 data bytes ping: sendto: No route to host

    replies(1): >>16731447 #
    10. avip ◴[] No.16729584{3}[source]
    You are right, I faithfully assumed it's a spec without checking. Thanks.
    11. hartator ◴[] No.16729709[source]
    It's not fully true that 127.0.0.1 is the same as 0.0.0.0. For example, binding a webserver to 0.0.0.0 make it on the public network while 127.0.0.1 is strictly localhost.
    12. pishpash ◴[] No.16730226[source]
    0.0.0.0 is not localhost. It's "any address".
    replies(1): >>16730482 #
    13. tzs ◴[] No.16730361{4}[source]
    The POSIX spec (IEEE 1003.1) says the same thing for inet_addr(), so it does occur in an actual spec.
    14. aexaey ◴[] No.16730482{3}[source]
    Yes, you're right.

    What I was trying to say is - On Linux, INADDR_ANY (0.0.0.0) supplied to connect() or sendto() calls is treated as a synonym for INADDR_LOOPBACK (127.0.0.1) address.

    Not so for bind() or course.

    15. jamiek88 ◴[] No.16731447{3}[source]
    However ping to 127.1 works the same as localhost.