2022-12-14 20:08:52 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuNetSrvInterfaces.cpp
|
|
|
|
Date: 2022-11-14
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include "Networking.hpp"
|
|
|
|
#include "AuNetSrvInterfaces.hpp"
|
|
|
|
#include "AuNetAdapter.hpp"
|
|
|
|
|
|
|
|
namespace Aurora::IO::Net
|
|
|
|
{
|
|
|
|
const AuString &NetSrvInterfaces::GetHostname()
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->lock);
|
|
|
|
if (this->bShouldUpdateCache)
|
|
|
|
{
|
|
|
|
UpdateCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
return hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetSrvInterfaces::ResetAdapterCache()
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->lock);
|
|
|
|
this->bShouldUpdateCache = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetSrvInterfaces::UpdateCache()
|
|
|
|
{
|
|
|
|
this->hostname = NetAdapter::GetHostname();
|
|
|
|
|
|
|
|
auto ipv4s = NetAdapter::GetIPv4s();
|
|
|
|
auto ipv6s = NetAdapter::GetIPv6s();
|
|
|
|
|
|
|
|
this->adapters.clear();
|
|
|
|
this->adapters.insert(this->adapters.end(), ipv4s.begin(), ipv4s.end());
|
|
|
|
this->adapters.insert(this->adapters.end(), ipv6s.begin(), ipv6s.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuSPtr<INetAdapter>> NetSrvInterfaces::GetAdapters()
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(this->lock);
|
|
|
|
if (this->bShouldUpdateCache)
|
|
|
|
{
|
|
|
|
UpdateCache();
|
|
|
|
}
|
|
|
|
return this->adapters;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetSrvInterfaces::IsSupportedOnOS()
|
|
|
|
{
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
#if defined(AURORA_PLATFORM_LINUX)
|
2022-12-17 13:57:00 +00:00
|
|
|
return true;
|
2022-12-14 20:08:52 +00:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|