NetworkTask.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <Kernel/E1000NetworkAdapter.h>
  2. #include <Kernel/EthernetFrameHeader.h>
  3. #include <Kernel/ARPPacket.h>
  4. #include <Kernel/Process.h>
  5. void NetworkTask_main()
  6. {
  7. auto* e1000_ptr = E1000NetworkAdapter::the();
  8. ASSERT(e1000_ptr);
  9. auto& e1000 = *e1000_ptr;
  10. ARPPacket arp;
  11. arp.hardware_type = 1; // Ethernet
  12. arp.hardware_address_length = 6; // MAC length
  13. arp.protocol_type = 0x0800; // IPv4
  14. arp.protocol_address_length = 4; // IP length
  15. arp.operation = 1; // 1 (request)
  16. e1000.send(MACAddress(), arp);
  17. kprintf("NetworkTask: Enter main loop.\n");
  18. for (;;) {
  19. auto packet = e1000.dequeue_packet();
  20. if (packet.is_null()) {
  21. sleep(100);
  22. continue;
  23. }
  24. if (packet.size() < sizeof(EthernetFrameHeader) + 4) {
  25. kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%d)\n", packet.size());
  26. continue;
  27. }
  28. auto* eth = (const EthernetFrameHeader*)packet.pointer();
  29. kprintf("NetworkTask: Handle packet from %s to %s\n", eth->source().to_string().characters(), eth->destination().to_string().characters());
  30. }
  31. }