AuroraRuntime/Source/IO/Net/AuNetSrvInterfaces.cpp

62 lines
1.6 KiB
C++

/***
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(NetSrvInterfaces::gLock);
if (NetSrvInterfaces::bShouldUpdateCache)
{
UpdateCache();
}
return NetSrvInterfaces::gHostname;
}
void NetSrvInterfaces::ResetAdapterCache()
{
AU_LOCK_GUARD(NetSrvInterfaces::gLock);
NetSrvInterfaces::bShouldUpdateCache = true;
}
void NetSrvInterfaces::UpdateCache()
{
NetSrvInterfaces::gHostname = NetAdapter::GetHostname();
auto ipv4s = NetAdapter::GetIPv4s();
auto ipv6s = NetAdapter::GetIPv6s();
NetSrvInterfaces::gAdapters.clear();
NetSrvInterfaces::gAdapters.insert(NetSrvInterfaces::gAdapters.end(), ipv4s.begin(), ipv4s.end());
NetSrvInterfaces::gAdapters.insert(NetSrvInterfaces::gAdapters.end(), ipv6s.begin(), ipv6s.end());
}
AuList<AuSPtr<INetAdapter>> NetSrvInterfaces::GetAdapters()
{
AU_LOCK_GUARD(NetSrvInterfaces::gLock);
if (this->bShouldUpdateCache)
{
UpdateCache();
}
return this->NetSrvInterfaces::gAdapters;
}
bool NetSrvInterfaces::IsSupportedOnOS()
{
#if defined(AURORA_PLATFORM_WIN32)
return true;
#endif
#if defined(AURORA_PLATFORM_LINUX)
return true;
#endif
return false;
}
}