mirror of
https://github.com/RGBCube/serenity
synced 2025-05-26 01:35:08 +00:00
Kernel: Add a simple MACAddress class.
This commit is contained in:
parent
405413c354
commit
4641ee49b5
4 changed files with 32 additions and 8 deletions
|
@ -57,7 +57,7 @@ E1000NetworkAdapter::E1000NetworkAdapter(PCI::Address pci_address, byte irq)
|
|||
detect_eeprom();
|
||||
kprintf("E1000: Has EEPROM? %u\n", m_has_eeprom);
|
||||
read_mac_address();
|
||||
auto* mac = mac_address();
|
||||
const auto& mac = mac_address();
|
||||
kprintf("E1000: MAC address: %b:%b:%b:%b:%b:%b\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
enable_irq();
|
||||
}
|
||||
|
|
27
Kernel/MACAddress.h
Normal file
27
Kernel/MACAddress.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/StdLib.h>
|
||||
|
||||
class MACAddress {
|
||||
public:
|
||||
MACAddress() { }
|
||||
MACAddress(const byte data[6])
|
||||
: m_valid(true)
|
||||
{
|
||||
memcpy(m_data, data, 6);
|
||||
}
|
||||
~MACAddress() { }
|
||||
|
||||
bool is_valid() const { return m_valid; }
|
||||
byte operator[](int i) const
|
||||
{
|
||||
ASSERT(i >= 0 && i < 6);
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
private:
|
||||
byte m_data[6];
|
||||
bool m_valid { false };
|
||||
};
|
|
@ -10,7 +10,3 @@ NetworkAdapter::~NetworkAdapter()
|
|||
{
|
||||
}
|
||||
|
||||
void NetworkAdapter::set_mac_address(const byte* mac_address)
|
||||
{
|
||||
memcpy(m_mac_address, mac_address, 6);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/MACAddress.h>
|
||||
|
||||
class NetworkAdapter {
|
||||
public:
|
||||
virtual ~NetworkAdapter();
|
||||
|
||||
virtual const char* class_name() const = 0;
|
||||
const byte* mac_address() { return m_mac_address; }
|
||||
MACAddress mac_address() { return m_mac_address; }
|
||||
|
||||
protected:
|
||||
NetworkAdapter();
|
||||
void set_mac_address(const byte*);
|
||||
void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; }
|
||||
|
||||
private:
|
||||
byte m_mac_address[6];
|
||||
MACAddress m_mac_address;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue