diff options
author | Thomas Graf <tgr@lsx.localdomain> | 2008-05-22 22:02:02 (GMT) |
---|---|---|
committer | Thomas Graf <tgr@lsx.localdomain> | 2008-05-22 22:02:02 (GMT) |
commit | 10cf5a586c149fdb7e2639000dbfae5e6f8522a5 (patch) | |
tree | 399a15d767fd15b85c92be2e70b748645eeb983e /src/nl-neightbl-list.c | |
parent | 337fbd24cad1f5cf9c8b4287a75f2c69f088adce (diff) | |
download | libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.zip libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.tar.gz libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.tar.bz2 |
New set of libnl tools
Converts all tools to the API changes and improves the useability by
introducing regular options and long options.
Diffstat (limited to 'src/nl-neightbl-list.c')
-rw-r--r-- | src/nl-neightbl-list.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/nl-neightbl-list.c b/src/nl-neightbl-list.c new file mode 100644 index 0000000..4e5acc6 --- /dev/null +++ b/src/nl-neightbl-list.c @@ -0,0 +1,64 @@ +/* + * src/nl-neightbl-list.c Dump neighbour tables + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> + */ + +#include "utils.h" + +static void print_usage(void) +{ + printf( + "Usage: nl-neightbl-list [OPTION]...\n" + "\n" + "Options\n" + " -f, --format=TYPE Output format { brief | details | stats }\n" + " -h, --help Show this help\n" + " -v, --version Show versioning information\n" + ); + exit(0); +} + +int main(int argc, char *argv[]) +{ + struct nl_sock *sock; + struct nl_cache *link_cache, *neightbl_cache; + struct nl_dump_params params = { + .dp_type = NL_DUMP_ONELINE, + .dp_fd = stdout, + }; + + sock = nlt_alloc_socket(); + nlt_connect(sock, NETLINK_ROUTE); + link_cache = nlt_alloc_link_cache(sock); + neightbl_cache = nlt_alloc_neightbl_cache(sock); + + for (;;) { + int c, optidx = 0; + static struct option long_opts[] = { + { "format", 1, 0, 'f' }, + { "help", 0, 0, 'h' }, + { "version", 0, 0, 'v' }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'f': params.dp_type = nlt_parse_dumptype(optarg); break; + case 'h': print_usage(); break; + case 'v': nlt_print_version(); break; + } + } + + nl_cache_dump(neightbl_cache, ¶ms); + + return 0; +} |