[Lldb-commits] [PATCH] D104856: [lldb] replace gethostbyname call by getaddrinfo
Jan Kratochvil via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 24 07:33:46 PDT 2021
jankratochvil added a comment.
In D104856#2838571 <https://reviews.llvm.org/D104856#2838571>, @teemperor wrote:
> The file is part of `debugserver` which is Darwin exclusive and is also only compiled/used when you're on Darwin. It's also kind of its own thing: it isn't using LLVM libraries such as ADT and we usually leave it out of larger refactorings because it's kind of in "maintenance-only" mode IIRC.
I still do not understand what code can use this function on OSX and on OSX I build with `-DLLDB_USE_SYSTEM_DEBUGSERVER=ON` which probably won't build the new `lldb-server` then.
Besides that IMO @serge-sans-paille may not need to patch it when it is OSX-only function.
================
Comment at: lldb/tools/debugserver/source/RNBSocket.cpp:37
bool ResolveIPV4HostName(const char *hostname, in_addr_t &addr) {
if (hostname == NULL || hostname[0] == '\0' ||
----------------
jankratochvil wrote:
> `in
Here the prototype does not permit IPv6.
================
Comment at: lldb/tools/debugserver/source/RNBSocket.cpp:40
strcmp(hostname, "localhost") == 0 ||
strcmp(hostname, "127.0.0.1") == 0) {
addr = htonl(INADDR_LOOPBACK);
----------------
This is redundant with `getaddrinfo`.
================
Comment at: lldb/tools/debugserver/source/RNBSocket.cpp:48
// See if an IP address was specified as numbers
int inet_pton_result = ::inet_pton(AF_INET, hostname, &addr);
----------------
This is redundant with `getaddrinfo`.
================
Comment at: lldb/tools/debugserver/source/RNBSocket.cpp:56
+ 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)
----------------
Here it should use `((sockaddr_in *)addr->ai_addr)->sin_addr` after verifying it is an IPv4 address - instead of the `inet_ntoa+inet_pton` calls.
Also it should iterate all the addresses by `addr->ai_next` (which is not possible with the `ResolveIPV4HostName` function prototype).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104856/new/
https://reviews.llvm.org/D104856
More information about the lldb-commits
mailing list