1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:08:12 +00:00

Kernel+Userland: Expose list of network adapters through /proc/netadapters.

Added a simple /bin/ifconfig program that just pretty-prints that file. :^)
This commit is contained in:
Andreas Kling 2019-06-16 07:06:49 +02:00
parent 264890bfc3
commit 9e0f7acfe5
6 changed files with 69 additions and 0 deletions

View file

@ -9,6 +9,7 @@
#include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Net/NetworkAdapter.h>
#include <Kernel/PCI.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/kmalloc.h>
@ -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 };