Prepare UDP support

This commit is contained in:
Baptiste Wicht 2016-09-10 20:40:41 +02:00
parent e0dc61693e
commit 9b064fe6b9
2 changed files with 59 additions and 0 deletions

View 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

View 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);
}