From 9e0f7acfe5d7529cf65d86cfd229780aca8c3694 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 16 Jun 2019 07:06:49 +0200 Subject: Kernel+Userland: Expose list of network adapters through /proc/netadapters. Added a simple /bin/ifconfig program that just pretty-prints that file. :^) --- Kernel/FileSystem/ProcFS.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Kernel/FileSystem') diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index f1cc2c74aa..c042b5abb7 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ enum ProcFileType { FI_Root_dmesg, FI_Root_pci, FI_Root_uptime, + FI_Root_netadapters, FI_Root_self, // symlink FI_Root_sys, // directory __FI_Root_End, @@ -251,6 +253,19 @@ ByteBuffer procfs$uptime(InodeIdentifier) return builder.to_byte_buffer(); } +ByteBuffer procfs$netadapters(InodeIdentifier) +{ + StringBuilder builder; + NetworkAdapter::for_each([&builder](auto& adapter) { + builder.appendf("%s,%s,%s,%s\n", + adapter.name().characters(), + adapter.class_name(), + adapter.mac_address().to_string().characters(), + adapter.ipv4_address().to_string().characters()); + }); + return builder.to_byte_buffer(); +} + ByteBuffer procfs$pid_vmo(InodeIdentifier identifier) { auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); @@ -1098,6 +1113,7 @@ ProcFS::ProcFS() m_entries[FI_Root_self] = { "self", FI_Root_self, procfs$self }; m_entries[FI_Root_pci] = { "pci", FI_Root_pci, procfs$pci }; m_entries[FI_Root_uptime] = { "uptime", FI_Root_uptime, procfs$uptime }; + m_entries[FI_Root_netadapters] = { "netadapters", FI_Root_netadapters, procfs$netadapters }; m_entries[FI_Root_sys] = { "sys", FI_Root_sys }; m_entries[FI_PID_vm] = { "vm", FI_PID_vm, procfs$pid_vm }; -- cgit v1.2.3