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