diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-12 12:14:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-12 13:47:07 +0200 |
commit | 532db9f76881b574924b7fb26772cc911e343a5a (patch) | |
tree | 538b77a4867b8b6e38c105aa8d803e24c1553047 | |
parent | af59f64bc0ca4446deb3265a4b1a37be3fb5d2ab (diff) | |
download | serenity-532db9f76881b574924b7fb26772cc911e343a5a.zip |
Kernel: Treat 0.0.0.0 as a loopback address
This matches what other operating systems like Linux do:
$ ip route get 0.0.0.0
local 0.0.0.0 dev lo src 127.0.0.1 uid 1000
cache <local>
$ ssh 0.0.0.0
gunnar@0.0.0.0's password:
$ ss -na | grep :22 | grep ESTAB
tcp ESTAB 0 0 127.0.0.1:43118 127.0.0.1:22
tcp ESTAB 0 0 127.0.0.1:22 127.0.0.1:43118
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/Routing.cpp | 2 |
3 files changed, 6 insertions, 0 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 62fd5cec4d..ad039cd4e7 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -139,6 +139,8 @@ KResult IPv4Socket::connect(FileDescription& description, Userspace<const sockad return EFAULT; m_peer_address = IPv4Address((const u8*)&safe_address.sin_addr.s_addr); + if (m_peer_address == IPv4Address { 0, 0, 0, 0 }) + m_peer_address = IPv4Address { 127, 0, 0, 1 }; m_peer_port = ntohs(safe_address.sin_port); return protocol_connect(description, should_block); diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index 7a72bcc868..d310912a55 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -40,6 +40,8 @@ RefPtr<NetworkAdapter> NetworkAdapter::from_ipv4_address(const IPv4Address& addr if (adapter->ipv4_address() == address || adapter->ipv4_broadcast() == address) return adapter; } + if (address[0] == 0 && address[1] == 0 && address[2] == 0 && address[3] == 0) + return LoopbackAdapter::the(); if (address[0] == 127) return LoopbackAdapter::the(); return nullptr; diff --git a/Kernel/Net/Routing.cpp b/Kernel/Net/Routing.cpp index e207cd35f4..3c6a6d0aac 100644 --- a/Kernel/Net/Routing.cpp +++ b/Kernel/Net/Routing.cpp @@ -141,6 +141,8 @@ RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, c return { adapter, mac }; }; + if (target[0] == 0 && target[1] == 0 && target[2] == 0 && target[3] == 0) + return if_matches(LoopbackAdapter::the(), LoopbackAdapter::the().mac_address()); if (target[0] == 127) return if_matches(LoopbackAdapter::the(), LoopbackAdapter::the().mac_address()); |