From fbb39988eb2616c42415db1e13b4c8dc9ac67c54 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Wed, 6 Jul 2016 21:54:19 +0200 Subject: [PATCH] IP Address utilities --- kernel/include/ip_layer.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 kernel/include/ip_layer.hpp diff --git a/kernel/include/ip_layer.hpp b/kernel/include/ip_layer.hpp new file mode 100644 index 00000000..2c617578 --- /dev/null +++ b/kernel/include/ip_layer.hpp @@ -0,0 +1,33 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#ifndef NET_IP_LAYER_H +#define NET_IP_LAYER_H + +#include + +namespace network { + +namespace ip { + +struct address { + uint32_t address = 0; + + uint8_t operator()(size_t index) const { + return (address >> ((3 - index) * 8)) & 0xFF; + } + + void set_sub(size_t index, uint8_t value){ + address |= uint32_t(value) << ((3 - index) * 8); + } +}; + +} // end of ip namespace + +} // end of network namespace + +#endif