[*] INetAdapter refactor: lets not assume all adapters have IP addresses

This commit is contained in:
Reece Wilson 2024-04-14 20:11:08 +01:00
parent 971b007ab9
commit 528cb01679
4 changed files with 40 additions and 30 deletions

View File

@ -24,11 +24,11 @@ namespace Aurora::IO::Net
virtual EIPProtocol GetFamily() = 0;
virtual const IPAddress &GetAddress() = 0;
virtual const IPAddress &GetBroadcastAddress() = 0;
virtual const IPAddress &GetAnycastAddress() = 0;
virtual const IPAddress &GetSubnetMask() = 0;
virtual const IPAddress &GetGateway() = 0;
virtual AuOptional<const IPAddress &> GetAddress() = 0;
virtual AuOptional<const IPAddress &> GetBroadcastAddress() = 0;
virtual AuOptional<const IPAddress &> GetAnycastAddress() = 0;
virtual AuOptional<const IPAddress &> GetSubnetMask() = 0;
virtual AuOptional<const IPAddress &> GetGateway() = 0;
virtual AuArray<AuUInt8, 8> GetMacAddress() = 0;

View File

@ -239,7 +239,7 @@ namespace Aurora::IO::Net
adapter.uReceiveBytesPerSec = pCurrAddresses->ReceiveLinkSpeed / 8;
}
if (adapter.address.ip == EIPProtocol::eIPProtocolV4)
if (adapter.address.Value().ip == EIPProtocol::eIPProtocolV4)
{
adapter.index = pCurrAddresses->IfIndex;
}

View File

@ -16,11 +16,6 @@ namespace Aurora::IO::Net
return this->name.empty() ? this->device : this->name;
}
const IPAddress &NetAdapter::GetSubnetMask()
{
return this->subnet;
}
const AuString &NetAdapter::GetDevice()
{
return this->device;
@ -38,7 +33,7 @@ namespace Aurora::IO::Net
EIPProtocol NetAdapter::GetFamily()
{
return this->address.ip;
return this->address.ValueOr(IPAddress {}).ip;
}
AuUInt16 NetAdapter::GetIndex()
@ -46,24 +41,39 @@ namespace Aurora::IO::Net
return this->index;
}
const IPAddress &NetAdapter::GetAddress()
AuOptional<const IPAddress &> NetAdapter::GetAddress()
{
return this->address;
return this->address ?
this->address.Value() :
AuOptional<const IPAddress &> {};
}
const IPAddress &NetAdapter::GetBroadcastAddress()
AuOptional<const IPAddress &> NetAdapter::GetBroadcastAddress()
{
return this->broadcast;
return this->broadcast ?
this->broadcast.Value() :
AuOptional<const IPAddress &> {};
}
const IPAddress &NetAdapter::GetAnycastAddress()
AuOptional<const IPAddress &> NetAdapter::GetAnycastAddress()
{
return this->anycast;
return this->anycast ?
this->anycast.Value() :
AuOptional<const IPAddress &> {};
}
const IPAddress &NetAdapter::GetGateway()
AuOptional<const IPAddress &> NetAdapter::GetGateway()
{
return this->gateway;
return this->gateway ?
this->gateway.Value() :
AuOptional<const IPAddress &> {};
}
AuOptional<const IPAddress &> NetAdapter::GetSubnetMask()
{
return this->subnet ?
this->subnet.Value() :
AuOptional<const IPAddress &> {};
}
const AuList<IPAddress> &NetAdapter::GetDNS()

View File

@ -21,11 +21,11 @@ namespace Aurora::IO::Net
EAdapterType GetAdapterType() override;
EAdapterStatus GetAdapterStatus() override;
const IPAddress &GetAddress() override;
const IPAddress &GetBroadcastAddress() override;
const IPAddress &GetAnycastAddress() override;
const IPAddress &GetSubnetMask() override;
const IPAddress &GetGateway() override;
AuOptional<const IPAddress &> GetAddress() override;
AuOptional<const IPAddress &> GetBroadcastAddress() override;
AuOptional<const IPAddress &> GetAnycastAddress() override;
AuOptional<const IPAddress &> GetSubnetMask() override;
AuOptional<const IPAddress &> GetGateway() override;
const AuList<IPAddress> &GetDNS() override;
@ -46,11 +46,11 @@ namespace Aurora::IO::Net
AuString name;
AuString device;
IPAddress address;
IPAddress broadcast;
IPAddress anycast;
IPAddress subnet;
IPAddress gateway;
AuOptional<IPAddress> address;
AuOptional<IPAddress> broadcast;
AuOptional<IPAddress> anycast;
AuOptional<IPAddress> subnet;
AuOptional<IPAddress> gateway;
EAdapterType eNetworkType { EAdapterType::eUnknown };
EAdapterStatus eNetworkStatus { EAdapterStatus::eUp };
bool dhcp {};