mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 07:48:47 +00:00
Kernel: Add a NetworkTask and a received network packet queue.
It will be easier to deal with incoming packets in a separate task.
This commit is contained in:
parent
47b096feb4
commit
35098cbde1
Notes:
sideshowbarker
2024-07-19 15:05:10 +09:00
Author: https://github.com/awesomekling
Commit: 35098cbde1
10 changed files with 90 additions and 11 deletions
33
Kernel/NetworkTask.cpp
Normal file
33
Kernel/NetworkTask.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <Kernel/E1000NetworkAdapter.h>
|
||||
#include <Kernel/EthernetFrameHeader.h>
|
||||
#include <Kernel/ARPPacket.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
void NetworkTask_main()
|
||||
{
|
||||
auto* e1000_ptr = E1000NetworkAdapter::the();
|
||||
ASSERT(e1000_ptr);
|
||||
auto& e1000 = *e1000_ptr;
|
||||
ARPPacket arp;
|
||||
arp.hardware_type = 1; // Ethernet
|
||||
arp.hardware_address_length = 6; // MAC length
|
||||
arp.protocol_type = 0x0800; // IPv4
|
||||
arp.protocol_address_length = 4; // IP length
|
||||
arp.operation = 1; // 1 (request)
|
||||
e1000.send(MACAddress(), arp);
|
||||
|
||||
kprintf("NetworkTask: Enter main loop.\n");
|
||||
for (;;) {
|
||||
auto packet = e1000.dequeue_packet();
|
||||
if (packet.is_null()) {
|
||||
sleep(100);
|
||||
continue;
|
||||
}
|
||||
if (packet.size() < sizeof(EthernetFrameHeader) + 4) {
|
||||
kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%d)\n", packet.size());
|
||||
continue;
|
||||
}
|
||||
auto* eth = (const EthernetFrameHeader*)packet.pointer();
|
||||
kprintf("NetworkTask: Handle packet from %s to %s\n", eth->source().to_string().characters(), eth->destination().to_string().characters());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue