summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2023-04-25 21:13:49 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2023-04-25 21:13:49 +0200
commitfa9d42260a789bebec1fee6fe3a19a0695617600 (patch)
tree14d7ebd10c30a36b5240392cec01bf7d11ecd012
parent36cd029a27aaba9fc3e84c68d79fcf887806e51b (diff)
downloadabase-fa9d42260a789bebec1fee6fe3a19a0695617600.tar.gz
abase-fa9d42260a789bebec1fee6fe3a19a0695617600.tar.bz2
started to implement a simple ifconfig
-rw-r--r--Makefile3
-rw-r--r--README15
-rw-r--r--ifconfig.118
-rw-r--r--ifconfig.c46
4 files changed, 81 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index dd89fae..a33b419 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,8 @@ LIB = $(LIBUTF) $(LIBUTIL)
BIN =\
more\
- hexdump
+ hexdump\
+ ifconfig
LIBUTILOBJ = $(LIBUTILSRC:.c=.o)
OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ)
diff --git a/README b/README
index 1bba99e..295c21a 100644
--- a/README
+++ b/README
@@ -8,6 +8,7 @@ Currently it contains the following:
- a simple 'hexdump'
- a 'fdisk' (but we have to decide for which kind of partition types
and what kind of operations, could be too big)
+- a 'ifconfig'
Note: abase is a shameless copy of sbase/ubase in certain areas like
the Makefile, libutil, etc. This might also make an integration into
@@ -32,4 +33,18 @@ Portability
Not really tested so far, but you should be able to build it with
gcc, clang, tcc, nwcc and pcc.
+Bugs and Questions
+------------------
+
+- more
+ - even non-line keyboard input is not portable
+ - how to enable terminal formatting like bold and make things not
+ depend on ncurses/termcap?
+- ifconfig
+ - implementations
+ - GNU net-tools
+ - net-3-tools
+ - nosh
+ - netlink api or ioctls
+
[1] http://www.musl-libc.org/
diff --git a/ifconfig.1 b/ifconfig.1
new file mode 100644
index 0000000..9468f98
--- /dev/null
+++ b/ifconfig.1
@@ -0,0 +1,18 @@
+.Dd 2023-04-24
+.Dt IFCONFIG 1
+.Os abase
+.Sh NAME
+.Nm ifconfig
+.Nd inspect and manipulate network settings
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+.Nm
+.Sh OPTIONS
+.sp
+.RE
+\fB\-a\fP
+.RS 4
+Show all network interfaces and configurations
+.RE
+
diff --git a/ifconfig.c b/ifconfig.c
new file mode 100644
index 0000000..2d3b8eb
--- /dev/null
+++ b/ifconfig.c
@@ -0,0 +1,46 @@
+/* See LICENSE file for copyright and license details. */
+#include <net/if.h>
+#include <stdio.h>
+
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [-a]\n", argv0);
+}
+
+static void
+print_interface(char *name)
+{
+ printf("%s\n", name);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int show_all = 0;
+ //~ struct ifreq ifr;
+
+ ARGBEGIN {
+ case 'a':
+ show_all = 1;
+ break;
+ default:
+ usage();
+ } ARGEND
+
+ if (show_all) {
+ struct if_nameindex *interfaces, *interface;
+
+ interfaces = if_nameindex();
+ if (interfaces != NULL) {
+ for (interface = interfaces; (interface->if_index != 0 || interface->if_name != NULL); interface++) {
+ print_interface(interface->if_name);
+ }
+ if_freenameindex(interfaces);
+ }
+ }
+
+ return 0;
+}