Files
.github
.vscode
Architecture
Core
Execute
FileSystem
Files
GUI
Library
Network
Profiling
Recovery
SystemCalls
Tasking
Tests
include
boot
cpu
filesystem
net
arp.hpp
dhcp.hpp
dns.hpp
eth.hpp
icmpv4.hpp
icmpv6.hpp
ipv4.hpp
ipv6.hpp
nc.hpp
net.hpp
ntp.hpp
tcp.hpp
udp.hpp
abi.h
assert.h
atomic.hpp
bitmap.hpp
cargs.h
convert.h
cpu.hpp
crc32.h
cstring
cwalk.h
debug.h
disk.hpp
display.hpp
driver.hpp
dumper.hpp
elf.h
exec.hpp
filesystem.hpp
gui.hpp
hashmap.hpp
intrin.hpp
ints.hpp
io.h
ipc.hpp
kconfig.hpp
limits.h
lock.hpp
md5.h
memory.hpp
msexec.h
pci.hpp
power.hpp
printf.h
rand.hpp
recovery.hpp
smartptr.hpp
smp.hpp
std.hpp
stddef.h
stdint.h
string.hpp
symbols.hpp
sys.h
syscalls.hpp
task.hpp
time.hpp
types.h
uart.hpp
vector.hpp
.gitignore
DAPI.hpp
Doxyfile
Fex.hpp
KConfig.cpp
KThread.cpp
Kernel.cpp
LICENSE
Makefile
README.md
dump.sh
ipc.h
kernel.h
syscalls.h
Kernel/include/net/arp.hpp

90 lines
2.2 KiB
C++

#ifndef __FENNIX_KERNEL_NETWORK_ARP_H__
#define __FENNIX_KERNEL_NETWORK_ARP_H__
#include <net/eth.hpp>
#include <net/nc.hpp>
#include <vector.hpp>
#include <types.h>
namespace NetworkARP
{
enum ARPOperation
{
REQUEST = 0x1,
REPLY = 0x2
};
enum ARPHardwareType
{
HTYPE_ETHERNET = 1,
HTYPE_802_3 = 6,
HTYPE_ARCNET = 7,
HTYPE_FRAME_RELAY = 15,
HTYPE_ATM = 16,
HTYPE_HDLC = 17,
HTYPE_FIBRE_CHANNEL = 18,
HTYPE_ATM_2 = 19,
HTYPE_SERIAL_LINE = 20
};
struct ARPHeader
{
uint16_t HardwareType;
uint16_t ProtocolType;
uint8_t HardwareSize;
uint8_t ProtocolSize;
uint16_t Operation;
uint48_t SenderMAC : 48;
uint32_t SenderIP;
uint48_t TargetMAC : 48;
uint32_t TargetIP;
} __attribute__((packed));
struct DiscoveredAddress
{
MediaAccessControl MAC;
InternetProtocol IP;
};
class ARP : public NetworkEthernet::EthernetEvents
{
private:
NetworkEthernet::Ethernet *Ethernet;
enum DAType
{
DA_ADD = 1,
DA_DEL = 2,
DA_SEARCH = 3,
DA_UPDATE = 4
};
Vector<NetworkARP::DiscoveredAddress *> DiscoveredAddresses;
DiscoveredAddress *ManageDiscoveredAddresses(DAType Type, InternetProtocol IP, MediaAccessControl MAC);
DiscoveredAddress *Search(InternetProtocol TargetIP);
DiscoveredAddress *Update(InternetProtocol TargetIP, MediaAccessControl TargetMAC);
bool OnEthernetPacketReceived(uint8_t *Data, uint64_t Length);
public:
ARP(NetworkEthernet::Ethernet *Ethernet);
~ARP();
/**
* @brief Resolve an IP address to a MAC address.
*
* @param IP The IP address to resolve. (Little-endian)
* @return uint48_t The MAC address of the IP address.
*/
uint48_t Resolve(InternetProtocol IP);
/**
* @brief Broadcast an ARP packet.
*
* @param IP The IP address to broadcast.
*/
void Broadcast(InternetProtocol IP);
};
}
#endif // !__FENNIX_KERNEL_NETWORK_ARP_H__