ladybird/Userland/ifconfig.cpp
Andreas Kling 9e0f7acfe5 Kernel+Userland: Expose list of network adapters through /proc/netadapters.
Added a simple /bin/ifconfig program that just pretty-prints that file. :^)
2019-06-16 07:06:49 +02:00

30 lines
775 B
C++

#include <LibCore/CFile.h>
#include <stdio.h>
int main(int argc, char** argv)
{
UNUSED_PARAM(argc);
UNUSED_PARAM(argv);
CFile file("/proc/netadapters");
if (!file.open(CIODevice::ReadOnly)) {
fprintf(stderr, "Error: %s\n", file.error_string());
return 1;
}
for (;;) {
auto line = file.read_line(1024);
if (line.is_null())
break;
auto parts = String::copy(line, Chomp).split(',');
if (parts.size() < 4)
continue;
printf("%s:\n", parts[0].characters());
printf(" mac: %s\n", parts[2].characters());
printf(" ipv4: %s\n", parts[3].characters());
printf(" class: %s\n", parts[1].characters());
printf("\n");
}
return 0;
}