mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-18 00:09:44 +00:00
LibCore: Use System::getaddrinfo()
in Socket::resolve_host
This commit is contained in:
parent
687ef7740a
commit
048d0a9870
Notes:
sideshowbarker
2024-07-17 04:34:25 +09:00
Author: https://github.com/LucasChollet
Commit: 048d0a9870
Pull-request: https://github.com/SerenityOS/serenity/pull/16383
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/MacDue
Reviewed-by: https://github.com/linusg ✅
Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 5 additions and 17 deletions
|
@ -367,24 +367,12 @@ ErrorOr<IPv4Address> Socket::resolve_host(DeprecatedString const& host, SocketTy
|
|||
hints.ai_flags = 0;
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
// FIXME: Convert this to Core::System
|
||||
struct addrinfo* results = nullptr;
|
||||
int rc = getaddrinfo(host.characters(), nullptr, &hints, &results);
|
||||
if (rc != 0) {
|
||||
if (rc == EAI_SYSTEM) {
|
||||
return Error::from_syscall("getaddrinfo"sv, -errno);
|
||||
}
|
||||
auto const results = TRY(Core::System::getaddrinfo(host.characters(), nullptr, hints));
|
||||
|
||||
auto const* error_string = gai_strerror(rc);
|
||||
return Error::from_string_view({ error_string, strlen(error_string) });
|
||||
}
|
||||
|
||||
ScopeGuard free_results = [results] { freeaddrinfo(results); };
|
||||
|
||||
for (auto* result = results; result != nullptr; result = result->ai_next) {
|
||||
if (result->ai_family == AF_INET) {
|
||||
auto* socket_address = bit_cast<struct sockaddr_in*>(result->ai_addr);
|
||||
NetworkOrdered<u32> network_ordered_address { socket_address->sin_addr.s_addr };
|
||||
for (auto const& result : results.addresses()) {
|
||||
if (result.ai_family == AF_INET) {
|
||||
auto* socket_address = bit_cast<struct sockaddr_in*>(result.ai_addr);
|
||||
NetworkOrdered<u32> const network_ordered_address { socket_address->sin_addr.s_addr };
|
||||
return IPv4Address { network_ordered_address };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue