From ec8f3b3f23e694fd92c916985906993132df20c4 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Tue, 24 Oct 2023 19:12:47 +0100 Subject: [PATCH] [+] INetAdapter::ToMacAddress [+] INetAdapter::HasDHCP [+] INetAdapter::GetMTU --- Include/Aurora/IO/Net/INetAdapter.hpp | 6 ++++++ Source/IO/Net/AuNetAdapter.Linux.cpp | 15 ++++++++++++--- Source/IO/Net/AuNetAdapter.NT.cpp | 11 ++++++++++- Source/IO/Net/AuNetAdapter.cpp | 15 +++++++++++++++ Source/IO/Net/AuNetAdapter.hpp | 9 +++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Include/Aurora/IO/Net/INetAdapter.hpp b/Include/Aurora/IO/Net/INetAdapter.hpp index eb3d5e8d..ec185147 100644 --- a/Include/Aurora/IO/Net/INetAdapter.hpp +++ b/Include/Aurora/IO/Net/INetAdapter.hpp @@ -24,6 +24,12 @@ namespace Aurora::IO::Net virtual IPAddress ToSubnetMask() = 0; virtual IPAddress ToGateway() = 0; + virtual AuArray ToMacAddress() = 0; + + virtual bool HasDHCP() = 0; + + virtual AuUInt32 GetMTU() = 0; + virtual AuList GetDNS() = 0; }; }; \ No newline at end of file diff --git a/Source/IO/Net/AuNetAdapter.Linux.cpp b/Source/IO/Net/AuNetAdapter.Linux.cpp index 2ca44e3b..7499da72 100644 --- a/Source/IO/Net/AuNetAdapter.Linux.cpp +++ b/Source/IO/Net/AuNetAdapter.Linux.cpp @@ -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); + } + } } } } diff --git a/Source/IO/Net/AuNetAdapter.NT.cpp b/Source/IO/Net/AuNetAdapter.NT.cpp index 2af45e18..58521821 100644 --- a/Source/IO/Net/AuNetAdapter.NT.cpp +++ b/Source/IO/Net/AuNetAdapter.NT.cpp @@ -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(pAdapter); + + pAdapterEx->dhcp = pIPAddrTable->DhcpEnabled; + if (pAdapterEx->device == AuString(pIPAddrTable->AdapterName)) { pAdapterEx->gateway = IPAddress(pIPAddrTable->GatewayList.IpAddress.String); diff --git a/Source/IO/Net/AuNetAdapter.cpp b/Source/IO/Net/AuNetAdapter.cpp index 9b1bcc04..3d34f15a 100644 --- a/Source/IO/Net/AuNetAdapter.cpp +++ b/Source/IO/Net/AuNetAdapter.cpp @@ -60,4 +60,19 @@ namespace Aurora::IO::Net { return this->dns; } + + AuArray NetAdapter::ToMacAddress() + { + return this->mac; + } + + bool NetAdapter::HasDHCP() + { + return this->dhcp; + } + + AuUInt32 NetAdapter::GetMTU() + { + return this->mtu; + } } \ No newline at end of file diff --git a/Source/IO/Net/AuNetAdapter.hpp b/Source/IO/Net/AuNetAdapter.hpp index dbd74098..893f4b8d 100644 --- a/Source/IO/Net/AuNetAdapter.hpp +++ b/Source/IO/Net/AuNetAdapter.hpp @@ -26,6 +26,12 @@ namespace Aurora::IO::Net AuList GetDNS() override; + AuArray 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 mac; + AuUInt32 mtu; AuList dns; AuUInt16 index {};