Codechange: [Network] Make hostname/client IP return strings instead of a C-string
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
* IPv4 dotted representation is given.
|
||||
* @return the hostname
|
||||
*/
|
||||
const char *NetworkAddress::GetHostname()
|
||||
const std::string &NetworkAddress::GetHostname()
|
||||
{
|
||||
if (this->hostname.empty() && this->address.ss_family != AF_UNSPEC) {
|
||||
assert(this->address_length != 0);
|
||||
@@ -27,7 +27,7 @@ const char *NetworkAddress::GetHostname()
|
||||
getnameinfo((struct sockaddr *)&this->address, this->address_length, buffer, sizeof(buffer), nullptr, 0, NI_NUMERICHOST);
|
||||
this->hostname = buffer;
|
||||
}
|
||||
return this->hostname.c_str();
|
||||
return this->hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -88,7 +88,7 @@ public:
|
||||
this->SetPort(port);
|
||||
}
|
||||
|
||||
const char *GetHostname();
|
||||
const std::string &GetHostname();
|
||||
std::string GetAddressAsString(bool with_family = true);
|
||||
const sockaddr_storage *GetAddress();
|
||||
|
||||
|
@@ -183,7 +183,7 @@ void TCPConnecter::Resolve()
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
|
||||
addrinfo *ai;
|
||||
int error = getaddrinfo(address.GetHostname(), port_name, &hints, &ai);
|
||||
int error = getaddrinfo(address.GetHostname().c_str(), port_name, &hints, &ai);
|
||||
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
|
||||
|
Reference in New Issue
Block a user