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