Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <AK/NetworkOrdered.h>
30#include <Kernel/Net/EtherType.h>
31#include <Kernel/Net/IPv4.h>
32#include <Kernel/Net/MACAddress.h>
33
34namespace Kernel {
35
36struct ARPOperation {
37 enum : u16 {
38 Request = 1,
39 Response = 2,
40 };
41};
42
43struct ARPHardwareType {
44 enum : u16 {
45 Ethernet = 1,
46 };
47};
48
49class [[gnu::packed]] ARPPacket
50{
51public:
52 u16 hardware_type() const { return m_hardware_type; }
53 void set_hardware_type(u16 w) { m_hardware_type = w; }
54
55 u16 protocol_type() const { return m_protocol_type; }
56 void set_protocol_type(u16 w) { m_protocol_type = w; }
57
58 u8 hardware_address_length() const { return m_hardware_address_length; }
59 void set_hardware_address_length(u8 b) { m_hardware_address_length = b; }
60
61 u8 protocol_address_length() const { return m_protocol_address_length; }
62 void set_protocol_address_length(u8 b) { m_protocol_address_length = b; }
63
64 u16 operation() const { return m_operation; }
65 void set_operation(u16 w) { m_operation = w; }
66
67 const MACAddress& sender_hardware_address() const { return m_sender_hardware_address; }
68 void set_sender_hardware_address(const MACAddress& address) { m_sender_hardware_address = address; }
69
70 const IPv4Address& sender_protocol_address() const { return m_sender_protocol_address; }
71 void set_sender_protocol_address(const IPv4Address& address) { m_sender_protocol_address = address; }
72
73 const MACAddress& target_hardware_address() const { return m_target_hardware_address; }
74 void set_target_hardware_address(const MACAddress& address) { m_target_hardware_address = address; }
75
76 const IPv4Address& target_protocol_address() const { return m_target_protocol_address; }
77 void set_target_protocol_address(const IPv4Address& address) { m_target_protocol_address = address; }
78
79private:
80 NetworkOrdered<u16> m_hardware_type { ARPHardwareType::Ethernet };
81 NetworkOrdered<u16> m_protocol_type { EtherType::IPv4 };
82 u8 m_hardware_address_length { sizeof(MACAddress) };
83 u8 m_protocol_address_length { sizeof(IPv4Address) };
84 NetworkOrdered<u16> m_operation;
85 MACAddress m_sender_hardware_address;
86 IPv4Address m_sender_protocol_address;
87 MACAddress m_target_hardware_address;
88 IPv4Address m_target_protocol_address;
89};
90
91static_assert(sizeof(ARPPacket) == 28);
92
93}