diff options
author | Fabian Dellwing <fabian.dellwing@gmail.com> | 2023-04-14 14:20:47 +0200 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-07 11:55:58 +0200 |
commit | 2efdac9441016a9016abdfcc9d2377c8b44dafae (patch) | |
tree | 5d57feced349d44f3ef29fe28cb9c201423fcef9 | |
parent | 4637d020c3bed24565e2d10b7267ef738e48d966 (diff) | |
download | serenity-2efdac9441016a9016abdfcc9d2377c8b44dafae.zip |
netstat: Fix port numbers not showing
Some change in our JsonObject API broke the logic here. We now read
the correct type from the JsonObject and convert it to a string ourself.
-rw-r--r-- | Userland/Utilities/netstat.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Userland/Utilities/netstat.cpp b/Userland/Utilities/netstat.cpp index f8110a922e..58a43005b8 100644 --- a/Userland/Utilities/netstat.cpp +++ b/Userland/Utilities/netstat.cpp @@ -114,14 +114,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } }; - auto get_formatted_address = [&](DeprecatedString const& address, DeprecatedString const& port) { + auto get_formatted_address = [&](DeprecatedString const& address, String const& port) { if (flag_wide) return DeprecatedString::formatted("{}:{}", address, port); - if ((address.length() + port.length()) <= max_formatted_address_length) + if ((address.length() + port.bytes().size()) <= max_formatted_address_length) return DeprecatedString::formatted("{}:{}", address, port); - return DeprecatedString::formatted("{}:{}", address.substring_view(0, max_formatted_address_length - port.length()), port); + return DeprecatedString::formatted("{}:{}", address.substring_view(0, max_formatted_address_length - port.bytes().size()), port); }; auto get_formatted_program = [&](pid_t pid) { @@ -186,13 +186,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } } - auto peer_port = if_object.get_deprecated_string("peer_port"sv).value_or({}); + auto peer_port = TRY(String::number(if_object.get_u32("peer_port"sv).value_or({}))); if (!flag_numeric) { auto service = getservbyport(htons(if_object.get_u32("peer_port"sv).value_or(0)), "tcp"); if (service != nullptr) { auto s_name = StringView { service->s_name, strlen(service->s_name) }; if (!s_name.is_empty()) - peer_port = s_name; + peer_port = TRY(String::from_utf8(s_name)); } } @@ -208,13 +208,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } } - auto local_port = if_object.get_deprecated_string("local_port"sv).value_or({}); + auto local_port = TRY(String::number(if_object.get_u32("local_port"sv).value_or({}))); if (!flag_numeric) { auto service = getservbyport(htons(if_object.get_u32("local_port"sv).value_or(0)), "tcp"); if (service != nullptr) { auto s_name = StringView { service->s_name, strlen(service->s_name) }; if (!s_name.is_empty()) - local_port = s_name; + local_port = TRY(String::from_utf8(s_name)); } } @@ -270,13 +270,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } } - auto local_port = if_object.get_deprecated_string("local_port"sv).value_or({}); + auto local_port = TRY(String::number(if_object.get_u32("local_port"sv).value_or({}))); if (!flag_numeric) { auto service = getservbyport(htons(if_object.get_u32("local_port"sv).value_or(0)), "udp"); if (service != nullptr) { auto s_name = StringView { service->s_name, strlen(service->s_name) }; if (!s_name.is_empty()) - local_port = s_name; + local_port = TRY(String::from_utf8(s_name)); } } @@ -292,13 +292,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } } - auto peer_port = if_object.get_deprecated_string("peer_port"sv).value_or({}); + auto peer_port = TRY(String::number(if_object.get_u32("peer_port"sv).value_or({}))); if (!flag_numeric) { auto service = getservbyport(htons(if_object.get_u32("peer_port"sv).value_or(0)), "udp"); if (service != nullptr) { auto s_name = StringView { service->s_name, strlen(service->s_name) }; if (!s_name.is_empty()) - peer_port = s_name; + peer_port = TRY(String::from_utf8(s_name)); } } |