1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Kernel: Truncate addresses stored by getsockname() and getpeername()

If there's not enough space in the output buffer for the whole sockaddr
we now simply truncate the address instead of returning EINVAL.

This patch also makes getpeername() actually return the peer address
rather than the local address.. :^)
This commit is contained in:
Andreas Kling 2020-02-07 23:42:28 +01:00
parent d34ad44f90
commit d04fcccc90
6 changed files with 23 additions and 38 deletions

View file

@ -76,19 +76,16 @@ LocalSocket::~LocalSocket()
all_sockets().resource().remove(this);
}
bool LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
{
// FIXME: Look into what fallback behavior we should have here.
if (*address_size != sizeof(sockaddr_un))
return false;
memcpy(address, &m_address, sizeof(sockaddr_un));
size_t bytes_to_copy = min(static_cast<size_t>(*address_size), sizeof(sockaddr_un));
memcpy(address, &m_address, bytes_to_copy);
*address_size = sizeof(sockaddr_un);
return true;
}
bool LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size)
void LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size)
{
return get_local_address(address, address_size);
get_local_address(address, address_size);
}
KResult LocalSocket::bind(const sockaddr* user_address, socklen_t address_size)