summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Guelton <sguelton@redhat.com>2019-09-06 11:06:23 +0000
committerSerge Guelton <sguelton@redhat.com>2019-09-06 11:06:23 +0000
commit90d32df7db51ec69bee38eedc4549976b7c52321 (patch)
treed6c2ad7757ac07b5b06432ec1966bae59bd16298
parent2ebd24cc136f9b2fdab4a00003b4ac0ffa1e2f37 (diff)
downloadbcm5719-llvm-90d32df7db51ec69bee38eedc4549976b7c52321.tar.gz
bcm5719-llvm-90d32df7db51ec69bee38eedc4549976b7c52321.zip
Remove call to obsolete gethostbyname, using getaddrinfo
Differential Revision: https://reviews.llvm.org/D67230 llvm-svn: 371195
-rw-r--r--lldb/source/Host/posix/HostInfoPosix.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp
index f300e22e9e5..78300fca034 100644
--- a/lldb/source/Host/posix/HostInfoPosix.cpp
+++ b/lldb/source/Host/posix/HostInfoPosix.cpp
@@ -32,10 +32,16 @@ bool HostInfoPosix::GetHostname(std::string &s) {
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;
}
OpenPOWER on IntegriCloud