1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * src/nl-neightbl-list.c Dump neighbour tables
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation version 2.1
8 * of the License.
9 *
10 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
11 */
12
13 #include <netlink/cli/utils.h>
14 #include <netlink/cli/link.h>
15
16 #include <linux/netlink.h>
17
print_usage(void)18 static void print_usage(void)
19 {
20 printf(
21 "Usage: nl-neightbl-list [OPTION]...\n"
22 "\n"
23 "Options\n"
24 " -f, --format=TYPE Output format { brief | details | stats }\n"
25 " -h, --help Show this help\n"
26 " -v, --version Show versioning information\n"
27 );
28 exit(0);
29 }
30
main(int argc,char * argv[])31 int main(int argc, char *argv[])
32 {
33 struct nl_sock *sock;
34 struct nl_cache *neightbl_cache;
35 struct nl_dump_params params = {
36 .dp_type = NL_DUMP_LINE,
37 .dp_fd = stdout,
38 };
39
40 sock = nl_cli_alloc_socket();
41 nl_cli_connect(sock, NETLINK_ROUTE);
42 nl_cli_link_alloc_cache(sock);
43 neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table",
44 rtnl_neightbl_alloc_cache);
45
46 for (;;) {
47 int c, optidx = 0;
48 static struct option long_opts[] = {
49 { "format", 1, 0, 'f' },
50 { "help", 0, 0, 'h' },
51 { "version", 0, 0, 'v' },
52 { 0, 0, 0, 0 }
53 };
54
55 c = getopt_long(argc, argv, "f:hv", long_opts, &optidx);
56 if (c == -1)
57 break;
58
59 switch (c) {
60 case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
61 case 'h': print_usage(); break;
62 case 'v': nl_cli_print_version(); break;
63 }
64 }
65
66 nl_cache_dump(neightbl_cache, ¶ms);
67
68 return 0;
69 }
70