Serenity Operating System
at master 51 lines 1.2 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/MACAddress.h> 10#include <Kernel/Net/IPv4.h> 11 12struct ICMPType { 13 enum { 14 EchoReply = 0, 15 EchoRequest = 8, 16 }; 17}; 18 19class [[gnu::packed]] ICMPHeader { 20public: 21 ICMPHeader() = default; 22 ~ICMPHeader() = default; 23 24 u8 type() const { return m_type; } 25 void set_type(u8 b) { m_type = b; } 26 27 u8 code() const { return m_code; } 28 void set_code(u8 b) { m_code = b; } 29 30 u16 checksum() const { return m_checksum; } 31 void set_checksum(u16 w) { m_checksum = w; } 32 33 void const* payload() const { return this + 1; } 34 void* payload() { return this + 1; } 35 36private: 37 u8 m_type { 0 }; 38 u8 m_code { 0 }; 39 NetworkOrdered<u16> m_checksum { 0 }; 40 // NOTE: The rest of the header is 4 bytes 41}; 42 43static_assert(AssertSize<ICMPHeader, 4>()); 44 45struct [[gnu::packed]] ICMPEchoPacket { 46 ICMPHeader header; 47 NetworkOrdered<u16> identifier; 48 NetworkOrdered<u16> sequence_number; 49 void* payload() { return this + 1; } 50 void const* payload() const { return this + 1; } 51};