1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:18:13 +00:00

IPv4: Save the source address/port together with incoming packet payloads.

We need the address/port to fill in the out-params in recvfrom().
It should now be more or less possible to create a UDP server. :^)
This commit is contained in:
Andreas Kling 2019-05-04 03:27:50 +02:00
parent c4bb9a3ccb
commit 780d2a08c4
6 changed files with 29 additions and 21 deletions

View file

@ -53,10 +53,6 @@ int UDPSocket::protocol_receive(const ByteBuffer& packet_buffer, void* buffer, s
auto& udp_packet = *static_cast<const UDPPacket*>(ipv4_packet.payload());
ASSERT(udp_packet.length() >= sizeof(UDPPacket)); // FIXME: This should be rejected earlier.
ASSERT(buffer_size >= (udp_packet.length() - sizeof(UDPPacket)));
if (addr) {
auto& ia = *(sockaddr_in*)addr;
ia.sin_port = htons(udp_packet.destination_port());
}
memcpy(buffer, udp_packet.payload(), udp_packet.length() - sizeof(UDPPacket));
return udp_packet.length() - sizeof(UDPPacket);
}