[Lldb-commits] [PATCH] D104856: [lldb] replace gethostbyname call by getaddrinfo

serge via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 24 06:25:00 PDT 2021


serge-sans-paille created this revision.
serge-sans-paille requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

According to the manpage

  The gethostbyname*() and gethostbyaddr*() functions are obsolete. Applications
  should use getaddrinfo(3) and getnameinfo(3) instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104856

Files:
  lldb/tools/debugserver/source/RNBSocket.cpp


Index: lldb/tools/debugserver/source/RNBSocket.cpp
===================================================================
--- lldb/tools/debugserver/source/RNBSocket.cpp
+++ lldb/tools/debugserver/source/RNBSocket.cpp
@@ -50,10 +50,9 @@
     if (inet_pton_result == 1)
       return true;
 
-    struct hostent *host_entry = gethostbyname(hostname);
-    if (host_entry) {
-      std::string ip_str(
-          ::inet_ntoa(*(struct in_addr *)*host_entry->h_addr_list));
+    struct addrinfo *addr = nullptr;
+    if (getaddrinfo(hostname, nullptr, 0, &addr) == 0) {
+      std::string ip_str(::inet_ntoa(addr->ai_addr->sin_addr);
       inet_pton_result = ::inet_pton(AF_INET, ip_str.c_str(), &addr);
       if (inet_pton_result == 1)
         return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104856.354235.patch
Type: text/x-patch
Size: 754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210624/5d6235f8/attachment.bin>


More information about the lldb-commits mailing list