mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-08 01:27:31 +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:
@@ -82,30 +82,18 @@ IPv4Socket::~IPv4Socket()
|
||||
all_sockets().resource().remove(this);
|
||||
}
|
||||
|
||||
bool IPv4Socket::get_local_address(sockaddr* address, socklen_t* address_size)
|
||||
void IPv4Socket::get_local_address(sockaddr* address, socklen_t* address_size)
|
||||
{
|
||||
// FIXME: Look into what fallback behavior we should have here.
|
||||
if (*address_size < sizeof(sockaddr_in))
|
||||
return false;
|
||||
auto& ia = (sockaddr_in&)*address;
|
||||
ia.sin_family = AF_INET;
|
||||
ia.sin_port = htons(m_local_port);
|
||||
memcpy(&ia.sin_addr, &m_local_address, sizeof(IPv4Address));
|
||||
sockaddr_in local_address = { AF_INET, htons(m_local_port), { m_local_address.to_in_addr_t() }, { 0 } };
|
||||
memcpy(address, &local_address, min(static_cast<size_t>(*address_size), sizeof(sockaddr_in)));
|
||||
*address_size = sizeof(sockaddr_in);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IPv4Socket::get_peer_address(sockaddr* address, socklen_t* address_size)
|
||||
void IPv4Socket::get_peer_address(sockaddr* address, socklen_t* address_size)
|
||||
{
|
||||
// FIXME: Look into what fallback behavior we should have here.
|
||||
if (*address_size < sizeof(sockaddr_in))
|
||||
return false;
|
||||
auto& ia = (sockaddr_in&)*address;
|
||||
ia.sin_family = AF_INET;
|
||||
ia.sin_port = htons(m_peer_port);
|
||||
memcpy(&ia.sin_addr, &m_peer_address, sizeof(IPv4Address));
|
||||
sockaddr_in peer_address = { AF_INET, htons(m_peer_port), { m_peer_address.to_in_addr_t() }, { 0 } };
|
||||
memcpy(address, &peer_address, min(static_cast<size_t>(*address_size), sizeof(sockaddr_in)));
|
||||
*address_size = sizeof(sockaddr_in);
|
||||
return true;
|
||||
}
|
||||
|
||||
KResult IPv4Socket::bind(const sockaddr* user_address, socklen_t address_size)
|
||||
|
||||
Reference in New Issue
Block a user