diff --git a/kernel/include/net/udp_layer.hpp b/kernel/include/net/udp_layer.hpp new file mode 100644 index 00000000..44c2e419 --- /dev/null +++ b/kernel/include/net/udp_layer.hpp @@ -0,0 +1,33 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// Distributed under the terms of the MIT License. +// (See accompanying file LICENSE or copy at +// http://www.opensource.org/licenses/MIT) +//======================================================================= + +#ifndef NET_UDP_LAYER_H +#define NET_UDP_LAYER_H + +#include + +#include "net/ethernet_layer.hpp" +#include "net/network.hpp" + +namespace network { + +namespace udp { + +struct header { + uint16_t source_port; + uint16_t target_port; + uint16_t length; + uint16_t checksum; +} __attribute__((packed)); + +void decode(network::interface_descriptor& interface, network::ethernet::packet& packet); + +} // end of upd namespace + +} // end of network namespace + +#endif diff --git a/kernel/src/net/udp_layer.cpp b/kernel/src/net/udp_layer.cpp new file mode 100644 index 00000000..7fa897f9 --- /dev/null +++ b/kernel/src/net/udp_layer.cpp @@ -0,0 +1,26 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// Distributed under the terms of the MIT License. +// (See accompanying file LICENSE or copy at +// http://www.opensource.org/licenses/MIT) +//======================================================================= + +#include "net/udp_layer.hpp" + +#include "kernel_utils.hpp" + +void network::udp::decode(network::interface_descriptor& interface, network::ethernet::packet& packet){ + packet.tag(2, packet.index); + + auto* udp_header = reinterpret_cast(packet.payload + packet.index); + + logging::logf(logging::log_level::TRACE, "udp: Start UDP packet handling\n"); + + auto source_port = switch_endian_16(udp_header->source_port); + auto target_port = switch_endian_16(udp_header->target_port); + auto length = switch_endian_16(udp_header->length); + + logging::logf(logging::log_level::TRACE, "udp: Source Port %h \n", source_port); + logging::logf(logging::log_level::TRACE, "udp: Target Port %h \n", target_port); + logging::logf(logging::log_level::TRACE, "udp: Length %h \n", length); +}