libnl: /data/src/libnl3/src/nl-neightbl-list.c Source File

libnl 3.7.0

nl-neightbl-list.c
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
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
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 }
nl_cache_dump
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
Definition: cache.c:1197
rtnl_neightbl_alloc_cache
int rtnl_neightbl_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
Build a neighbour table cache including all neighbour tables currently configured in the kernel.
Definition: neightbl.c:391
NL_DUMP_LINE
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition: types.h:16
nl_dump_params
Dumping parameters.
Definition: types.h:28
nl_dump_params::dp_type
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
Definition: types.h:32