mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 23:39:02 +00:00
Kernel: Add getpeername() syscall, and fix getsockname() behavior.
We were copying the raw IPv4 addresses into the wrong part of sockaddr_in, and we didn't set sa_family or sa_port.
This commit is contained in:
parent
f008156dbf
commit
ae470ec955
Notes:
sideshowbarker
2024-07-19 14:00:00 +09:00
Author: https://github.com/awesomekling
Commit: ae470ec955
11 changed files with 73 additions and 9 deletions
|
@ -46,12 +46,28 @@ IPv4Socket::~IPv4Socket()
|
|||
all_sockets().resource().remove(this);
|
||||
}
|
||||
|
||||
bool IPv4Socket::get_address(sockaddr* address, socklen_t* address_size)
|
||||
bool 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))
|
||||
if (*address_size < sizeof(sockaddr_in))
|
||||
return false;
|
||||
memcpy(address, &m_peer_address, sizeof(sockaddr_in));
|
||||
auto& ia = (sockaddr_in&)*address;
|
||||
ia.sin_family = AF_INET;
|
||||
ia.sin_port = m_local_port;
|
||||
memcpy(&ia.sin_addr, &m_local_address, sizeof(IPv4Address));
|
||||
*address_size = sizeof(sockaddr_in);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool 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 = m_peer_port;
|
||||
memcpy(&ia.sin_addr, &m_peer_address, sizeof(IPv4Address));
|
||||
*address_size = sizeof(sockaddr_in);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue