Documented and improved DNS::Resolve. Readme has been adjusted to changes.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user