mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-12 22:17:11 -04:00
Expose net structures to the tlib
This commit is contained in:
parent
30f558cddf
commit
7ea54ce2df
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <types.hpp>
|
#include <types.hpp>
|
||||||
|
|
||||||
|
#include "tlib/net_constants.hpp"
|
||||||
|
|
||||||
#include "net/network.hpp"
|
#include "net/network.hpp"
|
||||||
#include "net/ip_layer.hpp"
|
#include "net/ip_layer.hpp"
|
||||||
|
|
||||||
@ -31,25 +33,6 @@ struct echo_request_header {
|
|||||||
|
|
||||||
static_assert(sizeof(echo_request_header) == sizeof(header::rest), "Invalid size for echo request header");
|
static_assert(sizeof(echo_request_header) == sizeof(header::rest), "Invalid size for echo request header");
|
||||||
|
|
||||||
enum class type : uint8_t {
|
|
||||||
ECHO_REPLY = 0,
|
|
||||||
UNREACHABLE = 3,
|
|
||||||
SOURCE_QUENCH = 4,
|
|
||||||
REDICT = 5,
|
|
||||||
ECHO_REQUEST = 8,
|
|
||||||
ROUTER_ADVERTISEMENT = 9,
|
|
||||||
ROUTER_SOLICITATION = 10,
|
|
||||||
TIME_EXCEEDED = 11,
|
|
||||||
PARAMETER_PROBLEM = 12,
|
|
||||||
TIMESTAMP = 13,
|
|
||||||
TIMESTAMP_REPLY = 14,
|
|
||||||
INFORMATION_REQUEST = 15,
|
|
||||||
INFORMATION_REPLY = 16,
|
|
||||||
ADDRESS_MASK_REQUEST = 17,
|
|
||||||
ADDRESS_MASK_REPLY = 18,
|
|
||||||
TRACEROUTE = 30
|
|
||||||
};
|
|
||||||
|
|
||||||
void decode(network::interface_descriptor& interface, network::ethernet::packet& packet);
|
void decode(network::interface_descriptor& interface, network::ethernet::packet& packet);
|
||||||
|
|
||||||
network::ethernet::packet prepare_packet(network::interface_descriptor& interface, network::ip::address target_ip, size_t payload_size, type t, size_t code);
|
network::ethernet::packet prepare_packet(network::interface_descriptor& interface, network::ip::address target_ip, size_t payload_size, type t, size_t code);
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
//=======================================================================
|
|
||||||
// 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_ADDRESS_H
|
|
||||||
#define NET_IP_ADDRESS_H
|
|
||||||
|
|
||||||
#include <types.hpp>
|
|
||||||
|
|
||||||
namespace network {
|
|
||||||
|
|
||||||
namespace ip {
|
|
||||||
|
|
||||||
//TODO Maybe packed 4x8 is better
|
|
||||||
|
|
||||||
struct address {
|
|
||||||
uint32_t raw_address = 0;
|
|
||||||
|
|
||||||
address(){}
|
|
||||||
address(uint32_t raw) : raw_address(raw) {}
|
|
||||||
|
|
||||||
uint8_t operator()(size_t index) const {
|
|
||||||
return (raw_address >> ((3 - index) * 8)) & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_sub(size_t index, uint8_t value){
|
|
||||||
raw_address |= uint32_t(value) << ((3 - index) * 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const address& rhs) const {
|
|
||||||
return this->raw_address == rhs.raw_address;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
inline address make_address(uint8_t a, uint8_t b, uint8_t c, uint8_t d){
|
|
||||||
address addr;
|
|
||||||
addr.set_sub(0, a);
|
|
||||||
addr.set_sub(1, b);
|
|
||||||
addr.set_sub(2, c);
|
|
||||||
addr.set_sub(3, d);
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end of ip namespace
|
|
||||||
|
|
||||||
} // end of network namespace
|
|
||||||
|
|
||||||
#endif
|
|
@ -11,7 +11,7 @@
|
|||||||
#include <types.hpp>
|
#include <types.hpp>
|
||||||
|
|
||||||
#include "net/network.hpp"
|
#include "net/network.hpp"
|
||||||
#include "net/ip_address.hpp"
|
#include "tlib/net_constants.hpp"
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
#include <semaphore.hpp>
|
#include <semaphore.hpp>
|
||||||
#include <lock_guard.hpp>
|
#include <lock_guard.hpp>
|
||||||
|
|
||||||
|
#include "tlib/net_constants.hpp"
|
||||||
|
|
||||||
#include "net/ethernet_packet.hpp"
|
#include "net/ethernet_packet.hpp"
|
||||||
#include "net/ip_address.hpp"
|
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
|
@ -14,6 +14,61 @@
|
|||||||
|
|
||||||
THOR_NAMESPACE(tlib, network) {
|
THOR_NAMESPACE(tlib, network) {
|
||||||
|
|
||||||
|
namespace ip {
|
||||||
|
|
||||||
|
struct address {
|
||||||
|
uint32_t raw_address = 0;
|
||||||
|
|
||||||
|
address(){}
|
||||||
|
address(uint32_t raw) : raw_address(raw) {}
|
||||||
|
|
||||||
|
uint8_t operator()(size_t index) const {
|
||||||
|
return (raw_address >> ((3 - index) * 8)) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_sub(size_t index, uint8_t value){
|
||||||
|
raw_address |= uint32_t(value) << ((3 - index) * 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const address& rhs) const {
|
||||||
|
return this->raw_address == rhs.raw_address;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline address make_address(uint8_t a, uint8_t b, uint8_t c, uint8_t d){
|
||||||
|
address addr;
|
||||||
|
addr.set_sub(0, a);
|
||||||
|
addr.set_sub(1, b);
|
||||||
|
addr.set_sub(2, c);
|
||||||
|
addr.set_sub(3, d);
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of namespace ip
|
||||||
|
|
||||||
|
namespace icmp {
|
||||||
|
|
||||||
|
enum class type : uint8_t {
|
||||||
|
ECHO_REPLY = 0,
|
||||||
|
UNREACHABLE = 3,
|
||||||
|
SOURCE_QUENCH = 4,
|
||||||
|
REDICT = 5,
|
||||||
|
ECHO_REQUEST = 8,
|
||||||
|
ROUTER_ADVERTISEMENT = 9,
|
||||||
|
ROUTER_SOLICITATION = 10,
|
||||||
|
TIME_EXCEEDED = 11,
|
||||||
|
PARAMETER_PROBLEM = 12,
|
||||||
|
TIMESTAMP = 13,
|
||||||
|
TIMESTAMP_REPLY = 14,
|
||||||
|
INFORMATION_REQUEST = 15,
|
||||||
|
INFORMATION_REPLY = 16,
|
||||||
|
ADDRESS_MASK_REQUEST = 17,
|
||||||
|
ADDRESS_MASK_REPLY = 18,
|
||||||
|
TRACEROUTE = 30
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end of namespace icmp
|
||||||
|
|
||||||
enum class socket_domain : size_t {
|
enum class socket_domain : size_t {
|
||||||
AF_INET
|
AF_INET
|
||||||
};
|
};
|
||||||
@ -26,6 +81,13 @@ enum class socket_protocol : size_t {
|
|||||||
ICMP
|
ICMP
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct icmp_packet_descriptor {
|
||||||
|
size_t payload_size;
|
||||||
|
ip::address target_ip;
|
||||||
|
icmp::type type;
|
||||||
|
size_t code;
|
||||||
|
};
|
||||||
|
|
||||||
} // end of network namespace
|
} // end of network namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user