mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
IPv4: Add simple pseudorandom ephemeral port allocators for TCP and UDP.
This commit is contained in:
parent
77a782a67e
commit
c24d4b07db
8 changed files with 54 additions and 20 deletions
|
@ -112,11 +112,15 @@ bool IPv4Socket::can_write(SocketRole) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void IPv4Socket::allocate_source_port_if_needed()
|
||||
int IPv4Socket::allocate_source_port_if_needed()
|
||||
{
|
||||
if (m_source_port)
|
||||
return;
|
||||
protocol_allocate_source_port();
|
||||
return m_source_port;
|
||||
int port = protocol_allocate_source_port();
|
||||
if (port < 0)
|
||||
return port;
|
||||
m_source_port = (word)port;
|
||||
return port;
|
||||
}
|
||||
|
||||
ssize_t IPv4Socket::sendto(const void* data, size_t data_length, int flags, const sockaddr* addr, socklen_t addr_length)
|
||||
|
@ -142,7 +146,9 @@ ssize_t IPv4Socket::sendto(const void* data, size_t data_length, int flags, cons
|
|||
m_destination_port = ntohs(ia.sin_port);
|
||||
}
|
||||
|
||||
allocate_source_port_if_needed();
|
||||
int rc = allocate_source_port_if_needed();
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
kprintf("sendto: destination=%s:%u\n", m_destination_address.to_string().characters(), m_destination_port);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue