mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-12 22:17:11 -04:00
Prepare UDP support
This commit is contained in:
parent
e0dc61693e
commit
9b064fe6b9
33
kernel/include/net/udp_layer.hpp
Normal file
33
kernel/include/net/udp_layer.hpp
Normal file
@ -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 <types.hpp>
|
||||
|
||||
#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
|
26
kernel/src/net/udp_layer.cpp
Normal file
26
kernel/src/net/udp_layer.cpp
Normal file
@ -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<header*>(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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user