From 10c6f062b3eb9da9e45c64a0483920a6f122fbbb Mon Sep 17 00:00:00 2001 From: asynts Date: Tue, 25 Aug 2020 15:11:15 +0200 Subject: [PATCH] AK: Add Endian.h header to replace NetworkOrdered.h. --- AK/Endian.h | 114 +++++++++++++++++++++++++++ AK/IPv4Address.h | 3 +- AK/NetworkOrdered.h | 46 ----------- AK/Platform.h | 35 +++----- AK/Stream.h | 30 +++++++ Kernel/Net/ARP.h | 2 +- Kernel/Net/EthernetFrameHeader.h | 6 +- Kernel/Net/IPv4.h | 4 +- Libraries/LibCrypto/Hash/SHA1.cpp | 3 +- Libraries/LibGfx/PBMLoader.cpp | 2 +- Libraries/LibGfx/PGMLoader.cpp | 2 +- Libraries/LibGfx/PNGLoader.cpp | 2 +- Libraries/LibGfx/PPMLoader.cpp | 2 +- Libraries/LibTLS/ClientHandshake.cpp | 16 ++-- Libraries/LibTLS/Record.cpp | 12 +-- Libraries/LibTLS/TLSPacketBuilder.h | 6 +- Libraries/LibTLS/TLSv12.cpp | 3 +- Services/DHCPClient/DHCPv4.h | 8 +- Services/DHCPClient/DHCPv4Client.cpp | 3 +- Services/LookupServer/DNSPacket.h | 2 +- 20 files changed, 195 insertions(+), 106 deletions(-) create mode 100644 AK/Endian.h delete mode 100644 AK/NetworkOrdered.h diff --git a/AK/Endian.h b/AK/Endian.h new file mode 100644 index 00000000000..e5265a5148b --- /dev/null +++ b/AK/Endian.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2020, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include + +namespace AK { + +template +ALWAYS_INLINE T convert_between_host_and_little_endian(T value) +{ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + return value; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + if constexpr (sizeof(T) == 8) + return __builtin_bswap64(value); + if constexpr (sizeof(T) == 4) + return __builtin_bswap32(value); + if constexpr (sizeof(T) == 2) + return __builtin_bswap16(value); + if constexpr (sizeof(T) == 1) + return value; +#endif +} + +template +ALWAYS_INLINE T convert_between_host_and_big_endian(T value) +{ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + if constexpr (sizeof(T) == 8) + return __builtin_bswap64(value); + if constexpr (sizeof(T) == 4) + return __builtin_bswap32(value); + if constexpr (sizeof(T) == 2) + return __builtin_bswap16(value); + if constexpr (sizeof(T) == 1) + return value; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + return value; +#endif +} + +template +ALWAYS_INLINE T convert_between_host_and_network_endian(T value) +{ + return convert_between_host_and_big_endian(value); +} + +template +class [[gnu::packed]] LittleEndian +{ +public: + LittleEndian() { } + + LittleEndian(T value) + : m_value(convert_between_host_and_little_endian(value)) + { + } + + operator T() const { return convert_between_host_and_little_endian(m_value); } + +private: + T m_value { 0 }; +}; + +template +class [[gnu::packed]] BigEndian +{ +public: + BigEndian() { } + + BigEndian(T value) + : m_value(convert_between_host_and_big_endian(value)) + { + } + + operator T() const { return convert_between_host_and_big_endian(m_value); } + +private: + T m_value { 0 }; +}; + +template +using NetworkOrdered = BigEndian; + +} + +using AK::BigEndian; +using AK::LittleEndian; +using AK::NetworkOrdered; diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h index 68ac1030ee6..8beb3ba0e16 100644 --- a/AK/IPv4Address.h +++ b/AK/IPv4Address.h @@ -26,8 +26,8 @@ #pragma once +#include #include -#include #include #include #include @@ -106,7 +106,6 @@ public: return {}; } - if (a > 255 || b > 255 || c > 255 || d > 255) return {}; return IPv4Address((u8)a, (u8)b, (u8)c, (u8)d); diff --git a/AK/NetworkOrdered.h b/AK/NetworkOrdered.h deleted file mode 100644 index 1d328ff821c..00000000000 --- a/AK/NetworkOrdered.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -template -class [[gnu::packed]] NetworkOrdered -{ -public: - NetworkOrdered() {} - NetworkOrdered(const T& host_value) - : m_network_value(convert_between_host_and_network(host_value)) - { - } - - operator T() const { return convert_between_host_and_network(m_network_value); } - -private: - T m_network_value { 0 }; -}; diff --git a/AK/Platform.h b/AK/Platform.h index b745e6a780f..9a8050ad70c 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -37,17 +37,17 @@ #define ARCH(arch) (defined(AK_ARCH_##arch) && AK_ARCH_##arch) #ifdef ALWAYS_INLINE -#undef ALWAYS_INLINE +# undef ALWAYS_INLINE #endif #define ALWAYS_INLINE [[gnu::always_inline]] inline #ifdef NEVER_INLINE -#undef NEVER_INLINE +# undef NEVER_INLINE #endif #define NEVER_INLINE [[gnu::noinline]] #ifdef FLATTEN -#undef FLATTEN +# undef FLATTEN #endif #define FLATTEN [[gnu::flatten]] @@ -71,33 +71,16 @@ inline int open_with_path_length(const char* path, size_t path_length, int optio } #endif -template -ALWAYS_INLINE T convert_between_host_and_network(T value) -{ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - if constexpr (sizeof(T) == 8) - return __builtin_bswap64(value); - if constexpr (sizeof(T) == 4) - return __builtin_bswap32(value); - if constexpr (sizeof(T) == 2) - return __builtin_bswap16(value); - if constexpr (sizeof(T) == 1) - return value; -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - return value; -#endif -} - ALWAYS_INLINE int count_trailing_zeroes_32(unsigned int val) { #if defined(__GNUC__) || defined(__clang__) - return __builtin_ctz(val); + return __builtin_ctz(val); #else - for (u8 i = 0; i < 32; ++i) { - if ((val >> i) & 1) { - return i; - } + for (u8 i = 0; i < 32; ++i) { + if ((val >> i) & 1) { + return i; } - return 0; + } + return 0; #endif } diff --git a/AK/Stream.h b/AK/Stream.h index bb52de42366..c1d0e00ec72 100644 --- a/AK/Stream.h +++ b/AK/Stream.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -74,6 +75,35 @@ class DuplexStream , public OutputStream { }; +template +InputStream& operator>>(InputStream& stream, LittleEndian& value) +{ + T temporary; + stream >> temporary; + value = temporary; + return stream; +} +template +InputStream& operator<<(InputStream& stream, LittleEndian value) +{ + stream << static_cast(value); + return stream; +} +template +InputStream& operator>>(InputStream& stream, BigEndian& value) +{ + T temporary; + stream >> temporary; + value = temporary; + return stream; +} +template +InputStream& operator<<(InputStream& stream, BigEndian value) +{ + stream << static_cast(value); + return stream; +} + #if defined(__cpp_concepts) && !defined(__COVERITY__) template #else diff --git a/Kernel/Net/ARP.h b/Kernel/Net/ARP.h index e467faec20b..0783611cc84 100644 --- a/Kernel/Net/ARP.h +++ b/Kernel/Net/ARP.h @@ -26,8 +26,8 @@ #pragma once +#include #include -#include #include #include diff --git a/Kernel/Net/EthernetFrameHeader.h b/Kernel/Net/EthernetFrameHeader.h index f73ae2a3580..fa23de83070 100644 --- a/Kernel/Net/EthernetFrameHeader.h +++ b/Kernel/Net/EthernetFrameHeader.h @@ -26,16 +26,16 @@ #pragma once +#include #include -#include #pragma GCC diagnostic ignored "-Warray-bounds" class [[gnu::packed]] EthernetFrameHeader { public: - EthernetFrameHeader() {} - ~EthernetFrameHeader() {} + EthernetFrameHeader() { } + ~EthernetFrameHeader() { } MACAddress destination() const { return m_destination; } void set_destination(const MACAddress& address) { m_destination = address; } diff --git a/Kernel/Net/IPv4.h b/Kernel/Net/IPv4.h index 89e5793519b..e94d082ed17 100644 --- a/Kernel/Net/IPv4.h +++ b/Kernel/Net/IPv4.h @@ -27,8 +27,8 @@ #pragma once #include +#include #include -#include #include #include @@ -131,7 +131,7 @@ inline NetworkOrdered internet_checksum(const void* ptr, size_t count) u32 checksum = 0; auto* w = (const u16*)ptr; while (count > 1) { - checksum += convert_between_host_and_network(*w++); + checksum += AK::convert_between_host_and_network_endian(*w++); if (checksum & 0x80000000) checksum = (checksum & 0xffff) | (checksum >> 16); count -= 2; diff --git a/Libraries/LibCrypto/Hash/SHA1.cpp b/Libraries/LibCrypto/Hash/SHA1.cpp index 42b23209a01..3ff04bffd9d 100644 --- a/Libraries/LibCrypto/Hash/SHA1.cpp +++ b/Libraries/LibCrypto/Hash/SHA1.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include @@ -39,7 +40,7 @@ inline void SHA1::transform(const u8* data) { u32 blocks[80]; for (size_t i = 0; i < 16; ++i) - blocks[i] = convert_between_host_and_network(((const u32*)data)[i]); + blocks[i] = AK::convert_between_host_and_network_endian(((const u32*)data)[i]); // w[i] = (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1 for (size_t i = 16; i < Rounds; ++i) diff --git a/Libraries/LibGfx/PBMLoader.cpp b/Libraries/LibGfx/PBMLoader.cpp index 272851ceb28..c4001375cca 100644 --- a/Libraries/LibGfx/PBMLoader.cpp +++ b/Libraries/LibGfx/PBMLoader.cpp @@ -25,9 +25,9 @@ */ #include "PBMLoader.h" +#include #include #include -#include #include #include diff --git a/Libraries/LibGfx/PGMLoader.cpp b/Libraries/LibGfx/PGMLoader.cpp index cb69bd4b3d4..40c3ff22729 100644 --- a/Libraries/LibGfx/PGMLoader.cpp +++ b/Libraries/LibGfx/PGMLoader.cpp @@ -25,9 +25,9 @@ */ #include "PGMLoader.h" +#include #include #include -#include #include #include diff --git a/Libraries/LibGfx/PNGLoader.cpp b/Libraries/LibGfx/PNGLoader.cpp index 434047573c1..0dae43e9489 100644 --- a/Libraries/LibGfx/PNGLoader.cpp +++ b/Libraries/LibGfx/PNGLoader.cpp @@ -25,9 +25,9 @@ */ #include +#include #include #include -#include #include #include #include diff --git a/Libraries/LibGfx/PPMLoader.cpp b/Libraries/LibGfx/PPMLoader.cpp index c6c89f14af0..bb345e18a51 100644 --- a/Libraries/LibGfx/PPMLoader.cpp +++ b/Libraries/LibGfx/PPMLoader.cpp @@ -25,9 +25,9 @@ */ #include "PPMLoader.h" +#include #include #include -#include #include #include diff --git a/Libraries/LibTLS/ClientHandshake.cpp b/Libraries/LibTLS/ClientHandshake.cpp index 8b4bc28fa03..214fce237a6 100644 --- a/Libraries/LibTLS/ClientHandshake.cpp +++ b/Libraries/LibTLS/ClientHandshake.cpp @@ -24,7 +24,9 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include + #include #include #include @@ -70,7 +72,7 @@ ssize_t TLSv12::handle_hello(const ByteBuffer& buffer, WritePacketStage& write_p dbg() << "not enough data for version"; return (i8)Error::NeedMoreData; } - auto version = (Version)convert_between_host_and_network(*(const u16*)buffer.offset_pointer(res)); + auto version = (Version)AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res)); res += 2; if (!supports_version(version)) @@ -101,7 +103,7 @@ ssize_t TLSv12::handle_hello(const ByteBuffer& buffer, WritePacketStage& write_p dbg() << "not enough data for cipher suite listing"; return (i8)Error::NeedMoreData; } - auto cipher = (CipherSuite)convert_between_host_and_network(*(const u16*)buffer.offset_pointer(res)); + auto cipher = (CipherSuite)AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res)); res += 2; if (!supports_cipher(cipher)) { m_context.cipher = CipherSuite::Invalid; @@ -140,9 +142,9 @@ ssize_t TLSv12::handle_hello(const ByteBuffer& buffer, WritePacketStage& write_p } while ((ssize_t)buffer.size() - res >= 4) { - auto extension_type = (HandshakeExtension)convert_between_host_and_network(*(const u16*)buffer.offset_pointer(res)); + auto extension_type = (HandshakeExtension)AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res)); res += 2; - u16 extension_length = convert_between_host_and_network(*(const u16*)buffer.offset_pointer(res)); + u16 extension_length = AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res)); res += 2; #ifdef TLS_DEBUG @@ -156,7 +158,7 @@ ssize_t TLSv12::handle_hello(const ByteBuffer& buffer, WritePacketStage& write_p // SNI if (extension_type == HandshakeExtension::ServerName) { - u16 sni_host_length = convert_between_host_and_network(*(const u16*)buffer.offset_pointer(res + 3)); + u16 sni_host_length = AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res + 3)); if (buffer.size() - res - 5 < sni_host_length) { dbg() << "Not enough data for sni " << (buffer.size() - res - 5) << " < " << sni_host_length; return (i8)Error::NeedMoreData; @@ -168,7 +170,7 @@ ssize_t TLSv12::handle_hello(const ByteBuffer& buffer, WritePacketStage& write_p } } else if (extension_type == HandshakeExtension::ApplicationLayerProtocolNegotiation && m_context.alpn.size()) { if (buffer.size() - res > 2) { - auto alpn_length = convert_between_host_and_network(*(const u16*)buffer.offset_pointer(res)); + auto alpn_length = AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res)); if (alpn_length && alpn_length <= extension_length - 2) { const u8* alpn = buffer.offset_pointer(res + 2); size_t alpn_position = 0; @@ -267,7 +269,7 @@ void TLSv12::build_random(PacketBuilder& builder) dbg() << "Server mode not supported"; return; } else { - *(u16*)random_bytes = convert_between_host_and_network((u16)Version::V12); + *(u16*)random_bytes = AK::convert_between_host_and_network_endian((u16)Version::V12); } m_context.premaster_key = ByteBuffer::copy(random_bytes, bytes); diff --git a/Libraries/LibTLS/Record.cpp b/Libraries/LibTLS/Record.cpp index 59cf3c0cbe7..f061c5500ac 100644 --- a/Libraries/LibTLS/Record.cpp +++ b/Libraries/LibTLS/Record.cpp @@ -24,6 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #include #include #include @@ -56,7 +58,7 @@ void TLSv12::write_packet(ByteBuffer& packet) void TLSv12::update_packet(ByteBuffer& packet) { u32 header_size = 5; - *(u16*)packet.offset_pointer(3) = convert_between_host_and_network((u16)(packet.size() - header_size)); + *(u16*)packet.offset_pointer(3) = AK::convert_between_host_and_network_endian((u16)(packet.size() - header_size)); if (packet[0] != (u8)MessageType::ChangeCipher) { if (packet[0] == (u8)MessageType::Handshake && packet.size() > header_size) { @@ -120,7 +122,7 @@ void TLSv12::update_packet(ByteBuffer& packet) // store the correct ciphertext length into the packet u16 ct_length = (u16)ct.size() - header_size; - *(u16*)ct.offset_pointer(header_size - 2) = convert_between_host_and_network(ct_length); + *(u16*)ct.offset_pointer(header_size - 2) = AK::convert_between_host_and_network_endian(ct_length); // replace the packet with the ciphertext packet = ct; @@ -137,7 +139,7 @@ void TLSv12::update_hash(const ByteBuffer& message) ByteBuffer TLSv12::hmac_message(const ReadonlyBytes& buf, const Optional buf2, size_t mac_length, bool local) { - u64 sequence_number = convert_between_host_and_network(local ? m_context.local_sequence_number : m_context.remote_sequence_number); + u64 sequence_number = AK::convert_between_host_and_network_endian(local ? m_context.local_sequence_number : m_context.remote_sequence_number); ensure_hmac(mac_length, local); auto& hmac = local ? *m_hmac_local : *m_hmac_remote; #ifdef TLS_DEBUG @@ -185,7 +187,7 @@ ssize_t TLSv12::handle_message(const ByteBuffer& buffer) #endif buffer_position += 2; - auto length = convert_between_host_and_network(*(const u16*)buffer.offset_pointer(buffer_position)); + auto length = AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(buffer_position)); #ifdef TLS_DEBUG dbg() << "record length: " << length << " at offset: " << buffer_position; #endif @@ -238,7 +240,7 @@ ssize_t TLSv12::handle_message(const ByteBuffer& buffer) const u8* message_hmac = decrypted_span.offset(length); u8 temp_buf[5]; memcpy(temp_buf, buffer.offset_pointer(0), 3); - *(u16*)(temp_buf + 3) = convert_between_host_and_network(length); + *(u16*)(temp_buf + 3) = AK::convert_between_host_and_network_endian(length); auto hmac = hmac_message({ temp_buf, 5 }, decrypted_span.slice(0, length), mac_size); auto message_mac = ByteBuffer::wrap(const_cast(message_hmac), mac_size); if (hmac != message_mac) { diff --git a/Libraries/LibTLS/TLSPacketBuilder.h b/Libraries/LibTLS/TLSPacketBuilder.h index b7f9bc26c2c..b521f947a43 100644 --- a/Libraries/LibTLS/TLSPacketBuilder.h +++ b/Libraries/LibTLS/TLSPacketBuilder.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include namespace TLS { @@ -57,12 +58,12 @@ public: m_packet_data = ByteBuffer::create_uninitialized(size_hint + 16); m_current_length = 5; m_packet_data[0] = (u8)type; - *(u16*)m_packet_data.offset_pointer(1) = convert_between_host_and_network((u16)version); + *(u16*)m_packet_data.offset_pointer(1) = AK::convert_between_host_and_network_endian((u16)version); } inline void append(u16 value) { - value = convert_between_host_and_network(value); + value = AK::convert_between_host_and_network_endian(value); append((const u8*)&value, sizeof(value)); } inline void append(u8 value) @@ -115,4 +116,5 @@ private: ByteBuffer m_packet_data; size_t m_current_length; }; + } diff --git a/Libraries/LibTLS/TLSv12.cpp b/Libraries/LibTLS/TLSv12.cpp index 7924762b991..13bf311d6b6 100644 --- a/Libraries/LibTLS/TLSv12.cpp +++ b/Libraries/LibTLS/TLSv12.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -539,7 +540,7 @@ void TLSv12::consume(const ByteBuffer& record) dbg() << "message buffer length " << buffer_length; #endif while (buffer_length >= 5) { - auto length = convert_between_host_and_network(*(u16*)m_context.message_buffer.offset_pointer(index + size_offset)) + header_size; + auto length = AK::convert_between_host_and_network_endian(*(u16*)m_context.message_buffer.offset_pointer(index + size_offset)) + header_size; if (length > buffer_length) { #ifdef TLS_DEBUG dbg() << "Need more data: " << length << " | " << buffer_length; diff --git a/Services/DHCPClient/DHCPv4.h b/Services/DHCPClient/DHCPv4.h index 07c5787f8a0..1a1dfd8aa1d 100644 --- a/Services/DHCPClient/DHCPv4.h +++ b/Services/DHCPClient/DHCPv4.h @@ -28,10 +28,10 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -126,14 +126,14 @@ enum class DHCPMessageType : u8 { DHCPRelease, }; -template <> +template<> struct AK::Traits : public AK::GenericTraits { static constexpr bool is_trivial() { return true; } static unsigned hash(DHCPOption u) { return int_hash((u8)u); } }; struct ParsedDHCPv4Options { - template + template Optional get(DHCPOption option_name) const { auto option = options.get(option_name); @@ -146,7 +146,7 @@ struct ParsedDHCPv4Options { return *(const T*)value.value; } - template + template Vector get_many(DHCPOption option_name, size_t max_number) const { Vector values; diff --git a/Services/DHCPClient/DHCPv4Client.cpp b/Services/DHCPClient/DHCPv4Client.cpp index 8b8e6b228c1..355c03dc7b7 100644 --- a/Services/DHCPClient/DHCPv4Client.cpp +++ b/Services/DHCPClient/DHCPv4Client.cpp @@ -26,6 +26,7 @@ #include "DHCPv4Client.h" #include +#include #include #include #include @@ -163,7 +164,7 @@ void DHCPv4Client::handle_ack(const DHCPv4Packet& packet, const ParsedDHCPv4Opti transaction->has_ip = true; auto& interface = transaction->interface; auto new_ip = packet.yiaddr(); - auto lease_time = convert_between_host_and_network(options.get(DHCPOption::IPAddressLeaseTime).value_or(transaction->offered_lease_time)); + auto lease_time = AK::convert_between_host_and_network_endian(options.get(DHCPOption::IPAddressLeaseTime).value_or(transaction->offered_lease_time)); // set a timer for the duration of the lease, we shall renew if needed Core::Timer::create_single_shot( lease_time * 1000, diff --git a/Services/LookupServer/DNSPacket.h b/Services/LookupServer/DNSPacket.h index 832de9b7bbb..fce73037c82 100644 --- a/Services/LookupServer/DNSPacket.h +++ b/Services/LookupServer/DNSPacket.h @@ -26,7 +26,7 @@ #pragma once -#include +#include #include class [[gnu::packed]] DNSPacket