mirror of
https://github.com/RGBCube/serenity
synced 2025-07-07 08:37:34 +00:00
Kernel: Add a way to look up NetworkAdapters by IPv4 address.
This commit is contained in:
parent
c6a2012fe9
commit
8e667747f0
3 changed files with 36 additions and 13 deletions
|
@ -3,13 +3,39 @@
|
|||
#include <Kernel/EthernetFrameHeader.h>
|
||||
#include <Kernel/kmalloc.h>
|
||||
#include <Kernel/EtherType.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Lock.h>
|
||||
|
||||
static Lockable<HashTable<NetworkAdapter*>>& all_adapters()
|
||||
{
|
||||
static Lockable<HashTable<NetworkAdapter*>>* table;
|
||||
if (!table)
|
||||
table = new Lockable<HashTable<NetworkAdapter*>>;
|
||||
return *table;
|
||||
}
|
||||
|
||||
NetworkAdapter* NetworkAdapter::from_ipv4_address(const IPv4Address& address)
|
||||
{
|
||||
LOCKER(all_adapters().lock());
|
||||
for (auto* adapter : all_adapters().resource()) {
|
||||
if (adapter->ipv4_address() == address)
|
||||
return adapter;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NetworkAdapter::NetworkAdapter()
|
||||
{
|
||||
// FIXME: I wanna lock :(
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
all_adapters().resource().set(this);
|
||||
}
|
||||
|
||||
NetworkAdapter::~NetworkAdapter()
|
||||
{
|
||||
// FIXME: I wanna lock :(
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
all_adapters().resource().remove(this);
|
||||
}
|
||||
|
||||
void NetworkAdapter::send(const MACAddress& destination, const ARPPacket& packet)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue