mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
Kernel: Report AF_UNIX address family when accepting local sockets
Previously we just wrote the local socket bind path into the sockaddr_un buffer. With this patch, we actually report the family as well.
This commit is contained in:
parent
612dbdc671
commit
8e9676c28c
1 changed files with 12 additions and 6 deletions
|
@ -100,14 +100,20 @@ LocalSocket::~LocalSocket()
|
||||||
|
|
||||||
void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
|
void LocalSocket::get_local_address(sockaddr* address, socklen_t* address_size)
|
||||||
{
|
{
|
||||||
|
auto& address_un = *reinterpret_cast<sockaddr_un*>(address);
|
||||||
|
address_un = {
|
||||||
|
.sun_family = AF_UNIX,
|
||||||
|
.sun_path = {},
|
||||||
|
};
|
||||||
|
|
||||||
if (!m_path || m_path->is_empty()) {
|
if (!m_path || m_path->is_empty()) {
|
||||||
size_t bytes_to_copy = min(static_cast<size_t>(*address_size), sizeof(sockaddr_un));
|
*address_size = sizeof(address_un.sun_family);
|
||||||
memset(address, 0, bytes_to_copy);
|
return;
|
||||||
} else {
|
|
||||||
size_t bytes_to_copy = min(m_path->length(), min(static_cast<size_t>(*address_size), sizeof(sockaddr_un)));
|
|
||||||
memcpy(address, m_path->characters(), bytes_to_copy);
|
|
||||||
}
|
}
|
||||||
*address_size = sizeof(sockaddr_un);
|
|
||||||
|
size_t bytes_to_copy = min(m_path->length() + 1, min(static_cast<size_t>(*address_size), sizeof(address_un.sun_path)));
|
||||||
|
memcpy(address_un.sun_path, m_path->characters(), bytes_to_copy);
|
||||||
|
*address_size = sizeof(address_un.sun_family) + bytes_to_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size)
|
void LocalSocket::get_peer_address(sockaddr* address, socklen_t* address_size)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue