From d395cf38b7e8b95d98f8b1aa15777d561267247c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 22 Sep 2024 17:30:01 +0300 Subject: [PATCH] Kernel: Binding to port 0 will always find unused port --- kernel/kernel/Networking/IPv4Layer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/Networking/IPv4Layer.cpp b/kernel/kernel/Networking/IPv4Layer.cpp index 116ae63a16..0ee5f578f6 100644 --- a/kernel/kernel/Networking/IPv4Layer.cpp +++ b/kernel/kernel/Networking/IPv4Layer.cpp @@ -116,7 +116,9 @@ namespace Kernel return BAN::Error::from_errno(EAFNOSUPPORT); auto& sockaddr_in = *reinterpret_cast(address); - uint16_t port = BAN::host_to_network_endian(sockaddr_in.sin_port); + const uint16_t port = BAN::host_to_network_endian(sockaddr_in.sin_port); + if (port == NetworkSocket::PORT_NONE) + return bind_socket_to_unused(socket, address, address_len); SpinLockGuard _(m_bound_socket_lock);