diff options
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/ARP.h | 34 | ||||
-rw-r--r-- | Kernel/Net/E1000NetworkAdapter.cpp | 68 | ||||
-rw-r--r-- | Kernel/Net/E1000NetworkAdapter.h | 26 | ||||
-rw-r--r-- | Kernel/Net/EtherType.h | 2 | ||||
-rw-r--r-- | Kernel/Net/EthernetFrameHeader.h | 8 | ||||
-rw-r--r-- | Kernel/Net/ICMP.h | 22 | ||||
-rw-r--r-- | Kernel/Net/IPv4.h | 58 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 14 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.h | 22 | ||||
-rw-r--r-- | Kernel/Net/LocalSocket.cpp | 8 | ||||
-rw-r--r-- | Kernel/Net/LocalSocket.h | 4 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/LoopbackAdapter.h | 2 | ||||
-rw-r--r-- | Kernel/Net/MACAddress.h | 6 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 8 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 4 | ||||
-rw-r--r-- | Kernel/Net/NetworkTask.cpp | 4 | ||||
-rw-r--r-- | Kernel/Net/Socket.h | 2 | ||||
-rw-r--r-- | Kernel/Net/TCP.h | 62 | ||||
-rw-r--r-- | Kernel/Net/TCPSocket.cpp | 48 | ||||
-rw-r--r-- | Kernel/Net/TCPSocket.h | 20 | ||||
-rw-r--r-- | Kernel/Net/UDP.h | 24 | ||||
-rw-r--r-- | Kernel/Net/UDPSocket.cpp | 18 | ||||
-rw-r--r-- | Kernel/Net/UDPSocket.h | 4 |
24 files changed, 235 insertions, 235 deletions
diff --git a/Kernel/Net/ARP.h b/Kernel/Net/ARP.h index 6f3a3cb0ab..da03222e79 100644 --- a/Kernel/Net/ARP.h +++ b/Kernel/Net/ARP.h @@ -6,14 +6,14 @@ #include <Kernel/Net/MACAddress.h> struct ARPOperation { - enum : word { + enum : u16 { Request = 1, Response = 2, }; }; struct ARPHardwareType { - enum : word { + enum : u16 { Ethernet = 1, }; }; @@ -21,20 +21,20 @@ struct ARPHardwareType { class [[gnu::packed]] ARPPacket { public: - word hardware_type() const { return m_hardware_type; } - void set_hardware_type(word w) { m_hardware_type = w; } + u16 hardware_type() const { return m_hardware_type; } + void set_hardware_type(u16 w) { m_hardware_type = w; } - word protocol_type() const { return m_protocol_type; } - void set_protocol_type(word w) { m_protocol_type = w; } + u16 protocol_type() const { return m_protocol_type; } + void set_protocol_type(u16 w) { m_protocol_type = w; } - byte hardware_address_length() const { return m_hardware_address_length; } - void set_hardware_address_length(byte b) { m_hardware_address_length = b; } + u8 hardware_address_length() const { return m_hardware_address_length; } + void set_hardware_address_length(u8 b) { m_hardware_address_length = b; } - byte protocol_address_length() const { return m_protocol_address_length; } - void set_protocol_address_length(byte b) { m_protocol_address_length = b; } + u8 protocol_address_length() const { return m_protocol_address_length; } + void set_protocol_address_length(u8 b) { m_protocol_address_length = b; } - word operation() const { return m_operation; } - void set_operation(word w) { m_operation = w; } + u16 operation() const { return m_operation; } + void set_operation(u16 w) { m_operation = w; } const MACAddress& sender_hardware_address() const { return m_sender_hardware_address; } void set_sender_hardware_address(const MACAddress& address) { m_sender_hardware_address = address; } @@ -49,11 +49,11 @@ public: void set_target_protocol_address(const IPv4Address& address) { m_target_protocol_address = address; } private: - NetworkOrdered<word> m_hardware_type { ARPHardwareType::Ethernet }; - NetworkOrdered<word> m_protocol_type { EtherType::IPv4 }; - byte m_hardware_address_length { sizeof(MACAddress) }; - byte m_protocol_address_length { sizeof(IPv4Address) }; - NetworkOrdered<word> m_operation; + NetworkOrdered<u16> m_hardware_type { ARPHardwareType::Ethernet }; + NetworkOrdered<u16> m_protocol_type { EtherType::IPv4 }; + u8 m_hardware_address_length { sizeof(MACAddress) }; + u8 m_protocol_address_length { sizeof(IPv4Address) }; + NetworkOrdered<u16> m_operation; MACAddress m_sender_hardware_address; IPv4Address m_sender_protocol_address; MACAddress m_target_hardware_address; diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index 356b1c5f50..3ceb0d7e0e 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -92,7 +92,7 @@ OwnPtr<E1000NetworkAdapter> E1000NetworkAdapter::autodetect() }); if (found_address.is_null()) return nullptr; - byte irq = PCI::get_interrupt_line(found_address); + u8 irq = PCI::get_interrupt_line(found_address); return make<E1000NetworkAdapter>(found_address, irq); } @@ -102,7 +102,7 @@ E1000NetworkAdapter* E1000NetworkAdapter::the() return s_the; } -E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, byte irq) +E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, u8 irq) : IRQHandler(irq) , m_pci_address(pci_address) { @@ -132,7 +132,7 @@ E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, byte irq) const auto& mac = mac_address(); kprintf("E1000: MAC address: %b:%b:%b:%b:%b:%b\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - dword flags = in32(REG_CTRL); + u32 flags = in32(REG_CTRL); out32(REG_CTRL, flags | ECTRL_SLU); initialize_rx_descriptors(); @@ -153,9 +153,9 @@ void E1000NetworkAdapter::handle_irq() { out32(REG_IMASK, 0x1); - dword status = in32(0xc0); + u32 status = in32(0xc0); if (status & 4) { - dword flags = in32(REG_CTRL); + u32 flags = in32(REG_CTRL); out32(REG_CTRL, flags | ECTRL_SLU); } if (status & 0x10) { @@ -170,7 +170,7 @@ void E1000NetworkAdapter::detect_eeprom() { out32(REG_EEPROM, 0x1); for (volatile int i = 0; i < 999; ++i) { - dword data = in32(REG_EEPROM); + u32 data = in32(REG_EEPROM); if (data & 0x10) { m_has_eeprom = true; return; @@ -179,16 +179,16 @@ void E1000NetworkAdapter::detect_eeprom() m_has_eeprom = false; } -dword E1000NetworkAdapter::read_eeprom(byte address) +u32 E1000NetworkAdapter::read_eeprom(u8 address) { - word data = 0; - dword tmp = 0; + u16 data = 0; + u32 tmp = 0; if (m_has_eeprom) { - out32(REG_EEPROM, ((dword)address << 8) | 1); + out32(REG_EEPROM, ((u32)address << 8) | 1); while (!((tmp = in32(REG_EEPROM)) & (1 << 4))) ; } else { - out32(REG_EEPROM, ((dword)address << 2) | 1); + out32(REG_EEPROM, ((u32)address << 2) | 1); while (!((tmp = in32(REG_EEPROM)) & (1 << 1))) ; } @@ -199,8 +199,8 @@ dword E1000NetworkAdapter::read_eeprom(byte address) void E1000NetworkAdapter::read_mac_address() { if (m_has_eeprom) { - byte mac[6]; - dword tmp = read_eeprom(0); + u8 mac[6]; + u32 tmp = read_eeprom(0); mac[0] = tmp & 0xff; mac[1] = tmp >> 8; tmp = read_eeprom(1); @@ -217,14 +217,14 @@ void E1000NetworkAdapter::read_mac_address() void E1000NetworkAdapter::initialize_rx_descriptors() { - auto ptr = (dword)kmalloc_eternal(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16); + auto ptr = (u32)kmalloc_eternal(sizeof(e1000_rx_desc) * number_of_rx_descriptors + 16); // Make sure it's 16-byte aligned. if (ptr % 16) ptr = (ptr + 16) - (ptr % 16); m_rx_descriptors = (e1000_rx_desc*)ptr; for (int i = 0; i < number_of_rx_descriptors; ++i) { auto& descriptor = m_rx_descriptors[i]; - descriptor.addr = (qword)kmalloc_eternal(8192 + 16); + descriptor.addr = (u64)kmalloc_eternal(8192 + 16); descriptor.status = 0; } @@ -239,14 +239,14 @@ void E1000NetworkAdapter::initialize_rx_descriptors() void E1000NetworkAdapter::initialize_tx_descriptors() { - auto ptr = (dword)kmalloc_eternal(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16); + auto ptr = (u32)kmalloc_eternal(sizeof(e1000_tx_desc) * number_of_tx_descriptors + 16); // Make sure it's 16-byte aligned. if (ptr % 16) ptr = (ptr + 16) - (ptr % 16); m_tx_descriptors = (e1000_tx_desc*)ptr; for (int i = 0; i < number_of_tx_descriptors; ++i) { auto& descriptor = m_tx_descriptors[i]; - descriptor.addr = (qword)kmalloc_eternal(8192 + 16); + descriptor.addr = (u64)kmalloc_eternal(8192 + 16); descriptor.cmd = 0; } @@ -260,60 +260,60 @@ void E1000NetworkAdapter::initialize_tx_descriptors() out32(REG_TIPG, 0x0060200A); } -void E1000NetworkAdapter::out8(word address, byte data) +void E1000NetworkAdapter::out8(u16 address, u8 data) { if (m_use_mmio) { - auto* ptr = (volatile byte*)(m_mmio_base.get() + address); + auto* ptr = (volatile u8*)(m_mmio_base.get() + address); *ptr = data; return; } IO::out8(m_io_base + address, data); } -void E1000NetworkAdapter::out16(word address, word data) +void E1000NetworkAdapter::out16(u16 address, u16 data) { if (m_use_mmio) { - auto* ptr = (volatile word*)(m_mmio_base.get() + address); + auto* ptr = (volatile u16*)(m_mmio_base.get() + address); *ptr = data; return; } IO::out16(m_io_base + address, data); } -void E1000NetworkAdapter::out32(word address, dword data) +void E1000NetworkAdapter::out32(u16 address, u32 data) { if (m_use_mmio) { - auto* ptr = (volatile dword*)(m_mmio_base.get() + address); + auto* ptr = (volatile u32*)(m_mmio_base.get() + address); *ptr = data; return; } IO::out32(m_io_base + address, data); } -byte E1000NetworkAdapter::in8(word address) +u8 E1000NetworkAdapter::in8(u16 address) { if (m_use_mmio) - return *(volatile byte*)(m_mmio_base.get() + address); + return *(volatile u8*)(m_mmio_base.get() + address); return IO::in8(m_io_base + address); } -word E1000NetworkAdapter::in16(word address) +u16 E1000NetworkAdapter::in16(u16 address) { if (m_use_mmio) - return *(volatile word*)(m_mmio_base.get() + address); + return *(volatile u16*)(m_mmio_base.get() + address); return IO::in16(m_io_base + address); } -dword E1000NetworkAdapter::in32(word address) +u32 E1000NetworkAdapter::in32(u16 address) { if (m_use_mmio) - return *(volatile dword*)(m_mmio_base.get() + address); + return *(volatile u32*)(m_mmio_base.get() + address); return IO::in32(m_io_base + address); } -void E1000NetworkAdapter::send_raw(const byte* data, int length) +void E1000NetworkAdapter::send_raw(const u8* data, int length) { - dword tx_current = in32(REG_TXDESCTAIL); + u32 tx_current = in32(REG_TXDESCTAIL); #ifdef E1000_DEBUG kprintf("E1000: Sending packet (%d bytes)\n", length); #endif @@ -337,7 +337,7 @@ void E1000NetworkAdapter::send_raw(const byte* data, int length) void E1000NetworkAdapter::receive() { - dword rx_current; + u32 rx_current; for (;;) { rx_current = in32(REG_RXDESCTAIL); if (rx_current == in32(REG_RXDESCHEAD)) @@ -345,8 +345,8 @@ void E1000NetworkAdapter::receive() rx_current = (rx_current + 1) % number_of_rx_descriptors; if (!(m_rx_descriptors[rx_current].status & 1)) break; - auto* buffer = (byte*)m_rx_descriptors[rx_current].addr; - word length = m_rx_descriptors[rx_current].length; + auto* buffer = (u8*)m_rx_descriptors[rx_current].addr; + u16 length = m_rx_descriptors[rx_current].length; #ifdef E1000_DEBUG kprintf("E1000: Received 1 packet @ %p (%u) bytes!\n", buffer, length); #endif diff --git a/Kernel/Net/E1000NetworkAdapter.h b/Kernel/Net/E1000NetworkAdapter.h index e2050853d5..c2eec037b4 100644 --- a/Kernel/Net/E1000NetworkAdapter.h +++ b/Kernel/Net/E1000NetworkAdapter.h @@ -13,10 +13,10 @@ public: static OwnPtr<E1000NetworkAdapter> autodetect(); - E1000NetworkAdapter(PCI::Address, byte irq); + E1000NetworkAdapter(PCI::Address, u8 irq); virtual ~E1000NetworkAdapter() override; - virtual void send_raw(const byte*, int) override; + virtual void send_raw(const u8*, int) override; private: virtual void handle_irq() override; @@ -44,28 +44,28 @@ private: }; void detect_eeprom(); - dword read_eeprom(byte address); + u32 read_eeprom(u8 address); void read_mac_address(); - void write_command(word address, dword); - dword read_command(word address); + void write_command(u16 address, u32); + u32 read_command(u16 address); void initialize_rx_descriptors(); void initialize_tx_descriptors(); - void out8(word address, byte); - void out16(word address, word); - void out32(word address, dword); - byte in8(word address); - word in16(word address); - dword in32(word address); + void out8(u16 address, u8); + void out16(u16 address, u16); + void out32(u16 address, u32); + u8 in8(u16 address); + u16 in16(u16 address); + u32 in32(u16 address); void receive(); PCI::Address m_pci_address; - word m_io_base { 0 }; + u16 m_io_base { 0 }; PhysicalAddress m_mmio_base; - byte m_interrupt_line { 0 }; + u8 m_interrupt_line { 0 }; bool m_has_eeprom { false }; bool m_use_mmio { false }; diff --git a/Kernel/Net/EtherType.h b/Kernel/Net/EtherType.h index ae845d5bf5..9f9c8382bc 100644 --- a/Kernel/Net/EtherType.h +++ b/Kernel/Net/EtherType.h @@ -3,7 +3,7 @@ #include <AK/Types.h> struct EtherType { - enum : word { + enum : u16 { ARP = 0x0806, IPv4 = 0x0800, }; diff --git a/Kernel/Net/EthernetFrameHeader.h b/Kernel/Net/EthernetFrameHeader.h index 137285230e..c42aee8649 100644 --- a/Kernel/Net/EthernetFrameHeader.h +++ b/Kernel/Net/EthernetFrameHeader.h @@ -15,8 +15,8 @@ public: MACAddress source() const { return m_source; } void set_source(const MACAddress& address) { m_source = address; } - word ether_type() const { return m_ether_type; } - void set_ether_type(word ether_type) { m_ether_type = ether_type; } + u16 ether_type() const { return m_ether_type; } + void set_ether_type(u16 ether_type) { m_ether_type = ether_type; } const void* payload() const { return &m_payload[0]; } void* payload() { return &m_payload[0]; } @@ -24,8 +24,8 @@ public: private: MACAddress m_destination; MACAddress m_source; - NetworkOrdered<word> m_ether_type; - dword m_payload[0]; + NetworkOrdered<u16> m_ether_type; + u32 m_payload[0]; }; static_assert(sizeof(EthernetFrameHeader) == 14); diff --git a/Kernel/Net/ICMP.h b/Kernel/Net/ICMP.h index 40bb691181..633c8847d2 100644 --- a/Kernel/Net/ICMP.h +++ b/Kernel/Net/ICMP.h @@ -16,22 +16,22 @@ public: ICMPHeader() {} ~ICMPHeader() {} - byte type() const { return m_type; } - void set_type(byte b) { m_type = b; } + u8 type() const { return m_type; } + void set_type(u8 b) { m_type = b; } - byte code() const { return m_code; } - void set_code(byte b) { m_code = b; } + u8 code() const { return m_code; } + void set_code(u8 b) { m_code = b; } - word checksum() const { return m_checksum; } - void set_checksum(word w) { m_checksum = w; } + u16 checksum() const { return m_checksum; } + void set_checksum(u16 w) { m_checksum = w; } const void* payload() const { return this + 1; } void* payload() { return this + 1; } private: - byte m_type { 0 }; - byte m_code { 0 }; - NetworkOrdered<word> m_checksum { 0 }; + u8 m_type { 0 }; + u8 m_code { 0 }; + NetworkOrdered<u16> m_checksum { 0 }; // NOTE: The rest of the header is 4 bytes }; @@ -40,8 +40,8 @@ static_assert(sizeof(ICMPHeader) == 4); struct [[gnu::packed]] ICMPEchoPacket { ICMPHeader header; - NetworkOrdered<word> identifier; - NetworkOrdered<word> sequence_number; + NetworkOrdered<u16> identifier; + NetworkOrdered<u16> sequence_number; void* payload() { return this + 1; } const void* payload() const { return this + 1; } }; diff --git a/Kernel/Net/IPv4.h b/Kernel/Net/IPv4.h index aa802df6cb..827435e470 100644 --- a/Kernel/Net/IPv4.h +++ b/Kernel/Net/IPv4.h @@ -6,37 +6,37 @@ #include <AK/NetworkOrdered.h> #include <AK/Types.h> -enum class IPv4Protocol : word { +enum class IPv4Protocol : u16 { ICMP = 1, TCP = 6, UDP = 17, }; -NetworkOrdered<word> internet_checksum(const void*, size_t); +NetworkOrdered<u16> internet_checksum(const void*, size_t); class [[gnu::packed]] IPv4Packet { public: - byte version() const { return (m_version_and_ihl >> 4) & 0xf; } - void set_version(byte version) { m_version_and_ihl = (m_version_and_ihl & 0x0f) | (version << 4); } + u8 version() const { return (m_version_and_ihl >> 4) & 0xf; } + void set_version(u8 version) { m_version_and_ihl = (m_version_and_ihl & 0x0f) | (version << 4); } - byte internet_header_length() const { return m_version_and_ihl & 0xf; } - void set_internet_header_length(byte ihl) { m_version_and_ihl = (m_version_and_ihl & 0xf0) | (ihl & 0x0f); } + u8 internet_header_length() const { return m_version_and_ihl & 0xf; } + void set_internet_header_length(u8 ihl) { m_version_and_ihl = (m_version_and_ihl & 0xf0) | (ihl & 0x0f); } - word length() const { return m_length; } - void set_length(word length) { m_length = length; } + u16 length() const { return m_length; } + void set_length(u16 length) { m_length = length; } - word ident() const { return m_ident; } - void set_ident(word ident) { m_ident = ident; } + u16 ident() const { return m_ident; } + void set_ident(u16 ident) { m_ident = ident; } - byte ttl() const { return m_ttl; } - void set_ttl(byte ttl) { m_ttl = ttl; } + u8 ttl() const { return m_ttl; } + void set_ttl(u8 ttl) { m_ttl = ttl; } - byte protocol() const { return m_protocol; } - void set_protocol(byte protocol) { m_protocol = protocol; } + u8 protocol() const { return m_protocol; } + void set_protocol(u8 protocol) { m_protocol = protocol; } - word checksum() const { return m_checksum; } - void set_checksum(word checksum) { m_checksum = checksum; } + u16 checksum() const { return m_checksum; } + void set_checksum(u16 checksum) { m_checksum = checksum; } const IPv4Address& source() const { return m_source; } void set_source(const IPv4Address& address) { m_source = address; } @@ -47,33 +47,33 @@ public: void* payload() { return this + 1; } const void* payload() const { return this + 1; } - word payload_size() const { return m_length - sizeof(IPv4Packet); } + u16 payload_size() const { return m_length - sizeof(IPv4Packet); } - NetworkOrdered<word> compute_checksum() const + NetworkOrdered<u16> compute_checksum() const { ASSERT(!m_checksum); return internet_checksum(this, sizeof(IPv4Packet)); } private: - byte m_version_and_ihl { 0 }; - byte m_dscp_and_ecn { 0 }; - NetworkOrdered<word> m_length; - NetworkOrdered<word> m_ident; - NetworkOrdered<word> m_flags_and_fragment; - byte m_ttl { 0 }; - NetworkOrdered<byte> m_protocol; - NetworkOrdered<word> m_checksum; + u8 m_version_and_ihl { 0 }; + u8 m_dscp_and_ecn { 0 }; + NetworkOrdered<u16> m_length; + NetworkOrdered<u16> m_ident; + NetworkOrdered<u16> m_flags_and_fragment; + u8 m_ttl { 0 }; + NetworkOrdered<u8> m_protocol; + NetworkOrdered<u16> m_checksum; IPv4Address m_source; IPv4Address m_destination; }; static_assert(sizeof(IPv4Packet) == 20); -inline NetworkOrdered<word> internet_checksum(const void* ptr, size_t count) +inline NetworkOrdered<u16> internet_checksum(const void* ptr, size_t count) { - dword checksum = 0; - auto* w = (const word*)ptr; + u32 checksum = 0; + auto* w = (const u16*)ptr; while (count > 1) { checksum += convert_between_host_and_network(*w++); if (checksum & 0x80000000) diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 1d2ec7a57e..39a85db4cc 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -81,7 +81,7 @@ KResult IPv4Socket::bind(const sockaddr* address, socklen_t address_size) return KResult(-EINVAL); auto& ia = *(const sockaddr_in*)address; - m_local_address = IPv4Address((const byte*)&ia.sin_addr.s_addr); + m_local_address = IPv4Address((const u8*)&ia.sin_addr.s_addr); m_local_port = ntohs(ia.sin_port); dbgprintf("IPv4Socket::bind %s{%p} to port %u\n", class_name(), this, m_local_port); @@ -98,7 +98,7 @@ KResult IPv4Socket::connect(FileDescription& description, const sockaddr* addres return KResult(-EINVAL); auto& ia = *(const sockaddr_in*)address; - m_peer_address = IPv4Address((const byte*)&ia.sin_addr.s_addr); + m_peer_address = IPv4Address((const u8*)&ia.sin_addr.s_addr); m_peer_port = ntohs(ia.sin_port); return protocol_connect(description, should_block); @@ -123,12 +123,12 @@ bool IPv4Socket::can_read(FileDescription& description) const return m_can_read; } -ssize_t IPv4Socket::read(FileDescription& description, byte* buffer, ssize_t size) +ssize_t IPv4Socket::read(FileDescription& description, u8* buffer, ssize_t size) { return recvfrom(description, buffer, size, 0, nullptr, 0); } -ssize_t IPv4Socket::write(FileDescription& description, const byte* data, ssize_t size) +ssize_t IPv4Socket::write(FileDescription& description, const u8* data, ssize_t size) { return sendto(description, data, size, 0, nullptr, 0); } @@ -145,7 +145,7 @@ int IPv4Socket::allocate_local_port_if_needed() int port = protocol_allocate_local_port(); if (port < 0) return port; - m_local_port = (word)port; + m_local_port = (u16)port; return port; } @@ -162,7 +162,7 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt } auto& ia = *(const sockaddr_in*)addr; - m_peer_address = IPv4Address((const byte*)&ia.sin_addr.s_addr); + m_peer_address = IPv4Address((const u8*)&ia.sin_addr.s_addr); m_peer_port = ntohs(ia.sin_port); } @@ -249,7 +249,7 @@ ssize_t IPv4Socket::recvfrom(FileDescription& description, void* buffer, size_t return protocol_receive(packet.data, buffer, buffer_length, flags); } -void IPv4Socket::did_receive(const IPv4Address& source_address, word source_port, ByteBuffer&& packet) +void IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port, ByteBuffer&& packet) { LOCKER(lock()); auto packet_size = packet.size(); diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index 63f90fe346..d6c52a2bbf 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -27,21 +27,21 @@ public: virtual void attach(FileDescription&) override; virtual void detach(FileDescription&) override; virtual bool can_read(FileDescription&) const override; - virtual ssize_t read(FileDescription&, byte*, ssize_t) override; - virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; + virtual ssize_t read(FileDescription&, u8*, ssize_t) override; + virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; virtual bool can_write(FileDescription&) const override; virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override; virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override; - void did_receive(const IPv4Address& peer_address, word peer_port, ByteBuffer&&); + void did_receive(const IPv4Address& peer_address, u16 peer_port, ByteBuffer&&); const IPv4Address& local_address() const; - word local_port() const { return m_local_port; } - void set_local_port(word port) { m_local_port = port; } + u16 local_port() const { return m_local_port; } + void set_local_port(u16 port) { m_local_port = port; } const IPv4Address& peer_address() const { return m_peer_address; } - word peer_port() const { return m_peer_port; } - void set_peer_port(word port) { m_peer_port = port; } + u16 peer_port() const { return m_peer_port; } + void set_peer_port(u16 port) { m_peer_port = port; } protected: IPv4Socket(int type, int protocol); @@ -70,16 +70,16 @@ private: struct ReceivedPacket { IPv4Address peer_address; - word peer_port; + u16 peer_port; ByteBuffer data; }; SinglyLinkedList<ReceivedPacket> m_receive_queue; - word m_local_port { 0 }; - word m_peer_port { 0 }; + u16 m_local_port { 0 }; + u16 m_peer_port { 0 }; - dword m_bytes_received { 0 }; + u32 m_bytes_received { 0 }; bool m_can_read { false }; }; diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 57e13a4a3a..16f7edfbde 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -155,7 +155,7 @@ bool LocalSocket::can_read(FileDescription& description) const ASSERT_NOT_REACHED(); } -ssize_t LocalSocket::read(FileDescription& description, byte* buffer, ssize_t size) +ssize_t LocalSocket::read(FileDescription& description, u8* buffer, ssize_t size) { auto role = description.socket_role(); if (role == SocketRole::Accepted) { @@ -184,7 +184,7 @@ bool LocalSocket::has_attached_peer(const FileDescription& description) const ASSERT_NOT_REACHED(); } -ssize_t LocalSocket::write(FileDescription& description, const byte* data, ssize_t size) +ssize_t LocalSocket::write(FileDescription& description, const u8* data, ssize_t size) { if (!has_attached_peer(description)) return -EPIPE; @@ -206,10 +206,10 @@ bool LocalSocket::can_write(FileDescription& description) const ssize_t LocalSocket::sendto(FileDescription& description, const void* data, size_t data_size, int, const sockaddr*, socklen_t) { - return write(description, (const byte*)data, data_size); + return write(description, (const u8*)data, data_size); } ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*) { - return read(description, (byte*)buffer, buffer_size); + return read(description, (u8*)buffer, buffer_size); } diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 4d348e8435..179f290252 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -17,8 +17,8 @@ public: virtual void attach(FileDescription&) override; virtual void detach(FileDescription&) override; virtual bool can_read(FileDescription&) const override; - virtual ssize_t read(FileDescription&, byte*, ssize_t) override; - virtual ssize_t write(FileDescription&, const byte*, ssize_t) override; + virtual ssize_t read(FileDescription&, u8*, ssize_t) override; + virtual ssize_t write(FileDescription&, const u8*, ssize_t) override; virtual bool can_write(FileDescription&) const override; virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override; virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override; diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp index 2f90602e6b..2452d0bfad 100644 --- a/Kernel/Net/LoopbackAdapter.cpp +++ b/Kernel/Net/LoopbackAdapter.cpp @@ -18,7 +18,7 @@ LoopbackAdapter::~LoopbackAdapter() { } -void LoopbackAdapter::send_raw(const byte* data, int size) +void LoopbackAdapter::send_raw(const u8* data, int size) { dbgprintf("LoopbackAdapter: Sending %d byte(s) to myself.\n", size); did_receive(data, size); diff --git a/Kernel/Net/LoopbackAdapter.h b/Kernel/Net/LoopbackAdapter.h index e22c146330..0e263c57e0 100644 --- a/Kernel/Net/LoopbackAdapter.h +++ b/Kernel/Net/LoopbackAdapter.h @@ -9,7 +9,7 @@ public: virtual ~LoopbackAdapter() override; - virtual void send_raw(const byte*, int) override; + virtual void send_raw(const u8*, int) override; virtual const char* class_name() const override { return "LoopbackAdapter"; } private: diff --git a/Kernel/Net/MACAddress.h b/Kernel/Net/MACAddress.h index 72069bdaa5..a5e97f31e3 100644 --- a/Kernel/Net/MACAddress.h +++ b/Kernel/Net/MACAddress.h @@ -9,13 +9,13 @@ class [[gnu::packed]] MACAddress { public: MACAddress() {} - MACAddress(const byte data[6]) + MACAddress(const u8 data[6]) { memcpy(m_data, data, 6); } ~MACAddress() {} - byte operator[](int i) const + u8 operator[](int i) const { ASSERT(i >= 0 && i < 6); return m_data[i]; @@ -32,7 +32,7 @@ public: } private: - byte m_data[6]; + u8 m_data[6]; }; static_assert(sizeof(MACAddress) == 6); diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index 7537e1e224..bb39a869ea 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -53,7 +53,7 @@ void NetworkAdapter::send(const MACAddress& destination, const ARPPacket& packet eth->set_destination(destination); eth->set_ether_type(EtherType::ARP); memcpy(eth->payload(), &packet, sizeof(ARPPacket)); - send_raw((byte*)eth, size_in_bytes); + send_raw((u8*)eth, size_in_bytes); } void NetworkAdapter::send_ipv4(const MACAddress& destination_mac, const IPv4Address& destination_ipv4, IPv4Protocol protocol, ByteBuffer&& payload) @@ -69,16 +69,16 @@ void NetworkAdapter::send_ipv4(const MACAddress& destination_mac, const IPv4Addr ipv4.set_internet_header_length(5); ipv4.set_source(ipv4_address()); ipv4.set_destination(destination_ipv4); - ipv4.set_protocol((byte)protocol); + ipv4.set_protocol((u8)protocol); ipv4.set_length(sizeof(IPv4Packet) + payload.size()); ipv4.set_ident(1); ipv4.set_ttl(64); ipv4.set_checksum(ipv4.compute_checksum()); memcpy(ipv4.payload(), payload.pointer(), payload.size()); - send_raw((const byte*)ð, size_in_bytes); + send_raw((const u8*)ð, size_in_bytes); } -void NetworkAdapter::did_receive(const byte* data, int length) +void NetworkAdapter::did_receive(const u8* data, int length) { InterruptDisabler disabler; m_packet_queue.append(ByteBuffer::copy(data, length)); diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h index 39c2374e0d..118bb13774 100644 --- a/Kernel/Net/NetworkAdapter.h +++ b/Kernel/Net/NetworkAdapter.h @@ -52,8 +52,8 @@ protected: NetworkAdapter(); void set_interface_name(const StringView& basename); void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; } - virtual void send_raw(const byte*, int) = 0; - void did_receive(const byte*, int); + virtual void send_raw(const u8*, int) = 0; + void did_receive(const u8*, int); private: MACAddress m_mac_address; diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 0a12ffd5b7..c680a66135 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -225,8 +225,8 @@ void handle_icmp(const EthernetFrameHeader& eth, int frame_size) auto& request = reinterpret_cast<const ICMPEchoPacket&>(icmp_header); kprintf("handle_icmp: EchoRequest from %s: id=%u, seq=%u\n", ipv4_packet.source().to_string().characters(), - (word)request.identifier, - (word)request.sequence_number); + (u16)request.identifier, + (u16)request.sequence_number); size_t icmp_packet_size = ipv4_packet.payload_size(); auto buffer = ByteBuffer::create_zeroed(icmp_packet_size); auto& response = *(ICMPEchoPacket*)buffer.pointer(); diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index 7ff1fe7506..876424b9ce 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -9,7 +9,7 @@ #include <Kernel/Lock.h> #include <Kernel/UnixTypes.h> -enum class SocketRole : byte { +enum class SocketRole : u8 { None, Listener, Accepted, diff --git a/Kernel/Net/TCP.h b/Kernel/Net/TCP.h index 611c451105..b994b9d47f 100644 --- a/Kernel/Net/TCP.h +++ b/Kernel/Net/TCP.h @@ -3,7 +3,7 @@ #include <Kernel/Net/IPv4.h> struct TCPFlags { - enum : word { + enum : u16 { FIN = 0x01, SYN = 0x02, RST = 0x04, @@ -19,52 +19,52 @@ public: TCPPacket() {} ~TCPPacket() {} - size_t header_size() const { return data_offset() * sizeof(dword); } + size_t header_size() const { return data_offset() * sizeof(u32); } - word source_port() const { return m_source_port; } - void set_source_port(word port) { m_source_port = port; } + u16 source_port() const { return m_source_port; } + void set_source_port(u16 port) { m_source_port = port; } - word destination_port() const { return m_destination_port; } - void set_destination_port(word port) { m_destination_port = port; } + u16 destination_port() const { return m_destination_port; } + void set_destination_port(u16 port) { m_destination_port = port; } - dword sequence_number() const { return m_sequence_number; } - void set_sequence_number(dword number) { m_sequence_number = number; } + u32 sequence_number() const { return m_sequence_number; } + void set_sequence_number(u32 number) { m_sequence_number = number; } - dword ack_number() const { return m_ack_number; } - void set_ack_number(dword number) { m_ack_number = number; } + u32 ack_number() const { return m_ack_number; } + void set_ack_number(u32 number) { m_ack_number = number; } - word flags() const { return m_flags_and_data_offset & 0x1ff; } - void set_flags(word flags) { m_flags_and_data_offset = (m_flags_and_data_offset & ~0x1ff) | (flags & 0x1ff); } + u16 flags() const { return m_flags_and_data_offset & 0x1ff; } + void set_flags(u16 flags) { m_flags_and_data_offset = (m_flags_and_data_offset & ~0x1ff) | (flags & 0x1ff); } bool has_syn() const { return flags() & TCPFlags::SYN; } bool has_ack() const { return flags() & TCPFlags::ACK; } bool has_fin() const { return flags() & TCPFlags::FIN; } - byte data_offset() const { return (m_flags_and_data_offset & 0xf000) >> 12; } - void set_data_offset(word data_offset) { m_flags_and_data_offset = (m_flags_and_data_offset & ~0xf000) | data_offset << 12; } + u8 data_offset() const { return (m_flags_and_data_offset & 0xf000) >> 12; } + void set_data_offset(u16 data_offset) { m_flags_and_data_offset = (m_flags_and_data_offset & ~0xf000) | data_offset << 12; } - word window_size() const { return m_window_size; } - void set_window_size(word window_size) { m_window_size = window_size; } + u16 window_size() const { return m_window_size; } + void set_window_size(u16 window_size) { m_window_size = window_size; } - word checksum() const { return m_checksum; } - void set_checksum(word checksum) { m_checksum = checksum; } + u16 checksum() const { return m_checksum; } + void set_checksum(u16 checksum) { m_checksum = checksum; } - word urgent() const { return m_urgent; } - void set_urgent(word urgent) { m_urgent = urgent; } + u16 urgent() const { return m_urgent; } + void set_urgent(u16 urgent) { m_urgent = urgent; } - const void* payload() const { return ((const byte*)this) + header_size(); } - void* payload() { return ((byte*)this) + header_size(); } + const void* payload() const { return ((const u8*)this) + header_size(); } + void* payload() { return ((u8*)this) + header_size(); } private: - NetworkOrdered<word> m_source_port; - NetworkOrdered<word> m_destination_port; - NetworkOrdered<dword> m_sequence_number; - NetworkOrdered<dword> m_ack_number; - - NetworkOrdered<word> m_flags_and_data_offset; - NetworkOrdered<word> m_window_size; - NetworkOrdered<word> m_checksum; - NetworkOrdered<word> m_urgent; + NetworkOrdered<u16> m_source_port; + NetworkOrdered<u16> m_destination_port; + NetworkOrdered<u32> m_sequence_number; + NetworkOrdered<u32> m_ack_number; + + NetworkOrdered<u16> m_flags_and_data_offset; + NetworkOrdered<u16> m_window_size; + NetworkOrdered<u16> m_checksum; + NetworkOrdered<u16> m_urgent; }; static_assert(sizeof(TCPPacket) == 20); diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index f9d1c1281d..ad2f688495 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -5,15 +5,15 @@ #include <Kernel/Net/TCPSocket.h> #include <Kernel/Process.h> -Lockable<HashMap<word, TCPSocket*>>& TCPSocket::sockets_by_port() +Lockable<HashMap<u16, TCPSocket*>>& TCPSocket::sockets_by_port() { - static Lockable<HashMap<word, TCPSocket*>>* s_map; + static Lockable<HashMap<u16, TCPSocket*>>* s_map; if (!s_map) - s_map = new Lockable<HashMap<word, TCPSocket*>>; + s_map = new Lockable<HashMap<u16, TCPSocket*>>; return *s_map; } -TCPSocketHandle TCPSocket::from_port(word port) +TCPSocketHandle TCPSocket::from_port(u16 port) { RefPtr<TCPSocket> socket; { @@ -65,7 +65,7 @@ int TCPSocket::protocol_send(const void* data, int data_length) return data_length; } -void TCPSocket::send_tcp_packet(word flags, const void* payload, int payload_size) +void TCPSocket::send_tcp_packet(u16 flags, const void* payload, int payload_size) { // FIXME: Maybe the socket should be bound to an adapter instead of looking it up every time? auto* adapter = adapter_for_route_to(peer_address()); @@ -78,7 +78,7 @@ void TCPSocket::send_tcp_packet(word flags, const void* payload, int payload_siz tcp_packet.set_destination_port(peer_port()); tcp_packet.set_window_size(1024); tcp_packet.set_sequence_number(m_sequence_number); - tcp_packet.set_data_offset(sizeof(TCPPacket) / sizeof(dword)); + tcp_packet.set_data_offset(sizeof(TCPPacket) / sizeof(u32)); tcp_packet.set_flags(flags); if (flags & TCPFlags::ACK) @@ -104,41 +104,41 @@ void TCPSocket::send_tcp_packet(word flags, const void* payload, int payload_siz adapter->send_ipv4(MACAddress(), peer_address(), IPv4Protocol::TCP, move(buffer)); } -NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket& packet, word payload_size) +NetworkOrdered<u16> TCPSocket::compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket& packet, u16 payload_size) { struct [[gnu::packed]] PseudoHeader { IPv4Address source; IPv4Address destination; - byte zero; - byte protocol; - NetworkOrdered<word> payload_size; + u8 zero; + u8 protocol; + NetworkOrdered<u16> payload_size; }; - PseudoHeader pseudo_header { source, destination, 0, (byte)IPv4Protocol::TCP, sizeof(TCPPacket) + payload_size }; + PseudoHeader pseudo_header { source, destination, 0, (u8)IPv4Protocol::TCP, sizeof(TCPPacket) + payload_size }; - dword checksum = 0; - auto* w = (const NetworkOrdered<word>*)&pseudo_header; - for (size_t i = 0; i < sizeof(pseudo_header) / sizeof(word); ++i) { + u32 checksum = 0; + auto* w = (const NetworkOrdered<u16>*)&pseudo_header; + for (size_t i = 0; i < sizeof(pseudo_header) / sizeof(u16); ++i) { checksum += w[i]; if (checksum > 0xffff) checksum = (checksum >> 16) + (checksum & 0xffff); } - w = (const NetworkOrdered<word>*)&packet; - for (size_t i = 0; i < sizeof(packet) / sizeof(word); ++i) { + w = (const NetworkOrdered<u16>*)&packet; + for (size_t i = 0; i < sizeof(packet) / sizeof(u16); ++i) { checksum += w[i]; if (checksum > 0xffff) checksum = (checksum >> 16) + (checksum & 0xffff); } ASSERT(packet.data_offset() * 4 == sizeof(TCPPacket)); - w = (const NetworkOrdered<word>*)packet.payload(); - for (size_t i = 0; i < payload_size / sizeof(word); ++i) { + w = (const NetworkOrdered<u16>*)packet.payload(); + for (size_t i = 0; i < payload_size / sizeof(u16); ++i) { checksum += w[i]; if (checksum > 0xffff) checksum = (checksum >> 16) + (checksum & 0xffff); } if (payload_size & 1) { - word expanded_byte = ((const byte*)packet.payload())[payload_size - 1] << 8; + u16 expanded_byte = ((const u8*)packet.payload())[payload_size - 1] << 8; checksum += expanded_byte; if (checksum > 0xffff) checksum = (checksum >> 16) + (checksum & 0xffff); @@ -171,13 +171,13 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh int TCPSocket::protocol_allocate_local_port() { - static const word first_ephemeral_port = 32768; - static const word last_ephemeral_port = 60999; - static const word ephemeral_port_range_size = last_ephemeral_port - first_ephemeral_port; - word first_scan_port = first_ephemeral_port + RandomDevice::random_value() % ephemeral_port_range_size; + static const u16 first_ephemeral_port = 32768; + static const u16 last_ephemeral_port = 60999; + static const u16 ephemeral_port_range_size = last_ephemeral_port - first_ephemeral_port; + u16 first_scan_port = first_ephemeral_port + RandomDevice::random_value() % ephemeral_port_range_size; LOCKER(sockets_by_port().lock()); - for (word port = first_scan_port;;) { + for (u16 port = first_scan_port;;) { auto it = sockets_by_port().resource().find(port); if (it == sockets_by_port().resource().end()) { set_local_port(port); diff --git a/Kernel/Net/TCPSocket.h b/Kernel/Net/TCPSocket.h index 4c71a9be8d..8161eca234 100644 --- a/Kernel/Net/TCPSocket.h +++ b/Kernel/Net/TCPSocket.h @@ -17,21 +17,21 @@ public: State state() const { return m_state; } void set_state(State state) { m_state = state; } - void set_ack_number(dword n) { m_ack_number = n; } - void set_sequence_number(dword n) { m_sequence_number = n; } - dword ack_number() const { return m_ack_number; } - dword sequence_number() const { return m_sequence_number; } + void set_ack_number(u32 n) { m_ack_number = n; } + void set_sequence_number(u32 n) { m_sequence_number = n; } + u32 ack_number() const { return m_ack_number; } + u32 sequence_number() const { return m_sequence_number; } - void send_tcp_packet(word flags, const void* = nullptr, int = 0); + void send_tcp_packet(u16 flags, const void* = nullptr, int = 0); - static Lockable<HashMap<word, TCPSocket*>>& sockets_by_port(); - static TCPSocketHandle from_port(word); + static Lockable<HashMap<u16, TCPSocket*>>& sockets_by_port(); + static TCPSocketHandle from_port(u16); private: explicit TCPSocket(int protocol); virtual const char* class_name() const override { return "TCPSocket"; } - static NetworkOrdered<word> compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket&, word payload_size); + static NetworkOrdered<u16> compute_tcp_checksum(const IPv4Address& source, const IPv4Address& destination, const TCPPacket&, u16 payload_size); virtual int protocol_receive(const ByteBuffer&, void* buffer, size_t buffer_size, int flags) override; virtual int protocol_send(const void*, int) override; @@ -40,8 +40,8 @@ private: virtual bool protocol_is_disconnected() const override; virtual KResult protocol_bind() override; - dword m_sequence_number { 0 }; - dword m_ack_number { 0 }; + u32 m_sequence_number { 0 }; + u32 m_ack_number { 0 }; State m_state { State::Disconnected }; }; diff --git a/Kernel/Net/UDP.h b/Kernel/Net/UDP.h index 7ec39719cd..61718a8f06 100644 --- a/Kernel/Net/UDP.h +++ b/Kernel/Net/UDP.h @@ -8,26 +8,26 @@ public: UDPPacket() {} ~UDPPacket() {} - word source_port() const { return m_source_port; } - void set_source_port(word port) { m_source_port = port; } + u16 source_port() const { return m_source_port; } + void set_source_port(u16 port) { m_source_port = port; } - word destination_port() const { return m_destination_port; } - void set_destination_port(word port) { m_destination_port = port; } + u16 destination_port() const { return m_destination_port; } + void set_destination_port(u16 port) { m_destination_port = port; } - word length() const { return m_length; } - void set_length(word length) { m_length = length; } + u16 length() const { return m_length; } + void set_length(u16 length) { m_length = length; } - word checksum() const { return m_checksum; } - void set_checksum(word checksum) { m_checksum = checksum; } + u16 checksum() const { return m_checksum; } + void set_checksum(u16 checksum) { m_checksum = checksum; } const void* payload() const { return this + 1; } void* payload() { return this + 1; } private: - NetworkOrdered<word> m_source_port; - NetworkOrdered<word> m_destination_port; - NetworkOrdered<word> m_length; - NetworkOrdered<word> m_checksum; + NetworkOrdered<u16> m_source_port; + NetworkOrdered<u16> m_destination_port; + NetworkOrdered<u16> m_length; + NetworkOrdered<u16> m_checksum; }; static_assert(sizeof(UDPPacket) == 8); diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index c36f09c4bf..9658346642 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -5,15 +5,15 @@ #include <Kernel/Net/UDPSocket.h> #include <Kernel/Process.h> -Lockable<HashMap<word, UDPSocket*>>& UDPSocket::sockets_by_port() +Lockable<HashMap<u16, UDPSocket*>>& UDPSocket::sockets_by_port() { - static Lockable<HashMap<word, UDPSocket*>>* s_map; + static Lockable<HashMap<u16, UDPSocket*>>* s_map; if (!s_map) - s_map = new Lockable<HashMap<word, UDPSocket*>>; + s_map = new Lockable<HashMap<u16, UDPSocket*>>; return *s_map; } -UDPSocketHandle UDPSocket::from_port(word port) +UDPSocketHandle UDPSocket::from_port(u16 port) { RefPtr<UDPSocket> socket; { @@ -77,13 +77,13 @@ int UDPSocket::protocol_send(const void* data, int data_length) int UDPSocket::protocol_allocate_local_port() { - static const word first_ephemeral_port = 32768; - static const word last_ephemeral_port = 60999; - static const word ephemeral_port_range_size = last_ephemeral_port - first_ephemeral_port; - word first_scan_port = first_ephemeral_port + RandomDevice::random_value() % ephemeral_port_range_size; + static const u16 first_ephemeral_port = 32768; + static const u16 last_ephemeral_port = 60999; + static const u16 ephemeral_port_range_size = last_ephemeral_port - first_ephemeral_port; + u16 first_scan_port = first_ephemeral_port + RandomDevice::random_value() % ephemeral_port_range_size; LOCKER(sockets_by_port().lock()); - for (word port = first_scan_port;;) { + for (u16 port = first_scan_port;;) { auto it = sockets_by_port().resource().find(port); if (it == sockets_by_port().resource().end()) { set_local_port(port); diff --git a/Kernel/Net/UDPSocket.h b/Kernel/Net/UDPSocket.h index fbfce367b2..2f60b0452d 100644 --- a/Kernel/Net/UDPSocket.h +++ b/Kernel/Net/UDPSocket.h @@ -9,12 +9,12 @@ public: static NonnullRefPtr<UDPSocket> create(int protocol); virtual ~UDPSocket() override; - static UDPSocketHandle from_port(word); + static UDPSocketHandle from_port(u16); private: explicit UDPSocket(int protocol); virtual const char* class_name() const override { return "UDPSocket"; } - static Lockable<HashMap<word, UDPSocket*>>& sockets_by_port(); + static Lockable<HashMap<u16, UDPSocket*>>& sockets_by_port(); virtual int protocol_receive(const ByteBuffer&, void* buffer, size_t buffer_size, int flags) override; virtual int protocol_send(const void*, int) override; |