ARP.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include <Kernel/Net/EtherType.h>
  10. #include <Kernel/Net/IPv4.h>
  11. namespace Kernel {
  12. struct ARPOperation {
  13. enum : u16 {
  14. Request = 1,
  15. Response = 2,
  16. };
  17. };
  18. struct ARPHardwareType {
  19. enum : u16 {
  20. Ethernet = 1,
  21. };
  22. };
  23. class [[gnu::packed]] ARPPacket {
  24. public:
  25. u16 hardware_type() const { return m_hardware_type; }
  26. void set_hardware_type(u16 w) { m_hardware_type = w; }
  27. u16 protocol_type() const { return m_protocol_type; }
  28. void set_protocol_type(u16 w) { m_protocol_type = w; }
  29. u8 hardware_address_length() const { return m_hardware_address_length; }
  30. void set_hardware_address_length(u8 b) { m_hardware_address_length = b; }
  31. u8 protocol_address_length() const { return m_protocol_address_length; }
  32. void set_protocol_address_length(u8 b) { m_protocol_address_length = b; }
  33. u16 operation() const { return m_operation; }
  34. void set_operation(u16 w) { m_operation = w; }
  35. const MACAddress& sender_hardware_address() const { return m_sender_hardware_address; }
  36. void set_sender_hardware_address(const MACAddress& address) { m_sender_hardware_address = address; }
  37. const IPv4Address& sender_protocol_address() const { return m_sender_protocol_address; }
  38. void set_sender_protocol_address(const IPv4Address& address) { m_sender_protocol_address = address; }
  39. const MACAddress& target_hardware_address() const { return m_target_hardware_address; }
  40. void set_target_hardware_address(const MACAddress& address) { m_target_hardware_address = address; }
  41. const IPv4Address& target_protocol_address() const { return m_target_protocol_address; }
  42. void set_target_protocol_address(const IPv4Address& address) { m_target_protocol_address = address; }
  43. private:
  44. NetworkOrdered<u16> m_hardware_type { ARPHardwareType::Ethernet };
  45. NetworkOrdered<u16> m_protocol_type { EtherType::IPv4 };
  46. u8 m_hardware_address_length { sizeof(MACAddress) };
  47. u8 m_protocol_address_length { sizeof(IPv4Address) };
  48. NetworkOrdered<u16> m_operation;
  49. MACAddress m_sender_hardware_address;
  50. IPv4Address m_sender_protocol_address;
  51. MACAddress m_target_hardware_address;
  52. IPv4Address m_target_protocol_address;
  53. };
  54. static_assert(sizeof(ARPPacket) == 28);
  55. }