12using namespace MaxOS::net;
13using namespace MaxOS::common;
14using namespace MaxOS::memory;
20UDPPayloadHandler::~UDPPayloadHandler() =
default;
41 switch (
event -> type) {
42 case UDPEvents::DATA_RECEIVED:
64UDPSocket::~UDPSocket() =
default;
118UserDatagramProtocolHandler::~UserDatagramProtocolHandler() =
default;
140 uint16_t local_port = header -> destination_port;
141 uint16_t remote_port = header -> source_port;
165 if(socket !=
nullptr) {
186 if(socket !=
nullptr)
191 socket -> remote_port =
port;
192 socket -> remote_ip =
ip;
195 socket -> user_datagram_protocol_handler =
this;
226 if(socket !=
nullptr)
231 socket -> listening =
true;
232 socket -> local_port =
port;
234 socket -> user_datagram_protocol_handler =
this;
278 header -> source_port = socket -> local_port;
279 header -> destination_port = socket -> remote_port;
283 header -> source_port = ((header -> source_port & 0x00FF) << 8) | ((header -> source_port & 0xFF00) >> 8);
284 header -> destination_port = ((header -> destination_port & 0x00FF) << 8) | ((header -> destination_port & 0xFF00) >> 8);
287 for (
int i = 0; i < size; ++i) {
292 header -> checksum = 0;
331UDPDataReceivedEvent::~UDPDataReceivedEvent() =
default;
Vector< Event< UDPEvents > * > raise_event(Event< UDPEvents > *event)
Calls the on_event function of all the event m_handlers connected to the event manager and returns a ...
Vector< EventHandler< EventType > * > m_handlers
Used to store information about an event, has a type and a return value.
A stream that strings can be written to.
Stores the left, top, width and height of a rectangle.
static void * kmalloc(size_t size)
Allocates a block of memory in the KERNEL space.
static void kfree(void *pointer)
Frees a block of memory using the kernel memory manager.
Handles the payload of a specific IP protocol.
void send(InternetProtocolAddress destination_ip, uint8_t *payload_data, uint32_t size)
Sends an IP packet.
InternetProtocolHandler * internet_protocol_handler
The Internet protocol handler this payload handler is connected to.
Handles IPv4 packets over Ethernet frames.
InternetProtocolAddress get_internet_protocol_address() const
Gets the IP address of this device.
Event fired when data is received on a UDP socket.
UDPDataReceivedEvent(UDPSocket *socket, uint8_t *data, uint16_t size)
Construct a new UDP Data Received Event object.
UDPSocket * socket
The socket that received the data.
uint16_t size
The size of the data received.
uint8_t * data
The data received.
Handles the payload of a UDP packet.
UDPPayloadHandler()
Handler
common::Event< UDPEvents > * on_event(common::Event< UDPEvents > *event) override
Event handler for UDP payload events.
virtual void handle_user_datagram_protocol_message(UDPSocket *socket, uint8_t *data, uint16_t size)
Handle the recivement of a UDP message.
uint32_t remote_ip
The IP of the remote device.
uint16_t remote_port
The port on the remote device.
virtual void disconnect()
disconnect the UDP socket
UserDatagramProtocolHandler * user_datagram_protocol_handler
The UDP handler this socket is connected to.
virtual void send(uint8_t *data, uint16_t size)
send data through the UDP socket
bool listening
Wether the port is waiting for incoming connections.
virtual void handle_user_datagram_protocol_payload(uint8_t *data, uint16_t size)
Handle the recivement of a UDP payload.
UserDatagramProtocolHandler(InternetProtocolHandler *internet_protocol_handler, common::OutputStream *error_messages)
Construct a new User Datagram Protocol Handler object.
static UserDatagramProtocolPort free_ports
The next free port number.
void disconnect(UDPSocket *socket)
Disconnects the socket from the remote IP and port.
UDPSocket * connect(uint32_t ip, uint16_t port)
common::Vector< UDPSocket * > sockets
The list of UDP sockets.
UDPSocket * listen(uint16_t port)
Listens for incoming packets on the port.
static void bind(UDPSocket *socket, UDPPayloadHandler *udp_payload_handler)
Binds a handler to the socket.
bool handle_internet_protocol_payload(net::InternetProtocolAddress source_ip, net::InternetProtocolAddress destination_ip, uint8_t *payload_data, uint32_t size) override
Handle the recivement of an UDP packet.
common::OutputStream * errorMessages
Where to write error messages.
void send(UDPSocket *socket, const uint8_t *data, uint16_t size)
Sends a packet to the remote IP and port.
uint32_t InternetProtocolAddress
An IPv4 address.
Defines the User Datagram Protocol (UDP) for network communication.
UDPEvents
The events that can be fired by the UDP protocol.