diff --git a/Kernel/ARPPacket.h b/Kernel/ARP.h similarity index 98% rename from Kernel/ARPPacket.h rename to Kernel/ARP.h index 23f44ccb4c..934995d440 100644 --- a/Kernel/ARPPacket.h +++ b/Kernel/ARP.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include struct ARPOperation { diff --git a/Kernel/ICMP.h b/Kernel/ICMP.h index 2660b93d52..c8dc818195 100644 --- a/Kernel/ICMP.h +++ b/Kernel/ICMP.h @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include struct ICMPType { enum { diff --git a/Kernel/IPv4Packet.h b/Kernel/IPv4.h similarity index 67% rename from Kernel/IPv4Packet.h rename to Kernel/IPv4.h index 97dd1453a0..9b70764f85 100644 --- a/Kernel/IPv4Packet.h +++ b/Kernel/IPv4.h @@ -1,8 +1,10 @@ #pragma once +#include +#include #include -#include #include +#include enum class IPv4Protocol : word { ICMP = 1, @@ -12,6 +14,55 @@ enum class IPv4Protocol : word { NetworkOrdered internet_checksum(const void*, size_t); +class [[gnu::packed]] IPv4Address { +public: + IPv4Address() { } + IPv4Address(const byte data[4]) + { + memcpy(m_data, data, 4); + } + IPv4Address(byte a, byte b, byte c, byte d) + { + m_data[0] = a; + m_data[1] = b; + m_data[2] = c; + m_data[3] = d; + } + ~IPv4Address() { } + + byte operator[](int i) const + { + ASSERT(i >= 0 && i < 4); + return m_data[i]; + } + + String to_string() const + { + return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]); + } + + bool operator==(const IPv4Address& other) const { return m_data_as_dword == other.m_data_as_dword; } + bool operator!=(const IPv4Address& other) const { return m_data_as_dword != other.m_data_as_dword; } + +private: + union { + byte m_data[4]; + dword m_data_as_dword; + }; +}; + +static_assert(sizeof(IPv4Address) == 4); + +namespace AK { + +template<> +struct Traits { + static unsigned hash(const IPv4Address& address) { return string_hash((const char*)&address, sizeof(address)); } + static void dump(const IPv4Address& address) { kprintf("%s", address.to_string().characters()); } +}; + +} + class [[gnu::packed]] IPv4Packet { public: byte version() const { return (m_version_and_ihl >> 4) & 0xf; } diff --git a/Kernel/IPv4Address.h b/Kernel/IPv4Address.h deleted file mode 100644 index 46431cd9c1..0000000000 --- a/Kernel/IPv4Address.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class [[gnu::packed]] IPv4Address { -public: - IPv4Address() { } - IPv4Address(const byte data[4]) - { - memcpy(m_data, data, 4); - } - IPv4Address(byte a, byte b, byte c, byte d) - { - m_data[0] = a; - m_data[1] = b; - m_data[2] = c; - m_data[3] = d; - } - ~IPv4Address() { } - - byte operator[](int i) const - { - ASSERT(i >= 0 && i < 4); - return m_data[i]; - } - - String to_string() const - { - return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]); - } - - bool operator==(const IPv4Address& other) const { return m_data_as_dword == other.m_data_as_dword; } - bool operator!=(const IPv4Address& other) const { return m_data_as_dword != other.m_data_as_dword; } - -private: - union { - byte m_data[4]; - dword m_data_as_dword; - }; -}; - -static_assert(sizeof(IPv4Address) == 4); - -namespace AK { - -template<> -struct Traits { - static unsigned hash(const IPv4Address& address) { return string_hash((const char*)&address, sizeof(address)); } - static void dump(const IPv4Address& address) { kprintf("%s", address.to_string().characters()); } -}; - -} diff --git a/Kernel/NetworkAdapter.h b/Kernel/NetworkAdapter.h index bb1181abca..24b8c32821 100644 --- a/Kernel/NetworkAdapter.h +++ b/Kernel/NetworkAdapter.h @@ -4,9 +4,8 @@ #include #include #include -#include -#include -#include +#include +#include #include class NetworkAdapter { diff --git a/Kernel/NetworkTask.cpp b/Kernel/NetworkTask.cpp index 73416b4c38..616c949524 100644 --- a/Kernel/NetworkTask.cpp +++ b/Kernel/NetworkTask.cpp @@ -1,8 +1,8 @@ #include #include -#include +#include #include -#include +#include #include #include #include @@ -33,7 +33,7 @@ void NetworkTask_main() for (;;) { auto packet = e1000.dequeue_packet(); if (packet.is_null()) { - sleep(100); + sleep(1); continue; } if (packet.size() < (int)(sizeof(EthernetFrameHeader))) { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 2d09825b37..00cf2746d5 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include //#define DEBUG_IO //#define TASK_DEBUG