diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 3dec7ff127..fc7d0cae09 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -53,6 +55,7 @@ enum ProcFileType { FI_Root_net_adapters, FI_Root_net_tcp, + FI_Root_net_udp, FI_PID, @@ -311,6 +314,20 @@ Optional procfs$net_tcp(InodeIdentifier) return json.serialized(); } +Optional procfs$net_udp(InodeIdentifier) +{ + JsonArray json; + UDPSocket::for_each([&json](auto& socket) { + JsonObject obj; + obj.set("local_address", socket.local_address().to_string()); + obj.set("local_port", socket.local_port()); + obj.set("peer_address", socket.peer_address().to_string()); + obj.set("peer_port", socket.peer_port()); + json.append(obj); + }); + return json.serialized(); +} + Optional procfs$pid_vmo(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); @@ -917,6 +934,7 @@ bool ProcFSInode::traverse_as_directory(Function #include +void UDPSocket::for_each(Function callback) +{ + LOCKER(sockets_by_port().lock()); + for (auto it : sockets_by_port().resource()) + callback(*it.value); +} + Lockable>& UDPSocket::sockets_by_port() { static Lockable>* s_map; diff --git a/Kernel/Net/UDPSocket.h b/Kernel/Net/UDPSocket.h index b19cad00df..ff08f38cdb 100644 --- a/Kernel/Net/UDPSocket.h +++ b/Kernel/Net/UDPSocket.h @@ -8,6 +8,7 @@ public: virtual ~UDPSocket() override; static SocketHandle from_port(u16); + static void for_each(Function); private: explicit UDPSocket(int protocol);