diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2023-04-25 21:13:49 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2023-04-25 21:13:49 +0200 |
commit | fa9d42260a789bebec1fee6fe3a19a0695617600 (patch) | |
tree | 14d7ebd10c30a36b5240392cec01bf7d11ecd012 | |
parent | 36cd029a27aaba9fc3e84c68d79fcf887806e51b (diff) | |
download | abase-fa9d42260a789bebec1fee6fe3a19a0695617600.tar.gz abase-fa9d42260a789bebec1fee6fe3a19a0695617600.tar.bz2 |
started to implement a simple ifconfig
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | README | 15 | ||||
-rw-r--r-- | ifconfig.1 | 18 | ||||
-rw-r--r-- | ifconfig.c | 46 |
4 files changed, 81 insertions, 1 deletions
@@ -15,7 +15,8 @@ LIB = $(LIBUTF) $(LIBUTIL) BIN =\ more\ - hexdump + hexdump\ + ifconfig LIBUTILOBJ = $(LIBUTILSRC:.c=.o) OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ) @@ -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; +} |