mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-30 05:05:10 +00:00
Utilities/nc: Don't use LibC gethostbyname function
Instead, let's use the nicer Core::Socket API and resolve the hostname this way.
This commit is contained in:
parent
1df32b7e1a
commit
dcf7296929
|
@ -151,12 +151,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
dst_addr.sin_port = htons(port);
|
||||
|
||||
if (!numeric_mode) {
|
||||
auto* hostent = gethostbyname(target.characters());
|
||||
if (!hostent) {
|
||||
auto address_or_error = Core::Socket::resolve_host(target, Core::Socket::SocketType::Stream);
|
||||
if (address_or_error.is_error()) {
|
||||
warnln("nc: Unable to resolve '{}'", target);
|
||||
return 1;
|
||||
}
|
||||
dst_addr.sin_addr.s_addr = *(in_addr_t const*)hostent->h_addr_list[0];
|
||||
dst_addr.sin_addr.s_addr = address_or_error.release_value().to_u32();
|
||||
} else {
|
||||
if (inet_pton(AF_INET, target.characters(), &dst_addr.sin_addr) <= 0) {
|
||||
perror("inet_pton");
|
||||
|
|
Loading…
Reference in a new issue