It only means that as a source address (i.e. when binding a socket to a local interface). As the destination address it doesn't have this meaning – it's technically an illegal address.
However it seems that originally BSD treated it as a loopback connection and Linux carries it on.
For IPv4, an all-zeros destination is handled in net/ipv4/route.c
at route lookup time:
struct rtable *ip_route_output_key_hash_rcu(...) {
...
if (!fl4->daddr) {
fl4->daddr = fl4->saddr;
if (!fl4->daddr)
fl4->daddr = fl4->saddr = htonl(INADDR_LOOPBACK);
dev_out = net->loopback_dev;
fl4->flowi4_oif = LOOPBACK_IFINDEX;
res->type = RTN_LOCAL;
flags |= RTCF_LOCAL;
goto make_route;
}
...
}
Which translates to "If destination is empty, fill it in with 127.0.0.1 and route via the lo
interface". The OS pretends that you tried to connect to localhost.
The same in IPv6 is handled at protocol level (individually by TCP and UDP). For example, net/ipv6/tcp_ipv6.c
contains:
static int tcp_v6_connect(...) {
...
/*
* connect() to INADDR_ANY means loopback (BSD'ism).
*/
if (ipv6_addr_any(&usin->sin6_addr)) {
if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
&usin->sin6_addr);
else
usin->sin6_addr = in6addr_loopback;
}
...
}
Meanwhile in net/ipv6/udp.c
:
int udpv6_sendmsg(...) {
...
if (!ipv6_addr_any(daddr))
fl6.daddr = *daddr;
else
fl6.daddr.s6_addr[15] = 0x1; /* :: means loopback (BSD'ism) */
...
}
@DavidPostill Could you say, is there information why linux OS redirects 0.0.0.0 to localhost in duplicate that you gave? I don't see, do you? – Pavel – 2018-03-26T13:40:04.237
Agreed, the so-called duplicate is anything but. – plugwash – 2018-09-19T14:07:44.800