mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +00:00
Kernel: Use Userspace<T> for the sendto syscall, and Socket implementation
Note that the data member is of type ImmutableBufferArgument, which has no Userspace<T> usage. I left it alone for now, to be fixed in a future change holistically for all usages.
This commit is contained in:
parent
d4dae49dcd
commit
9f9b05ba0f
9 changed files with 16 additions and 13 deletions
|
@ -193,19 +193,22 @@ int IPv4Socket::allocate_local_port_if_needed()
|
|||
return port;
|
||||
}
|
||||
|
||||
KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const void* data, size_t data_length, int flags, const sockaddr* addr, socklen_t addr_length)
|
||||
KResultOr<size_t> IPv4Socket::sendto(FileDescription&, const void* data, size_t data_length, int flags, Userspace<const sockaddr*> addr, socklen_t addr_length)
|
||||
{
|
||||
(void)flags;
|
||||
if (addr && addr_length != sizeof(sockaddr_in))
|
||||
return KResult(-EINVAL);
|
||||
|
||||
if (addr) {
|
||||
if (addr->sa_family != AF_INET) {
|
||||
klog() << "sendto: Bad address family: " << addr->sa_family << " is not AF_INET!";
|
||||
sockaddr_in ia;
|
||||
if (!Process::current()->validate_read_and_copy_typed(&ia, Userspace<const sockaddr_in*>(addr.ptr())))
|
||||
return KResult(-EFAULT);
|
||||
|
||||
if (ia.sin_family != AF_INET) {
|
||||
klog() << "sendto: Bad address family: " << ia.sin_family << " is not AF_INET!";
|
||||
return KResult(-EAFNOSUPPORT);
|
||||
}
|
||||
|
||||
auto& ia = *(const sockaddr_in*)addr;
|
||||
m_peer_address = IPv4Address((const u8*)&ia.sin_addr.s_addr);
|
||||
m_peer_port = ntohs(ia.sin_port);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue