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 /ifconfig.c | |
parent | 36cd029a27aaba9fc3e84c68d79fcf887806e51b (diff) | |
download | abase-fa9d42260a789bebec1fee6fe3a19a0695617600.tar.gz abase-fa9d42260a789bebec1fee6fe3a19a0695617600.tar.bz2 |
started to implement a simple ifconfig
Diffstat (limited to 'ifconfig.c')
-rw-r--r-- | ifconfig.c | 46 |
1 files changed, 46 insertions, 0 deletions
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; +} |