1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +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

@ -32,7 +32,7 @@ public:
virtual ssize_t sendto(FileDescriptor&, const void*, size_t, int, const sockaddr*, socklen_t) override;
virtual ssize_t recvfrom(FileDescriptor&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
void did_receive(ByteBuffer&&);
void did_receive(const IPv4Address& source_address, word source_port, ByteBuffer&&);
const IPv4Address& source_address() const;
word source_port() const { return m_source_port; }
@ -67,7 +67,13 @@ private:
DoubleBuffer m_for_client;
DoubleBuffer m_for_server;
SinglyLinkedList<ByteBuffer> m_receive_queue;
struct ReceivedPacket {
IPv4Address source_address;
word source_port;
ByteBuffer data;
};
SinglyLinkedList<ReceivedPacket> m_receive_queue;
word m_source_port { 0 };
word m_destination_port { 0 };