4 ms·
This will break code that uses (e.g.) 0.0.0.1 as a "fail address": $ telnet 0.0.0.1 22 Trying 0.0.0.1... telnet: Unable to connect to remote host:
by p1mrx 7y ago
This will break code that uses (e.g.) 0.0.0.1 as a "fail address":
$ telnet 0.0.0.1 22
Trying 0.0.0.1...
telnet: Unable to connect to remote host: Invalid argument
It's nice because the connect() syscall fails immediately, instead of sending packets and waiting for a timeout. 0.0.0.0 is not a suitable replacement, because it's interpreted as 127.0.0.1:
$ telnet 0.0.0.0 22
Trying 0.0.0.0...
Connected to 0.0.0.0.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.9p1 Debian-10
Doesn't the kernel have a policy of not breaking userspace, even if the behavior is undocumented?
- zonidjan 7y agoWhy would code detect a failure and then use a fake address to cause an error, instead of just erroring?
- p1mrx 7y agoThe address may not be controlled by the code in question. Think /etc/hosts, command line flags, and config files, where you want some condition to trigger an error.
- herpderperator 7y agoIf you ask me, 0.0.0.0 should not be interpreted as 127.0.0.1. Yes, I know programs like ping interpret it this way as well. I just think it's ridiculous.
- silverwind 7y agoAgree that the bug is in userspace. Unless there is a RFC that says "0.0.0.0 shall be interpreted as 127.0.0.1", it's just super-weird that it even does that.
- p_l 7y agoSo, some software actually parses 0/8 as localhost? This explains so many broken tutorials..
- IshKebab 7y agoThe main use is to control which interfaces servers listen on. I.e. can you access them from other machines.
- unilynx 7y agoIt makes sense if you compare it to how listening sockets work - if I listen on 127.0.0.1:80, I can connect to 127.0.0.1:80. if I listen to 0.0.0.0:80 (all ipv4 addresses), I can connect to 0.0.0.0:80 And as a bonus, I can just 'telnet 0 80' instead of having to type out 127.0.0.1
- IshKebab 7y agoIt says 0.0.0.0 is still reserved, and I've never heard of software using 0.0.0.1 as a "fail address". Is it really common?
- p1mrx 7y agoI know I've used it myself, but from a sample size of one, I can't say whether http://www.hyrumslaw.com/ http://www.hyrumslaw.com/ or http://xkcd.com/1172/ http://xkcd.com/1172/ is more relevant.