[+] INetAdapter::ToMacAddress

[+] INetAdapter::HasDHCP
[+] INetAdapter::GetMTU
This commit is contained in:
Reece Wilson 2023-10-24 19:12:47 +01:00
parent 9092f9268c
commit ec8f3b3f23
5 changed files with 52 additions and 4 deletions

View File

@ -24,6 +24,12 @@ namespace Aurora::IO::Net
virtual IPAddress ToSubnetMask() = 0;
virtual IPAddress ToGateway() = 0;
virtual AuArray<AuUInt8, 8> ToMacAddress() = 0;
virtual bool HasDHCP() = 0;
virtual AuUInt32 GetMTU() = 0;
virtual AuList<IPAddress> GetDNS() = 0;
};
};

View File

@ -446,14 +446,23 @@ namespace Aurora::IO::Net
size_t dstlen = RTA_PAYLOAD(attr);
const size_t addrlen = (family == AF_INET) ? sizeof(struct in_addr) : sizeof(struct in6_addr);
if (attr->rta_type == IFLA_IFNAME)
{
adapter.device = (const char *)RTA_DATA(attr);
}
// TODO: we can pull MTU and other stats from here.
if (attr->rta_type == IFLA_MTU)
{
adapter.mtu = *(unsigned int *)RTA_DATA(attr);
}
if (attr->rta_type == IFLA_ADDRESS)
{
if (dstlen <= adapter.mac.size())
{
AuMemcpy(adapter.mac.begin(), (const char *)RTA_DATA(attr), dstlen);
}
}
}
}
}

View File

@ -148,6 +148,10 @@ namespace Aurora::IO::Net
adapter.device = pCurrAddresses->AdapterName;
adapter.name = AuLocale::ConvertFromWChar(pCurrAddresses->FriendlyName);
AuMemcpy(adapter.mac.begin(), pCurrAddresses->PhysicalAddress, pCurrAddresses->PhysicalAddressLength);
adapter.mtu = pCurrAddresses->Mtu;
auto pUnicast = pCurrAddresses->FirstUnicastAddress;
if (pUnicast)
{
@ -160,7 +164,7 @@ namespace Aurora::IO::Net
adapter.address = ep.ip;
}
auto pMulticast = pCurrAddresses->FirstMulticastAddress;
if (pMulticast)
{
@ -201,6 +205,8 @@ namespace Aurora::IO::Net
adapter.gateway = ep.ip;
}
adapter.dhcp = pCurrAddresses->Dhcpv4Enabled;
}
if (adapter.address.ip == EIPProtocol::eIPProtocolV4)
@ -269,6 +275,9 @@ namespace Aurora::IO::Net
for (auto &pAdapter : gIpv4Adapters)
{
auto pAdapterEx = AuStaticCast<NetAdapter>(pAdapter);
pAdapterEx->dhcp = pIPAddrTable->DhcpEnabled;
if (pAdapterEx->device == AuString(pIPAddrTable->AdapterName))
{
pAdapterEx->gateway = IPAddress(pIPAddrTable->GatewayList.IpAddress.String);

View File

@ -60,4 +60,19 @@ namespace Aurora::IO::Net
{
return this->dns;
}
AuArray<AuUInt8, 8> NetAdapter::ToMacAddress()
{
return this->mac;
}
bool NetAdapter::HasDHCP()
{
return this->dhcp;
}
AuUInt32 NetAdapter::GetMTU()
{
return this->mtu;
}
}

View File

@ -26,6 +26,12 @@ namespace Aurora::IO::Net
AuList<IPAddress> GetDNS() override;
AuArray<AuUInt8, 8> ToMacAddress() override;
bool HasDHCP() override;
AuUInt32 GetMTU() override;
// FriendlyName
static AuString GetHostname();
@ -40,6 +46,9 @@ namespace Aurora::IO::Net
IPAddress anycast;
IPAddress subnet;
IPAddress gateway;
bool dhcp {};
AuArray<AuUInt8, 8> mac;
AuUInt32 mtu;
AuList<IPAddress> dns;
AuUInt16 index {};