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; }
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; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits