Documented and improved DNS::Resolve. Readme has been adjusted to changes.

This commit is contained in:
2024-02-01 17:24:38 -08:00
parent beaa7cb034
commit e48a3fd750
4 changed files with 14 additions and 37 deletions

View File

@@ -8,8 +8,6 @@ ehs::Int_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer
*appVerId = "Release";
*appVer = {1, 0, 0};
ehs::Console::Attach();
ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8();
if (args.Size() > 1)

View File

@@ -12,7 +12,7 @@
namespace ehs
{
Str_8 DNS::Resolve(const AddrType addrType, const Str_8& hostName)
Str_8 DNS::Resolve(const Str_8& hostname)
{
#if defined(EHS_OS_WINDOWS)
WSADATA data = {};
@@ -25,15 +25,9 @@ namespace ehs
}
#endif
addrinfo hints = {};
if (addrType == AddrType::IPV6)
hints.ai_family = AF_INET6;
else if (addrType == AddrType::IPV4)
hints.ai_family = AF_INET;
addrinfo* result = nullptr;
Int_32 code = getaddrinfo(hostName, nullptr, &hints, &result);
Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result);
if (code)
{
EHS_LOG_INT("Error", 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
@@ -49,22 +43,26 @@ namespace ehs
#endif
if (addrType == AddrType::IPV6)
if (result->ai_family == AF_INET6)
{
Char_8 ipResult[INET6_ADDRSTRLEN];
Str_8 ipResult(INET6_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
return ipResult;
}
else if (addrType == AddrType::IPV4)
else if (result->ai_family == AF_INET)
{
Char_8 ipResult[INET_ADDRSTRLEN];
Str_8 ipResult(INET_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
return ipResult;