3 ms·
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
by aexaey 9y ago
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/ https://fosdem.org/2018/schedule/event/email_address_quiz/
- mrkstu 9y agoStays 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
- jamiek88 9y agoHowever ping to 127.1 works the same as localhost.
- hartator 9y agoIt'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.
- pishpash 9y ago0.0.0.0 is not localhost. It's "any address".
- aexaey 9y agoYes, 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.