UDP.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <Kernel/Net/IPv4.h>
  8. namespace Kernel {
  9. class [[gnu::packed]] UDPPacket {
  10. public:
  11. UDPPacket() = default;
  12. ~UDPPacket() = default;
  13. u16 source_port() const { return m_source_port; }
  14. void set_source_port(u16 port) { m_source_port = port; }
  15. u16 destination_port() const { return m_destination_port; }
  16. void set_destination_port(u16 port) { m_destination_port = port; }
  17. u16 length() const { return m_length; }
  18. void set_length(u16 length) { m_length = length; }
  19. u16 checksum() const { return m_checksum; }
  20. void set_checksum(u16 checksum) { m_checksum = checksum; }
  21. const void* payload() const { return this + 1; }
  22. void* payload() { return this + 1; }
  23. private:
  24. NetworkOrdered<u16> m_source_port;
  25. NetworkOrdered<u16> m_destination_port;
  26. NetworkOrdered<u16> m_length;
  27. NetworkOrdered<u16> m_checksum;
  28. };
  29. static_assert(sizeof(UDPPacket) == 8);
  30. }