summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/IPv4Address.h30
-rw-r--r--Kernel/GlobalProcessExposed.cpp27
2 files changed, 47 insertions, 10 deletions
diff --git a/AK/IPv4Address.h b/AK/IPv4Address.h
index 3df22ea34e..03a6f61cab 100644
--- a/AK/IPv4Address.h
+++ b/AK/IPv4Address.h
@@ -7,11 +7,18 @@
#pragma once
#include <AK/Endian.h>
+#include <AK/Format.h>
#include <AK/Optional.h>
-#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
+#ifdef KERNEL
+# include <AK/Error.h>
+# include <Kernel/KString.h>
+#else
+# include <AK/String.h>
+#endif
+
namespace AK {
class [[gnu::packed]] IPv4Address {
@@ -48,6 +55,16 @@ public:
return octet(SubnetClass(i));
}
+#ifdef KERNEL
+ ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const
+ {
+ return Kernel::KString::formatted("{}.{}.{}.{}",
+ octet(SubnetClass::A),
+ octet(SubnetClass::B),
+ octet(SubnetClass::C),
+ octet(SubnetClass::D));
+ }
+#else
String to_string() const
{
return String::formatted("{}.{}.{}.{}",
@@ -65,6 +82,7 @@ public:
octet(SubnetClass::B),
octet(SubnetClass::A));
}
+#endif
static Optional<IPv4Address> from_string(StringView string)
{
@@ -131,6 +149,15 @@ struct Traits<IPv4Address> : public GenericTraits<IPv4Address> {
static constexpr unsigned hash(const IPv4Address& address) { return int_hash(address.to_u32()); }
};
+#ifdef KERNEL
+template<>
+struct Formatter<IPv4Address> : Formatter<ErrorOr<NonnullOwnPtr<Kernel::KString>>> {
+ ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
+ {
+ return Formatter<ErrorOr<NonnullOwnPtr<Kernel::KString>>>::format(builder, value.to_string());
+ }
+};
+#else
template<>
struct Formatter<IPv4Address> : Formatter<String> {
ErrorOr<void> format(FormatBuilder& builder, IPv4Address value)
@@ -138,6 +165,7 @@ struct Formatter<IPv4Address> : Formatter<String> {
return Formatter<String>::format(builder, value.to_string());
}
};
+#endif
}
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp
index 8ab58cbcf9..a98fed1db0 100644
--- a/Kernel/GlobalProcessExposed.cpp
+++ b/Kernel/GlobalProcessExposed.cpp
@@ -47,11 +47,15 @@ private:
obj.add("class_name", adapter.class_name());
obj.add("mac_address", adapter.mac_address().to_string());
if (!adapter.ipv4_address().is_zero()) {
- obj.add("ipv4_address", adapter.ipv4_address().to_string());
- obj.add("ipv4_netmask", adapter.ipv4_netmask().to_string());
+ auto ipv4_address = adapter.ipv4_address().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("ipv4_address", ipv4_address->view());
+ auto ipv4_netmask = adapter.ipv4_netmask().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("ipv4_netmask", ipv4_netmask->view());
+ }
+ if (!adapter.ipv4_gateway().is_zero()) {
+ auto ipv4_gateway = adapter.ipv4_gateway().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("ipv4_gateway", ipv4_gateway->view());
}
- if (!adapter.ipv4_gateway().is_zero())
- obj.add("ipv4_gateway", adapter.ipv4_gateway().to_string());
obj.add("packets_in", adapter.packets_in());
obj.add("bytes_in", adapter.bytes_in());
obj.add("packets_out", adapter.packets_out());
@@ -78,7 +82,8 @@ private:
arp_table().for_each([&](const auto& it) {
auto obj = array.add_object();
obj.add("mac_address", it.value.to_string());
- obj.add("ip_address", it.key.to_string());
+ auto ip_address = it.key.to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("ip_address", ip_address->view());
});
array.finish();
return {};
@@ -96,9 +101,11 @@ private:
JsonArraySerializer array { builder };
TCPSocket::for_each([&array](auto& socket) {
auto obj = array.add_object();
- obj.add("local_address", socket.local_address().to_string());
+ auto local_address = socket.local_address().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("local_address", local_address->view());
obj.add("local_port", socket.local_port());
- obj.add("peer_address", socket.peer_address().to_string());
+ auto peer_address = socket.peer_address().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("peer_address", peer_address->view());
obj.add("peer_port", socket.peer_port());
obj.add("state", TCPSocket::to_string(socket.state()));
obj.add("ack_number", socket.ack_number());
@@ -153,9 +160,11 @@ private:
JsonArraySerializer array { builder };
UDPSocket::for_each([&array](auto& socket) {
auto obj = array.add_object();
- obj.add("local_address", socket.local_address().to_string());
+ auto local_address = socket.local_address().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("local_address", local_address->view());
obj.add("local_port", socket.local_port());
- obj.add("peer_address", socket.peer_address().to_string());
+ auto peer_address = socket.peer_address().to_string().release_value_but_fixme_should_propagate_errors();
+ obj.add("peer_address", peer_address->view());
obj.add("peer_port", socket.peer_port());
if (Process::current().is_superuser() || Process::current().uid() == socket.origin_uid()) {
obj.add("origin_pid", socket.origin_pid().value());