EthernetFrameHeader.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/Endian.h>
  8. #include <AK/MACAddress.h>
  9. #pragma GCC diagnostic ignored "-Warray-bounds"
  10. class [[gnu::packed]] EthernetFrameHeader {
  11. public:
  12. EthernetFrameHeader() = default;
  13. ~EthernetFrameHeader() = default;
  14. MACAddress destination() const { return m_destination; }
  15. void set_destination(const MACAddress& address) { m_destination = address; }
  16. MACAddress source() const { return m_source; }
  17. void set_source(const MACAddress& address) { m_source = address; }
  18. u16 ether_type() const { return m_ether_type; }
  19. void set_ether_type(u16 ether_type) { m_ether_type = ether_type; }
  20. const void* payload() const { return &m_payload[0]; }
  21. void* payload() { return &m_payload[0]; }
  22. private:
  23. MACAddress m_destination;
  24. MACAddress m_source;
  25. NetworkOrdered<u16> m_ether_type;
  26. u32 m_payload[0];
  27. };
  28. static_assert(sizeof(EthernetFrameHeader) == 14);