[PATCH] D67230: Remove call to obsolete gethostbyname, using getaddrinfo
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 04:07:00 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371195: Remove call to obsolete gethostbyname, using getaddrinfo (authored by serge_sans_paille, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D67230?vs=218940&id=219060#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67230/new/
https://reviews.llvm.org/D67230
Files:
lldb/trunk/source/Host/posix/HostInfoPosix.cpp
Index: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
===================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp
@@ -32,10 +32,16 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67230.219060.patch
Type: text/x-patch
Size: 904 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190906/06f9fa82/attachment.bin>
More information about the llvm-commits
mailing list