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