The Pedigree Project 0.1
user/applications/netconfig/main.cc
1/* Copyright (c) 2026, Pedigree Developers. */
2#include <stdio.h>
3#include <string.h>
4
5static int printFile(const char* path) {
6 FILE* file = fopen(path, "r");
7 if (!file) {
8 perror(path);
9 return 1;
10 }
11 char buffer[4096];
12 size_t count;
13 int failed = 0;
14 while ((count = fread(buffer, 1, sizeof(buffer), file))) {
15 if (fwrite(buffer, 1, count, stdout) != count) {
16 failed = 1;
17 break;
18 }
19 }
20 if (ferror(file)) {
21 perror(path);
22 failed = 1;
23 }
24 fclose(file);
25 return failed;
26}
27
28int main(int argc, char* argv[]) {
29 if (argc != 1) {
30 const bool help = argc == 2 && !strcmp(argv[1], "--help");
31 fprintf(help ? stdout : stderr,
32 "Usage: netconfig\nShow network devices, addresses, and DNS.\n");
33 return help ? 0 : 1;
34 }
35 if (printFile("/proc/net/interfaces"))
36 return 1;
37 puts("DNS:");
38 if (printFile("/proc/resolv.conf"))
39 return 1;
40 if (fflush(stdout) || ferror(stdout)) {
41 perror("netconfig");
42 return 1;
43 }
44 return 0;
45}