[Lldb-commits] [lldb] r371195 - Remove call to obsolete gethostbyname, using getaddrinfo
Serge Guelton via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 6 04:06:24 PDT 2019
Author: serge_sans_paille
Date: Fri Sep 6 04:06:23 2019
New Revision: 371195
URL: http://llvm.org/viewvc/llvm-project?rev=371195&view=rev
Log:
Remove call to obsolete gethostbyname, using getaddrinfo
Differential Revision: https://reviews.llvm.org/D67230
Modified:
lldb/trunk/source/Host/posix/HostInfoPosix.cpp
Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=371195&r1=371194&r2=371195&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Fri Sep 6 04:06:23 2019
@@ -32,10 +32,16 @@ bool HostInfoPosix::GetHostname(std::str
char hostname[PATH_MAX];
hostname[sizeof(hostname) - 1] = '\0';
if (::gethostname(hostname, sizeof(hostname) - 1) == 0) {
- struct hostent *h = ::gethostbyname(hostname);
- if (h)
- s.assign(h->h_name);
- else
+ struct addrinfo hints;
+ struct addrinfo *res = nullptr;
+ std::memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_CANONNAME;
+ int err = ::getaddrinfo(hostname, nullptr, &hints, &res);
+ if (err == 0) {
+ assert(res->ai_canonname && "getaddrinfo found a canonical name");
+ s.assign(res->ai_canonname);
+ freeaddrinfo(res);
+ } else
s.assign(hostname);
return true;
}
More information about the lldb-commits
mailing list