Review initialization of local ports

This commit is contained in:
Baptiste Wicht 2016-09-18 21:03:13 +02:00
parent 76b4264192
commit ad7a4f41cf
5 changed files with 17 additions and 10 deletions

View File

@ -19,6 +19,8 @@ namespace network {
namespace tcp {
void init_layer();
void decode(network::interface_descriptor& interface, network::ethernet::packet& packet);
//TODO The parameters should be set in a descriptor

View File

@ -25,6 +25,8 @@ struct header {
uint16_t checksum;
} __attribute__((packed));
void init_layer();
void decode(network::interface_descriptor& interface, network::ethernet::packet& packet);
std::expected<network::ethernet::packet> user_prepare_packet(char* buffer, network::socket& sock, const packet_descriptor* descriptor);

View File

@ -183,6 +183,11 @@ void network::init(){
}
}
}
// Initialize the necessary network layers
network::udp::init_layer();
network::tcp::init_layer();
}
void network::finalize(){

View File

@ -125,6 +125,10 @@ size_t tcp_payload_len(const network::ethernet::packet& packet){
} //end of anonymous namespace
void network::tcp::init_layer(){
local_port = 1023;
}
void network::tcp::decode(network::interface_descriptor& interface, network::ethernet::packet& packet) {
packet.tag(2, packet.index);
@ -360,11 +364,6 @@ std::expected<void> network::tcp::finalize_packet(network::interface_descriptor&
}
std::expected<size_t> network::tcp::connect(network::socket& sock, network::interface_descriptor& interface, size_t server_port, network::ip::address server) {
// TODO This is terrible
if(!local_port.load()){
local_port = 1024;
}
// Create the connection
auto& connection = connections.create_connection();

View File

@ -72,6 +72,10 @@ void prepare_packet(network::ethernet::packet& packet, size_t source, size_t tar
} //end of anonymous namespace
void network::udp::init_layer(){
local_port = 1023;
}
void network::udp::decode(network::interface_descriptor& interface, network::ethernet::packet& packet){
packet.tag(2, packet.index);
@ -146,11 +150,6 @@ std::expected<void> network::udp::finalize_packet(network::interface_descriptor&
}
std::expected<size_t> network::udp::client_bind(network::socket& sock, size_t server_port, network::ip::address server){
// TODO This is terrible
if(!local_port.load()){
local_port = 1024;
}
// Create the connection
auto& connection = connections.create_connection();