ICMP.h 1.1 KB

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