Prepare packet receiving in user mode

This commit is contained in:
Baptiste Wicht 2016-09-04 22:08:30 +02:00
parent 5a051b234c
commit 9e1aebc44d
2 changed files with 22 additions and 1 deletions

View File

@ -12,6 +12,7 @@
#include "logging.hpp"
#include "kernel_utils.hpp"
#include "scheduler.hpp"
namespace {
@ -75,6 +76,20 @@ void network::icmp::decode(network::interface_descriptor& /*interface*/, network
logging::logf(logging::log_level::TRACE, "icmp: Unsupported ICMP packet received (type:%u)\n", uint64_t(icmp_header->type));
break;
}
// TODO Need something better for this
for(size_t pid = 0; pid < scheduler::MAX_PROCESS; ++pid){
auto state = scheduler::get_process_state(pid);
if(state != scheduler::process_state::EMPTY && state != scheduler::process_state::NEW && state != scheduler::process_state::KILLED){
for(auto& socket : scheduler::get_sockets(pid)){
if(socket.listen && socket.protocol == network::socket_protocol::ICMP){
socket.listen_packets.push(packet);
socket.listen_queue.wake_up();
}
}
}
}
}
network::ethernet::packet network::icmp::prepare_packet(network::interface_descriptor& interface, network::ip::address target_ip, size_t payload_size, type t, size_t code){

View File

@ -71,7 +71,13 @@ int main(int argc, char* argv[]) {
return 1;
}
//TODO Wait for replies
auto* icmp_header = reinterpret_cast<tlib::icmp::header*>(p->payload + p->index);
auto command_type = static_cast<tlib::icmp::type>(icmp_header->type);
if(command_type == tlib::icmp::type::ECHO_REPLY){
tlib::printf("reply received from %s\n", ip.c_str());
}
status = tlib::listen(*socket, false);
if (!status) {